How to: Add a Custom Column to the Reports List 如何:将自定义列添加到报表列表

This topic describes how to customize the persistent class used to store reports to associate additional information with report objects. For instance, adding the Category property will result in an additional column in the Reports List View, and end users will be able to group, sort or filter by categories.

本主题介绍如何自定义用于存储报表的持久性类,以便将其他信息与报表对象相关联。例如,添加"类别"属性将导致报表列表视图中出现另一列,最终用户将能够按类别进行分组、排序或筛选。

 

WinForms:

ReportsV2_WizParamsRuntime

ASP.NET:

ReportsV2_WizParamsRuntime_Web

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 模块概述)。

 

Note 注意
Mobile applications do not support the Report Wizard, so the approach described in this topic cannot be implemented in the Mobile platform.
移动应用程序不支持报表向导,因此本主题中描述的方法无法在移动平台中实现。
 
Tip 提示
A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T154234
完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=T154234

.

Inherit ReportDataV2

继承报表数据V2

Entity Framework 实体框架

If you use the Entity Framework, create the MyReportDataV2 entity derived from DevExpress.Persistent.BaseImpl.EF.ReportDataV2. Then, add your custom entity to the DbContext.

如果使用实体框架,请创建从 DevExpress 派生的 MyReportDataV2 实体。然后,将自定义实体添加到 DbContext。

public class MyReportDataV2 : DevExpress.Persistent.BaseImpl.EF.ReportDataV2 {
    public string Category { get; set; }
}

public class MySolutionDbContext : DbContext {
    // ...
    public DbSet<ReportDataV2> ReportDataV2 { get; set; }
    public DbSet<MyReportDataV2> MyReportDataV2 { get; set; }
}

 

XPO

If you use XPO, create the MyReportDataV2 persistent class derived from DevExpress.Persistent.BaseImpl.ReportDataV2.

如果使用 XPO,请创建从 DevExpress 派生的 MyReportDataV2 持久类。

public class MyReportDataV2 : DevExpress.Persistent.BaseImpl.ReportDataV2 {
    public MyReportDataV2(Session session) : base(session) { }
    private string category;
    public string Category {
        get { return category; }
        set { SetPropertyValue(nameof(Category), ref category, value); }
     }
}

 

Specify ReportsModuleV2.ReportDataType

指定报表模块V2.报表数据类型

In the Application Designer, set the ReportsModuleV2.ReportDataType property value to MyReportDataV2.

在应用程序设计器中,将报表模块V2.报表数据类型属性值设置为 MyReportDataV2。

ReportsV2_ReportDataType

Repeat this step for both the WinApplication.cs (WinApplication.vb) and WebApplication.cs (WebApplication.vb) files.

对WinApplication.cs (WinApplication.vb) 和WebApplication.cs (WebApplication.vb) 文件重复此步骤。

Add the New Property to the Report Wizard

将新属性添加到报表向导

Note 注意
You can omit this section if you do not want the additional property to be initialized by a user. Instead, you can customize the ReportsStorage class to update the property value in code.
如果不希望用户初始化其他属性,则可以省略此部分。相反,您可以自定义报表存储类以更新代码中的属性值。

 

To make the newly introduced property visible in the Report Wizard, do the following.

  • In the platform-agnostic module project, inherit from the NewXafReportWizardParameters class and declare the Category string property.

要使新引入的属性在"报表向导"中可见,可以执行以下操作。

  • 在与平台无关的模块项目中,从 NewXafReportWizard 参数类继承并声明类别字符串属性。
