如何序列化DevExpress XtraReport报表设计

Seb*_*ian 8 .net c# reporting devexpress xtrareport

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

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

说得通?

Kyl*_*net 9

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

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);
}
Run Code Online (Sandbox Code Playgroud)

在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;
}
Run Code Online (Sandbox Code Playgroud)