zoukankan      html  css  js  c++  java
  • How to: Display a List of Non-Persistent Objects in a Popup Dialog 如何:在弹出对话框中显示非持久化对象列表

    This example demonstrates how to populate and display a list of objects that are not bound to the database (non-persistent objects). A sample application that stores a list of books will be created in this example. An Action that displays a list of duplicate books in a pop-up window will be added to this application.

    此示例演示如何填充和显示未绑定到数据库的对象(非持久性对象)的列表。此示例中将创建一个存储书籍列表的示例应用程序。在弹出窗口中显示重复书籍列表的操作将添加到此应用程序。

    Note 注意
    Mobile applications do not show objects from collection properties in Detail Views. To implement this functionality in the Mobile UI, show a List View as described in the How to: Display a Non-Persistent Object's List View from the Navigation topic.
    移动应用程序不会在"详细信息视图"中显示来自集合属性的对象。要在移动 UI 中实现此功能,请查看"如何:从导航主题显示非持久性对象的列表视图"中所述的列表视图。
    Tip 提示
    A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E980
    完整的示例项目可在 DevExpress 代码示例数据库中找到,http://www.devexpress.com/example=E980

    .

    1.Define the Book persistent class.

       定义书籍持久性类。

    [DefaultClassOptions]
    public class Book : BaseObject {
        public Book(Session session) : base(session) { }
        public string Title {
            get { return GetPropertyValue<string>(nameof(Title)); }
            set { SetPropertyValue<string>(nameof(Title), value); }
        }
    }

    The Book class, as its name implies, is used to represent books. It inherits BaseObject, and thus it is persistent. It contains a single Title property, which stores a book's title.

    书类,顾名思义,是用来代表书籍的。它继承 BaseObject,因此它是永久性的。它包含一个标题属性,该属性存储书籍的标题。

    2.Define two non-persistent classes - Duplicate and DuplicatesList.

       定义两个非持久性类 - 重复类和重复类列表。

    [DomainComponent]
    public class Duplicate {
        [Browsable(false), DevExpress.ExpressApp.Data.Key]
        public int Id;
        public string Title { get; set; }
        public int Count { get; set; }
    }
    [DomainComponent]
    public class DuplicatesList {
        private BindingList<Duplicate> duplicates;
        public DuplicatesList() {
            duplicates = new BindingList<Duplicate>();
        }
        public BindingList<Duplicate> Duplicates { get { return duplicates; } }
    }
    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).These classes are not inherited from an XPO base persistent class, and are not added to the Entity Framework data model. As a result, they are not persistent. The DomainComponentAttribute applied to these classes indicates that these classes should be added to the Application Model and thus will participate in UI construction. The Duplicate non-persistent class has three public properties - Title, Count and Id. The Title property stores the title of a book. The Count property stores the total number of books with the title specified by the Title property. Id is a key property. It is required to add a key property to a non-persistent class and provide a unique key property value for each class instance in order for the ListView to operate correctly. To specify a key property, use the KeyAttribute. The DuplicatesList non-persistent class aggregates the duplicates via the Duplicates collection property of the BindingList<Duplicate> type.
    本例中省略了INotifyPropertyChanged、IXafEntityObject和IObjectSpaceLink接口实现。但是,建议在实际应用程序中支持这些接口(请参阅业务类和非持久性对象中的属性更改事件)。这些类不是从 XPO 基基持久类继承的,也不会添加到实体框架数据模型中。因此,它们不是持久的。应用于这些类的域组件属性指示这些类应添加到应用程序模型中,从而将参与 UI 构造。重复的非持久性类有三个公共属性 - 标题、计数和 ID。"标题"属性存储书籍的标题。"Count"属性存储具有"标题"属性指定的帐簿总数。Id 是密钥属性。需要将键属性添加到非持久性类,并为每个类实例提供唯一的键属性值,以便 ListView 能够正常运行。要指定键属性,请使用"键属性"。复制列表非持久性类通过 BindingList<Duplicate> 类型的重复集合属性聚合重复项。

     

    3.Create the following ShowDuplicateBooksController View Controller.

       创建以下显示复制书控制器视图控制器。

    public class ShowDuplicateBooksController : ObjectViewController<ListView, Book> {
        public ShowDuplicateBooksController() {
            PopupWindowShowAction showDuplicatesAction = 
                new PopupWindowShowAction(this, "ShowDuplicateBooks", "View");
            showDuplicatesAction.CustomizePopupWindowParams += showDuplicatesAction_CustomizePopupWindowParams;
        }
        void showDuplicatesAction_CustomizePopupWindowParams(object sender, CustomizePopupWindowParamsEventArgs e) {
            Dictionary<string, int> dictionary = new Dictionary<string, int>();
            foreach(Book book in View.CollectionSource.List) {
                if(!string.IsNullOrEmpty(book.Title)) {
                    if(dictionary.ContainsKey(book.Title)) {
                        dictionary[book.Title]++;
                    }
                    else 
                        dictionary.Add(book.Title, 1);
                }
            }
            var nonPersistentOS = Application.CreateObjectSpace(typeof(DuplicatesList));
            DuplicatesList duplicateList =nonPersistentOS.CreateObject<DuplicatesList>();
            int duplicateId = 0;
            foreach(KeyValuePair<string, int> record in dictionary) {
                if (record.Value > 1) {
                    var dup = nonPersistentOS.CreateObject<Duplicate>();
                    dup.Id = duplicateId;
                    dup.Title = record.Key;
                    dup.Count = record.Value;
                    duplicateList.Duplicates.Add(dup);
                    duplicateId++;
                }
            }
            nonPersistentOS.CommitChanges();
            DetailView detailView = Application.CreateDetailView(nonPersistentOS, duplicateList);
            detailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit;
            e.View = detailView;
            e.DialogController.SaveOnAccept = false;
            e.DialogController.CancelAction.Active["NothingToCancel"] = false;
        }
    }

    This Controller inherits ObjectViewController<ListView, Book>, and thus, targets List Views that display Books. In the Controller's constructor, the ShowDuplicateBooksPopupWindowShowAction is created. In the Action's PopupWindowShowAction.CustomizePopupWindowParams event handler, the Books are iterated to find the duplicates. For each duplicate book found, the Duplicate object is instantiated and added to the DuplicatesList.Duplicates collection. Note that a unique key value (Id) is assigned for each Duplicate. Finally, a DuplicatesList Detail View is created and passed to the handler's CustomizePopupWindowParamsEventArgs.View parameter. As a result, a DuplicatesList object is displayed in a pop-up window when a user clicks ShowDuplicateBooks.

    此控制器继承对象视图控制器[列表视图,Book],因此,目标列表视图显示书籍。在控制器的构造函数中,将创建"显示复制书"PopupWindowShowAction。在操作的"弹出窗口窗口显示操作"中,自定义PopupWindowParams事件处理程序,将迭代"书籍"以查找重复项。对于找到的每个重复书籍,复制对象将实例化并添加到重复列表。请注意,为每个副本分配了唯一的键值 (Id)。最后,创建一个重复列表详细信息视图,并将其传递给处理程序的"自定义弹出窗口"ParamsEventArgs.View 参数。因此,当用户单击"显示复制书"时,在弹出窗口中将显示一个重复列表对象。

    The following images illustrate the implemented Action and its pop-up window.

    下图说明了实现的操作及其弹出窗口。

    Windows Forms:

    窗口窗体:

    ShowDuplicateBooksWin

    ASP.NET:

    ShowDuplicateBooksWeb

     
  • 相关阅读:
    在纪念中国人民抗日战争暨世界反法西斯战争胜利70周年大会上的讲话
    ConcurrentHashMap 的实现原理
    聊聊并发(四)——深入分析ConcurrentHashMap
    Mybatis 动态 SQL
    Mybatis Mapper XML 文件
    MySQL的语句执行顺序
    Java 集合细节(二):asList 的缺陷
    java中 列表,集合,数组之间的转换
    将java中数组转换为ArrayList的方法实例(包括ArrayList转数组)
    把Java数组转换为List时的注意事项
  • 原文地址:https://www.cnblogs.com/foreachlife/p/How-to-Display-a-List-of-Non-Persistent-Objects-in-a-Popup-Dialog.html
Copyright © 2011-2022 走看看