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サポートサイトへのリンク方法を説明しています。レポート定義を保存します。
SaveおよびLoadLayoutオーバーライドを使用して、ストリームの保存/読み込みを行うことができます。設計者は、コマンドハンドラーを追加して、保存コマンドをインターセプトできます。
これらの記事はあなたが必要とするものをカバーするべきです:
方法:エンドユーザーデザイナーでコマンドをオーバーライドする(カスタム保存)
完全を期すために:すべてのハウツーのリスト
編集:固定リンク
所属していません StackOverflow