zoukankan      html  css  js  c++  java
  • How to: Display Non-Persistent Objects in a Report 如何:在报表中显示非持久性对象

    This topic describes how to create a report based on non-persistent data, which is not queried from a database using your ORM data model. This can be helpful for analysis and reporting data obtained from dynamic runtime calculations, stored procedures, arbitrary SQL queries or third-party services. To be able to use the Reports V2 Module in this scenario, you will need to define your data structure with the help of non-persistent classes and then create required object instances using the Non  Persistent ObjectSpace. ObjectsGetting event. A similar approach is demonstrated in the How to: Display a Non-Persistent Object's List View from the Navigation topic.

    本主题介绍如何基于非持久性数据创建报表,这些数据不会使用 ORM 数据模型从数据库查询。这对分析和报告从动态运行时计算、存储过程、任意 SQL 查询或第三方服务获得的数据非常有用。为了能够在此方案中使用报告 V2 模块,您需要在非持久性类的帮助下定义数据结构,然后使用非持久性 ObjectSpace 创建所需的对象实例。对象获取事件。在"如何:从导航主题显示非持久性对象的列表视图"中演示了类似的方法。

    • Declare a non-persistent class (e.g., MyNonPersistentObject), and decorate it with the DomainComponentAttribute and VisibleInReportsAttribute attributes.

    • 声明非持久性类(例如,Mynon持久性对象),并使用域组件属性和可见InReports属性属性来修饰它。

    using DevExpress.ExpressApp.DC;
    using DevExpress.Persistent.Base;
    // ...
    [DomainComponent, VisibleInReportsAttribute]
    public class MyNonPersistentObject {
        public string Name { get; set; }
    }
    Note 注意
    The INotifyPropertyChanged, IXafEntityObject and IObjectSpaceLink interface implementations were omitted in this example. However, it is recommended to support these interfaces in real-world applications (see PropertyChanged Event in Business Classes and Non-Persistent Objects).

    本示例中省略了 INotifyPropertyChanged、IXafEntityObject 和 IObjectSpaceLink 接口实现。但是,建议在实际应用程序中支持这些接口(请参阅业务类和非持久性对象中的属性更改事件)。

    • Create a predefined static report in Visual Studio or create a report at runtime using the MyNonPersistentObject as the report's data type.

    • 在 Visual Studio 中创建预定义的静态报表,或使用 MyNon 持久性对象在运行时创建报表作为报表的数据类型。

    In Visual Studio, set the DataSourceBase.ObjectTypeName property of the CollectionDataSource component to MyNonPersistentObject.

    在 Visual Studio 中,将数据收集Source.ObjectTypeName 组件的"数据收集数据源"属性设置为 Mynon持久性对象。

    NonPersistenReportVS

    At runtime, choose MyNonPersistentObject in the Data Type combo box of the Report Wizard.

    在运行时,在报表向导的数据类型组合框中选择 MyNon 持久对象。

    NonPersistenReportVS

    Important 重要
    ViewDataSource is not supposed to work with non-persistent data. Always use CollectionDataSource.
    ViewDataSource 不应使用非持久性数据。始终使用收集数据源。

    If you now preview the created report, it will display no data. Proceed to see how to populate the MyNonPersistentObject collection.

    如果现在预览创建的报表,它将不显示任何数据。继续查看如何填充 MyNon 持久对象集合。

    • Open the WinApplication.cs (WinApplication.vb), WebApplication.cs (WebApplication.vb) and/or MobileApplication.cs (MobileApplication.vb) code. Ensure that the NonPersistentObjectSpaceProvider is registered in the overridden CreateDefaultObjectSpaceProvider method (in addition to the existing XPObjectSpaceProvider or EFObjectSpaceProvider). Currently, this code is added automatically by the Solution Wizard, but it may be missing if you have created your project using an older version of XAF.

    • 打开WinApplication.cs(WinApplication.vb)、WebApplication.cs(WebApplication.vb)和/或MobileApplication.cs(MobileApplication.vb)代码。确保非持久对象空间提供程序已注册在重写的创建默认对象空间提供程序方法(除了现有的 XPObjectSpace 提供程序或 EFObjectSpace 提供程序)。目前,此代码由解决方案向导自动添加,但如果使用旧版本的 XAF 创建项目,则可能会丢失此代码。

      protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
          // ...
          args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
      }
    • Create a Window Controller. In the overridden OnActivated method, subscribe to the XafApplication.ObjectSpaceCreated event. In the event handler, if the ObjectSpaceCreatedEventArgs.ObjectSpace is of the NonPersistentObjectSpace type, subscribe to the NonPersistentObjectSpace.ObjectsGetting event and populate the e.Objects collection as required.

    • 创建窗口控制器。在重写的 On 激活方法中,订阅 Xaf 应用程序.ObjectSpace 创建事件。在事件处理程序中,如果 ObjectSpace 创建事件Args.ObjectSpace 属于非持久对象空间类型,请订阅非持久对象空间.Object获取事件并根据需要填充 e.Objects 集合。

      using DevExpress.ExpressApp;
      // ...
      public class NonPersistentClassWindowController : WindowController {
          public NonPersistentClassWindowController()
              : base() {
              TargetWindowType = WindowType.Main;
          }
          protected override void OnActivated() {
              base.OnActivated();
              Application.ObjectSpaceCreated += Application_ObjectSpaceCreated;
          }
          private void Application_ObjectSpaceCreated(Object sender, ObjectSpaceCreatedEventArgs e) {
              if (e.ObjectSpace is NonPersistentObjectSpace) {
                  ((NonPersistentObjectSpace)e.ObjectSpace).ObjectsGetting += ObjectSpace_ObjectsGetting;
              }
          }
          private void ObjectSpace_ObjectsGetting(Object sender, ObjectsGettingEventArgs e) {
              if (e.ObjectType == typeof(MyNonPersistentObject)) {
                  BindingList<MyNonPersistentObject> objects = new BindingList<MyNonPersistentObject>();
                  for (int i = 1; i < 10; i++) {
                      objects.Add(new MyNonPersistentObject() { Name = string.Format("Object {0}", i) });
                  }
                  e.Objects = objects;
              }
          }
          protected override void OnDeactivated() {
              base.OnDeactivated();
              Application.ObjectSpaceCreated -= Application_ObjectSpaceCreated;
          } 
      }

      The result is demonstrated in the image below.

      结果如下图所示。

    NonPersistenReportWin

  • 相关阅读:
    python应用之文件属性浏览
    python进阶之路之文件处理
    magento安装时的数据库访问错误
    magento麦进斗客户地址属性不保存在sales_flat_order_address
    自动填写麦进斗Magento进货地址字段
    麦进斗magentoRequireJs回调失败
    如何在麦进斗magento2中调用站外的JS?
    在magento1.9结账地址中删除验证
    麦进斗:在windows系统里面刷新magento2的缓存
    如何安装麦进斗Magento2
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Display-Non-Persistent-Objects-in-a-Report.html
Copyright © 2011-2022 走看看