【问题标题】:How to get the templates/reports that already created in C#.Net using Devexpress?如何使用 Devexpress 获取已经在 C#.Net 中创建的模板/报告?
【发布时间】:2014-09-06 10:52:45
【问题描述】:

我正在使用DevExpress 工具在 C#.Net 中进行项目。我创建了一些模板/报告 (XtraReport),并创建了按钮以从 link 单独显示这些模板。

现在我需要获取所有模板名称并希望在 DropDown 中显示并最终用户单独选择和查看每个模板??

我可以从 bin>Debug>UserTemplates .repx 格式文件中获取我从设计器创建并存储在外部的模板,并使用此代码存储在下拉列表中并显示在预览中。

printBarManager1.PrintControl = printControl1;
XtraReport RptObj = XtraReport.FromFile(Application.StartupPath + @"\UserTemplates\" + CBL_QuoteTempList.EditValue + ".repx", true);

RptObj.CreateDocument();
printControl1.PrintingSystem = RptObj.PrintingSystem;

但是我需要获取我创建的模板吗?如何获得 ?去哪里买?建议我或帮助我解决这个问题。

提前致谢。斯里哈里

【问题讨论】:

    标签: c# .net templates devexpress xtrareport


    【解决方案1】:

    据我了解,您有一个包含 *.repx 文件的文件夹,但您不知道如何让您的用户选择其中之一。

    您可以使用此代码加载组合

    public static void loadCombo(ComboBoxEdit control) 
    {
            string path = @"C:\FolderWithRepxFiles\";
    
            string[] filePaths = Directory.GetFiles(path, "*.repx");
            control.Properties.Items.Clear();
            foreach (string item in filePaths)
                control.Properties.Items.Add(System.IO.Path.GetFileNameWithoutExtension(item));
    }
    

    然后你可以用这个打印/打印预览报告

    public static void PrintPreview(ComboBoxEdit control)
    {
          string selection = control.SelectedItem as string;
          string fullPath = @"C:\FolderWithRepxFiles\" + selection + ".repx";
          XtraReport rr = XtraReport.FromFile(fullPath, true);
          ReportPrintTool printTool = new ReportPrintTool(rr);
          printTool.ShowRibbonPreview();
          //printTool.Print();
    }
    

    要自定义保存过程,您必须创建自定义命令处理程序。 以下是你的做法:

    XRDesignRibbonForm designForm = new XRDesignRibbonForm();
    designForm.OpenReport(Your_Report_Object);
    XRDesignPanel panel = designForm.ActiveDesignPanel;
    designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.SaveFileAs, DevExpress.XtraReports.UserDesigner.CommandVisibility.None);
    designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.SaveAll, CommandVisibility.None);
    designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowPreviewTab, CommandVisibility.None);
    designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowHTMLViewTab, CommandVisibility.None);
    designForm.ActiveDesignPanel.SetCommandVisibility(ReportCommand.ShowTabbedInterface, CommandVisibility.None);
    if (panel != null)
          panel.AddCommandHandler(new SaveCommandHandler(panel));
    designForm.ShowDialog();
    

    你需要这个课程

     public class SaveCommandHandler : DevExpress.XtraReports.UserDesigner.ICommandHandler
     {
            XRDesignPanel panel;
            string NewPathX = null;
    
            public SaveCommandHandler(XRDesignPanel panel)
            {
                this.panel = panel;
            }
    
            void Save()
            {
    
                //Show a form with a textbox and ask the user to give you a name for the report
                string fileName = "UserSelectedFileName";
    
                fileName = @"C:\YourDefaultFolder" + fileName + ".repx";
    
                panel.Report.SaveLayout(fileName);
    
    
                panel.ReportState = ReportState.Saved;
            }
    
            public bool CanHandleCommand(ReportCommand command, ref bool useNextHandler)
            {
                useNextHandler = command != ReportCommand.SaveFile;
                return command == ReportCommand.SaveFile;
            }
    
            public void HandleCommand(ReportCommand command, object[] args)
            {
                bool handled = false;
                if (!CanHandleCommand(command, ref handled)) return;
                Save();
            }
        }
    

    更多信息:
    https://documentation.devexpress.com/#xtrareports/CustomDocument2211 http://www.devexpress.com/Support/Center/Example/Details/E4354

    这是你需要的吗?

    【讨论】:

    • 嗨@George 感谢您的回答,很遗憾您理解错误。如果我从 XtraReports 创建 Reports / Templates 我不知道它将如何存储(如 .repx)以及如何访问它??
    • 我告诉过如果我从 Report Designer 创建新的Report / Template,它会要求用户将路径保存为 .repx 文件。我可以访问它。
    • 你不想让用户选择一个文件夹,对吗?你想指定一个默认的?
    • 不,先生,实际上阅读了第一条评论,我从XtraReport 创建了一个报告,现在我需要在下拉/查找编辑中获取它?
    • 我想我不明白...您拥有的报告是一个 *.repx 文件。在查找编辑中得到它是什么意思?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    • 1970-01-01
    • 1970-01-01
    • 2012-11-04
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多