Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I serialize a DevExpress XtraReport report design

I need to serialize a report design. This is the scenario:

The app has base reports, let's say "Sales Report" with a set of pre-defined columns and design, like the corp. logo in the header. The users needs to have the ability to change that layout adding, for example, a footer with the office address, or page numbers. For doing that they need to edit the report, enter the designer and add/change what they need. This changed report layout needs to be serialized to be stored in the database for that user, so the next time, the user opens that report, using that design.

Makes sense?

like image 628
Sebastian Avatar asked Aug 03 '09 12:08

Sebastian


2 Answers

Here's a simplified version of how I do this:

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);
}

Inside MySaveCommandHandler class:

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;
}
like image 173
Kyle Gagnet Avatar answered Sep 23 '22 11:09

Kyle Gagnet


I think what you are looking for is the SaveLayout method:

Saving the report

YourReport report = new YourReport();

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

Loading the report

YourReport report = new YourReport();

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

Edit:

here a link to the devexpress support site explaining how to save the report definition.

like image 39
Francis B. Avatar answered Sep 19 '22 11:09

Francis B.