How to: Use the Custom Report Preview Form 如何:使用自定义报表预览窗体

This example demonstrates how to show a custom Report Preview form by handling the ReportServiceController.CustomShowPreview 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 模块概述)。

Use the following Controller to display a report preview in a custom window (the CustomPreviewForm form, in this example).

使用以下控制器在自定义窗口中显示报表预览(在此示例中为自定义预览窗体)。

using DevExpress.XtraReports.UI;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.ReportsV2;
// ...
public class CustomPreviewController : ViewController {
    private ReportServiceController reportServiceController;
    protected override void OnActivated() {
        base.OnActivated();
        reportServiceController = Frame.GetController<ReportServiceController>();
        if (reportServiceController != null) {
            reportServiceController.CustomShowPreview += reportServiceController_CustomShowPreview;
        }
    }
    void reportServiceController_CustomShowPreview(object sender, CustomShowPreviewEventArgs e) {
        IReportContainer reportContainer = 
            ReportDataProvider.ReportsStorage.GetReportContainerByHandle(e.ReportContainerHandle);
        reportServiceController.SetupBeforePrint(reportContainer.Report, 
            e.ParametersObject, e.Criteria, e.CanApplyCriteria, e.SortProperty, e.CanApplySortProperty);
        CustomPreviewForm form = new CustomPreviewForm();
        form.ShowReport(reportContainer.Report);
        e.Handled = true;
    }
    protected override void OnDeactivated() {
        if (reportServiceController != null) {
            reportServiceController.CustomShowPreview -= reportServiceController_CustomShowPreview;
        }
    }
}

The CustomPreviewForm form can be designed as described in the following tutorials:

  • Adding Items to a Print Preview's Standard Toolbar
  • Adding Items to a Print Preview's Ribbon Toolbar

自定义预览表单窗体可以按照以下教程中的说明进行设计:

  • 将项目添加到打印预览的标准工具栏
  • 将项目添加到打印预览的功能区工具栏

When the CustomPreviewForm is ready, add the ShowReport method to it.

当自定义预览表单准备就绪时,向其添加显示报表方法。

public void ShowReport(XtraReport report){
    documentViewer1.DocumentSource = report;
    report.CreateDocument();
    Show();
}

In this example, documentViewer1 is the DocumentViewer component added to the current form.

在此示例中,文档Viewer1 是添加到当前窗体的文档查看器组件。

Tip 提示
Refer to the API and Customization section in the XtraReports documentation to learn more about report preview customization.
请参阅 XtraReports 文档中的 API 和自定义部分,了解有关报表预览自定义的详细信息。
原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Use-the-Custom-Report-Preview-Form.html