我如何序列化的DevExpress XtraReport报表设计
-
10-07-2019 - |
题
我需要序列一个报告设计。这是该方案:
在应用程序有基地的报道,让我们说“销售报表”一组预定义的列和设计,如CORP。标志的标题。用户需要有改变这种布局添加,例如能力,与办公地址页脚,或页码。对于这样做,他们需要编辑报表,输入设计,并添加/更改他们需要什么。这个变化的报告布局需要被序列被存储在数据库中为该用户,所以接下来的时间,在用户打开该报告中,用该设计。
有道理?
解决方案
下面是我怎么做的简化版本:
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;
}
其他提示
我想你正在寻找的是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");
修改强>
这里链接到DevExpress的支持网站,说明如何保存报告定义
不隶属于 StackOverflow