Distribute the Created Reports with the Application

This topic describes how to distribute reports with an application and update them.

Important

This topic is related to the legacy Reports Module (Obsolete). If you use the Reports V2 Module, you do not need to follow the instructions here. Instead, create a predefined report as described in the Create Predefined Static Reports topic.

  • Create the EmbeddedReports folder in the MySolution.Module project:

    Tutorial_BMD_Lesson10_1

  • Run the Windows Forms application.
  • Export each report layout to an REPX file in the new EmbeddedReports folder using the Report Designer's smart tag menu.

    Tutorial_BMD_Lesson10_1_1

  • Stop the application. In the Solution Explorer, click the Show All Files toolbar button. Select the report files in the EmbeddedReports sub-folder, right-click the selection, and choose Include in Project.

    Tutorial_BMD_Lesson10_2

  • Set the Build Action property for both REPX files to Embedded Resource.

    Tutorial_BMD_Lesson10_2_1

  • Add the following references to the application module:

    DevExpress.ExpressApp.Reports

    DevExpress.XtraReports

    System.Drawing

  • Open the Updater.cs (Updater.vb) file located in the MySolution.Module project and add the following method to the Updater class:

    using DevExpress.ExpressApp.Reports;
    using DevExpress.ExpressApp;
    //...
    private void CreateReport(string reportName) {
       ReportData reportdata = ObjectSpace.FindObject<ReportData>(
          new BinaryOperator("Name", reportName));
       if (reportdata == null) {
          reportdata = ObjectSpace.CreateObject<ReportData>();
          XafReport rep = new XafReport();
          rep.ObjectSpace = ObjectSpace;
          rep.LoadLayout(GetType().Assembly.GetManifestResourceStream(
             "MySolution.Module.EmbeddedReports." + reportName + ".repx"));
          rep.ReportName = reportName;
          reportdata.SaveReport(rep);
       }
    }
    

    In this method, a new ReportData object is created (the report that you created via the Report Designer in the Create a Report in Visual Studio lesson). The content of the report from the EmbeddedReports folder, passed as a parameter, is saved to this ReportData object, which is then saved to the database.

    Note

    The LoadLayout method loads the report's definition saved within the report file. This definition includes the report name. We set the ReportName property after loading the report definition to avoid creating duplicate reports. Otherwise, duplicate reports may appear when the name stored within the report definition differs from the name passed to the CreateReport method.

  • To create reports and save them to the database, the CreateReport method defined in the previous step must be called from the Updater's UpdateDatabaseAfterUpdateSchema method. For this purpose, execute the CreateReport method for each report you wish to create in the UpdateDatabaseAfterUpdateSchema method as shown below:

    public class Updater : DevExpress.ExpressApp.Updating.ModuleUpdater {
       //...
       public override void UpdateDatabaseAfterUpdateSchema() {
          //...
          CreateReport("ContactsGroupedByPosition");
          CreateReport("TasksStateReport");
       }
    }
    
  • Check to see that the reports are created when running the application.

    Tutorial_BMD_Lesson10_3

See Also