方法:一覧への報告はどのようにカスタム列を追加します。追加のカスタム列をレポートのリストに

このトピックでは、ストアに使用永続クラスをカスタマイズする方法について説明し、レポートをレポートオブジェクトに追加情報を関連付けること。例えば、追加カテゴリーのプロパティは、で追加の列になりますレポートリストビュー、およびエンドユーザーは、カテゴリ別にグループ、ソートやフィルタできるようになります。

このトピックでは、追加情報やオブジェクトに関連付けられたレポートするために、永続的なレポートを保存するためのクラスをカスタマイズする方法について説明します。たとえば、レポートのリストビュー内の別の列が表示されますになります「class」属性を追加し、エンドユーザーは、ソートやフィルタ、カテゴリ別にグループ化することができるようになります。

 

リサイズ:

ReportsV2_WizParamsRuntime

ASP.NET:

ReportsV2_WizParamsRuntime_Web

このトピックでは、あなたが使用していますXAFアプリケーション持っていると仮定されるレポートV2モジュール、および1つまたは複数のレポートを(参照作成したレポートV2モジュールの概要を)。

このトピックでは、あなたがXAFアプリケーションV2モジュールを使用してレポートを持っている、とあなたが一つ以上のレポート(レポートの概要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

詳細表示のレイアウトをカスタマイズする方法の詳細については、を参照してくださいアイテムの表示レイアウトのカスタマイズのヘルプトピック。

レイアウトビューをカスタマイズする方法の詳細については、ビューのプロジェクトレイアウトカスタムヘルプトピックを参照してください。

おすすめ

転載: www.cnblogs.com/foreachlife/p/How-to-Add-a-Custom-Column-to-the-Reports-List.html