How to: Merge the Pages of Two Reports 如何:合并两个报表的页面

This example demonstrates how to modify report content before it is displayed by handling the ReportDataSourceHelper.BeforeShowPreview event.

此示例演示如何通过处理报表数据源帮助程序。在显示报表内容之前对其进行修改。

 

Note 注意
Mobile applications do not support the report preview mechanism, so the approach described in this topic cannot be implemented in the Mobile platform.
移动应用程序不支持报表预览机制,因此本主题中描述的方法无法在移动平台中实现。

 

In this topic, it is assumed that you have an XAF application that uses the Reports V2 Module, and you have created one or more reports (see Reports V2 Module Overview).

在本主题中,假定您有一个使用报表 V2 模块的 XAF 应用程序,并且您创建了一个或多个报表(请参阅报表 V2 模块概述)。

 

To merge two reports right before they are displayed, implement the following helper class, which handles the ReportDataSourceHelper.BeforeShowPreview event. In this example, pages from the SecondReport will be appended to the pages of the FirstReport when the FirstReport is previewed.

要在显示两个报表之前合并它们,实现以下帮助器类,该类处理报表数据源Helper.在此示例中,预览第一个报表时,第二个报表中的页面将追加到第一个报表的页面。

 

using DevExpress.XtraReports.UI;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2;
// ...
public class MergeReportHelper {
    ReportDataSourceHelper helper;
    public MergeReportHelper(ModuleList modules) {
        ReportsModuleV2 module = ReportsModuleV2.FindReportsModule(modules);
        if (module != null) {
            module.ReportsDataSourceHelper.BeforeShowPreview +=
                ReportsDataSourceHelper_BeforeShowPreview;
        }
    }
    private void ReportsDataSourceHelper_BeforeShowPreview(
        object sender, BeforeShowPreviewEventArgs e) {
        MergeReportsBeforeShow(e.Report, (ReportDataSourceHelper)sender);
    }
    private void MergeReportsBeforeShow(
        XtraReport report, ReportDataSourceHelper reportsDataSourceHelper) {
        if (report is FirstReport) {
            report.AfterPrint += report_AfterPrint;
            helper = reportsDataSourceHelper;
        }
    }
    void report_AfterPrint(object sender, EventArgs e) {
        FirstReport firstReport = sender as FirstReport;
        SecondReport secondReport = new SecondReport();
        helper.SetupReport(secondReport);
        secondReport.CreateDocument(false);
        firstReport.Pages.AddRange(secondReport.Pages);
        firstReport.PrintingSystem.ContinuousPageNumbering = true;
    }
}

 

The ReportDataSourceHelper.SetupReport method call is required to display a report in XAF. Without it, the data source will not provide data.

报表数据源Helper.SetupReport 方法调用需要在 XAF 中显示报表。如果没有它,数据源将不会提供数据。

 

Create an instance of the MergeReportHelper class after the application setup is complete. You can do it in the platform-agnostic module by handling the XafApplication.SetupComplete event in the overridden ModuleBase.Setup method.

应用程序设置完成后,创建 MergeReportHelper 类的实例。您可以通过在重写的 ModuleBase.安装程序方法中处理 XafApplication.安装程序完成事件,在与平台无关的模块中执行此操作。

 

public override void Setup(XafApplication application) {
    base.Setup(application);
    application.SetupComplete += delegate(object sender, EventArgs e) {
        new MergeReportHelper(((XafApplication)sender).Modules);
    };
}

 

posted @ 2020-01-10 14:38  code first life  阅读(480)  评论(0编辑  收藏  举报