【问题标题】:How can I serialize a DevExpress XtraReport report design如何序列化 DevExpress XtraReport 报告设计
【发布时间】:2009-08-03 12:52:29
【问题描述】:

我需要序列化报表设计。这是场景:

该应用具有基本报告,比如“销售报告”,其中包含一组预定义的列和设计,例如 corp.标头中的徽标。用户需要能够更改该布局,例如添加带有办公室地址或页码的页脚。为此,他们需要编辑报告,输入设计器并添加/更改他们需要的内容。此更改的报表布局需要序列化以存储在该用户的数据库中,因此下一次,用户使用该设计打开该报表。

有道理吗?

【问题讨论】:

    标签: c# .net devexpress reporting xtrareport


    【解决方案1】:

    这是我如何做到这一点的简化版本:

    XtraReport customReport;
    customReport = new MyXtraReport();
    byte[] layout = LoadCustomLayoutFromDB();
    if (layout != null) {
        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(layout)) {
            customReport.LoadLayout(memoryStream);
        }
    }
    
    using (XRDesignFormEx designer = new XRDesignFormEx()) {
        MySaveCommandHandler customCommands = new MySaveCommandHandler(designer.DesignPanel);
        designer.DesignPanel.AddCommandHandler(customCommands);
        designer.OpenReport(customReport);
        designer.ShowDialog(this);
        if (customCommands.ChangesSaved)
            SaveCustomLayoutToDB(customCommands.Layout);
    }
    

    在 MySaveCommandHandler 类中:

    public virtual void HandleCommand(ReportCommand command, object[] args, ref bool handled) {
        if (command != ReportCommand.SaveFileAs && command != ReportCommand.SaveFileAs)
            return;
    
        using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream()) {
            panel.Report.SaveLayout(memoryStream);
            this.layout = memoryStream.ToArray();
            changesSaved = true;
        }
    
        panel.ReportState = ReportState.Saved;
        handled = true;
    }
    

    【讨论】:

    • 我有一个问题...为什么将布局保存到一个字节[],是不是简单,更直接的保存到数据库?那么在 SaveCustomLayoutToDb 方法中,您将其传递给 SQL Server 二进制列或其他什么?
    【解决方案2】:

    我认为您正在寻找的是 SaveLayout 方法:

    保存报告

    YourReport report = new YourReport();
    
    // Save the layout to a file.
    report.SaveLayout(@"C:\YourReport.repx");
    

    加载报告

    YourReport report = new YourReport();
    
    // Load the layout
    report.LoadLayout(@"C:\YourReport.repx");
    

    编辑:

    这里是 link devexpress 支持网站,解释如何保存报告定义。

    【讨论】:

    • 对不起,Francis,但据我所知,将报告保存到 repx 文件并不是序列化。您知道该工具是否具有 SaveToXml() 方法或其他方法吗?谢谢。
    • 序列化并不意味着您必须将信息保存在 xml 文件中。目前,DevExpress 不支持将报告定义保存在 xml 中,但他们为将来的版本实现了此功能 (devexpress.com/Support/Center/p/AS4336.aspx)。
    • 弗朗西斯说的是真的。这不是那个意思。但恕我直言,这是当今最常见的工作方式。将对象序列化为 XML 并使用 Web 服务通过网络发送或将其保存在数据库中的文本文件中。
    【解决方案3】:

    您可以使用 Save 和 LoadLayout 覆盖在流中保存/加载。对于设计器,您可以添加一个命令处理程序来拦截保存命令。

    这些文章应该涵盖您需要的内容:

    How to: Save and Restore a Report Definition from a Stream

    How to: Override Commands in the End-User Designer (Custom Saving)

    为了完整起见:List of all how-to's

    编辑:固定链接

    【讨论】:

    • 非常感谢 Dag,这对我在这件事上走得更远很有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多