using DevExpress.ExpressApp.DC;
using DevExpress.ExpressApp.ReportsV2;
using DevExpress.ExpressApp.ReportsV2.Win;
using DevExpress.XtraReports.UI;
// ...
[DomainComponent]
public class CustomReportWizardParameters : NewReportWizardParameters {
    public CustomReportWizardParameters(XtraReport report, Type reportDataType) : 
        base(report, reportDataType) { }
    public string Category { get; set; }
    public override void AssignData(IReportDataV2Writable reportData) {
        base.AssignData(reportData);
        if (reportData is MyReportDataV2) {
            ((MyReportDataV2)reportData).Category = Category;
        }
    }
}

 

  • In the WinForms module project, implement a View Controller. Override the OnActivated method, access the standard WinReportServiceController and subscribe to its WinReportServiceController.NewXafReportWizardShowing event. In the event handler, pass an instance of the CustomReportWizardParameters class to the Report Wizard.

  • 在 WinForms 模块项目中,实现视图控制器。覆盖 On 激活方法,访问标准的 WinReport 服务控制器并订阅其 WinReport 服务控制器。在事件处理程序中,将自定义报告向导参数类的实例传递给报表向导。

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.ReportsV2.Win;
    // ...
    public class ReportWizardModifyController : ViewController {
        WinReportServiceController reportServiceController;
        public ReportWizardModifyController() { }
        protected override void OnActivated() {
            base.OnActivated();
            reportServiceController = Frame.GetController<WinReportServiceController>();
            if (reportServiceController != null) {
                reportServiceController.NewXafReportWizardShowing +=
                    reportServiceController_NewXafReportWizardShowing;
            }
        }
        protected override void OnDeactivated() {
            reportServiceController.NewXafReportWizardShowing -=
                reportServiceController_NewXafReportWizardShowing;
            reportServiceController = null;
            base.OnDeactivated();
        }
        void reportServiceController_NewXafReportWizardShowing(object sender,
            NewXafReportWizardShowingEventArgs e) {
            if (!e.ReportDataType.Equals(typeof(MyReportDataV2))) return;
            CustomReportWizardParameters newReportParamsObject = new
                CustomReportWizardParameters(e.WizardParameters.Report, e.WizardParameters.ReportDataType);
            newReportParamsObject.Category = "Default";
            e.WizardParameters = newReportParamsObject;
        }
    }

     

  • In the ASP.NET module project, implement one more View Controller. Analogously, override the OnActivated method, access the standard WebReportServiceController and subscribe to its WebReportServiceController.NewReportWizardShowing event. In the event handler, pass an instance of the CustomReportWizardParameters class to the Report Wizard.

  • 在ASP.NET模块项目中,实现一个视图控制器。类似地,重写 OnActivated 方法,访问标准 Web 报表服务控制器并订阅其 Web 报表服务控制器。NewReportWizard 显示事件。在事件处理程序中,将自定义报告向导参数类的实例传递给报表向导。

    using DevExpress.ExpressApp;
    using DevExpress.ExpressApp.ReportsV2.Web;
    // ...
    public class ReportWizardModifyController : ViewController {
        WebReportServiceController reportServiceController;
        public ReportWizardModifyController() { }
        protected override void OnActivated() {
            base.OnActivated();
            reportServiceController = Frame.GetController<WebReportServiceController>();
            if (reportServiceController != null) {
                reportServiceController.NewReportWizardShowing +=
                    reportServiceController_NewReportWizardShowing;
            }
        }
        protected override void OnDeactivated() {
            reportServiceController.NewReportWizardShowing -=
                reportServiceController_NewReportWizardShowing;
            reportServiceController = null;
            base.OnDeactivated();
        }
        void reportServiceController_NewReportWizardShowing(object sender,
            WebNewReportWizardShowingEventArgs e) {
            if (!e.ReportDataType.Equals(typeof(MyReportDataV2))) return;
            CustomReportWizardParameters newReportParamsObject = new
                CustomReportWizardParameters(e.WizardParameters.Report, e.WizardParameters.ReportDataType);
            newReportParamsObject.Category = "Default";
            e.WizardParameters = newReportParamsObject;
        }
    }

     

The following Detail Views are added to the Application Model after performing the steps above.

  • MyReportData_DetailView
  • CustomReportWizardParameters_DetailView

执行上述步骤后,以下详细信息视图将添加到应用程序模型中。

  • MyReportData_DetailView
  • CustomReportWizardParameters_DetailView

 

To place the new Category item at the desired position, start the Model Editor and adjust these Detail View layouts.

要将新的"类别"项置于所需位置,请启动模型编辑器并调整这些"详细信息视图"布局。

ReportsV2_WizParams

For a detailed explanation of how to customize a Detail View's layout, refer to the View Items Layout Customization help topic.

有关如何自定义详细信息视图布局的详细说明,请参阅查看项目布局自定义帮助主题。

posted @ 2020-01-08 15:57  code first life  阅读(413)  评论(0编辑  收藏  举报