Integrate the report into a C# application

You have a data source and at least one report design document. You can now package and add the necessary code to launch the report from a C# application.

You have tested your data source and design using the Report Launcher (see the quick start process). You now want to integrate the data and report into a bespoke application using code to make the necessary calls. This code will not only run the report, it will also specify the format of the report, how and if the report displays, and where the report is saved on disk.

Package the data source

Regardless of the number of generated data sources, a single library named DataSourceLib.dll is required to hold all the generated data sources under the namespace. If you used BAM to create the project, this library is automatically created; otherwise, you must create this library using your source code. The library must be signed using a strong name.

Now examine the properties for the application node, and you see it referenced under the Linker options property: /reference:"$(ProjectDir)/bin/DataSourceLib.dll". You need to reference this library in your own application.

Add code to run the report

Before we look at the method that creates the report, take note of the using clause towards the start of the file and the resource it references:
using FourJs.Report.BAM.SQLReports;
This is needed, as all generated data sources are contained in that namespace, as shown by the namespace definition in the generated code:
namespace FourJs.Report.BAM.SQLReports

For the code that creates the report in the C# sample application, look for the createPDFReport method.

  1. Configure the report.

    In this example, the report is configured to be output to PDF.

    // Configure the report
    FormatHandler handler = new FormatWriter(reportFileName);
    LayoutedPagesConsumer renderer = new PDFRenderer(handler); ;
    PXMLConsumer layout = new PXMLLayouter(renderer);
    FourRpProcessor reportProcessor = new FourRpProcessor(reportDesignFileName, layout);
  2. Instantiate the data source object from the data source library.
    // Run the report
    OrderReport orderReport = new OrderReport(connection);
  3. Pass the object to the report engine for processing.
    reportProcessor.runFromSerializable(orderReport);

View the report

The viewReport method opens and displays the created PDF file.