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, );
}
}
var nonPersistentOS = Application.CreateObjectSpace(typeof(DuplicatesList));
DuplicatesList duplicateList =nonPersistentOS.CreateObject<DuplicatesList>();
int duplicateId = ;
foreach(KeyValuePair<string, int> record in dictionary) {
if (record.Value > ) {
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:

窗口窗体:

ASP.NET:

 

How to: Display a List of Non-Persistent Objects in a Popup Dialog 如何:在弹出对话框中显示非持久化对象列表的更多相关文章

  1. 解决display none到display block 渲染时间过长的问题,以及bootstrap模态框导致其他框中input不能获得焦点问题的解决

    在做定制页面的时候,遇到这么一个问题,因为弹出框用的是bootstrap的自带的弹出框,控制显示和隐藏也是用自带的属性控制 控制显示,在触发的地方 例如botton上面加上 data-toggle=& ...

  2. Ecstore后台中显示页面display,page,singlepage方法的区别?

    dispaly 显示的页面不包含框架的其他页面,只是本身的页面(使用范围:Ecstore的前端.后端). page 显示的页面包含在框架的里面(使用范围:Ecstore的前端.后端). singlep ...

  3. 完美解决xhost +报错: unable to open display "" 装oracle的时候总是在弹出安装界面的时候出错

    详细很多朋友在装oracle的时候总是在弹出安装界面的时候出错,界面就是蹦不出来. oracle安装 先切换到root用户,执行xhost + 然后再切换到oracle用户,执行export DISP ...

  4. table中tr的display属性在火狐中显示不正常,IE中显示正常

    最近在作项目的时候碰到一个问题,就是需要AJAX来交互显示<tr> </tr> 标签内的东西,按照常理,对于某一单元行需要显示时,使用:display:block属性,不需要显 ...

  5. tr设置display属性时,在FF中td合并在第一个td中显示的问题

      今天用firefox测试页面的时候,发现用javascript控制 tr 的显示隐藏时,当把tr的显示由“display:none”改为“display:block”时,该tr下的td内容合并到了 ...

  6. ADD software version display

    ADD software version display ADD software version display1. Problem Description2. Analysis3. Solutio ...

  7. Add an Action that Displays a Pop-up Window 添加显示弹出窗口按钮

    In this lesson, you will learn how to create an Action that shows a pop-up window. This type of Acti ...

  8. 使用 WSO2 API Manager 管理 Rest API

    WSO2 API Manager 简介 随着软件工程的增多,越来越多的软件提供各种不同格式.不同定义的 Rest API 作为资源共享,而由于这些 API 资源的异构性,很难对其进行复用.WSO2 A ...

  9. paper 77:[转载]ENDNOTE使用方法,常用!

    一.简介  EndNote是一款用于海量文献管理和批量参考文献管理的工具软件,自问世起就成为科研界的必备武器.在前EndNote时代,文献复习阶段从各大数据库中搜集到的文献往往千头万绪.或重复或遗漏, ...

随机推荐

  1. socket实现一个简单的echo服务

    服务端的实现: public class EchoServer{ //创建一个serverSocket private final ServerSocket serverSocket; //创建一个构 ...

  2. 浏览器/外网访问docker container中的hadoop

    假设你制作了个docker的 hadoop的镜像,镜像名叫 hd_image,如果想在外网的浏览器中访问hadoop的50070和8088端口,则在启动镜像hd_image时, 脚本如下: docke ...

  3. luogu P2343 宝石管理系统 |分块+堆

    题目描述 GY君购买了一批宝石放进了仓库.有一天GY君心血来潮,想要清点他的宝石,于是把m个宝石都取出来放进了宝石管理系统.每个宝石i都有一个珍贵值vi,他希望你能编写程序查找到从大到小第n珍贵的宝石 ...

  4. MySql数据库之单表数据查询

    查询数据 1.查询所有数据: select * from 表名; 2.根据指定条件查询数据:

  5. UESTC-1964命运石之门(类似SPFA的BFS)

    命运石之门 Time Limit: 1000 MS     Memory Limit: 256 MB Submit Status "这一切都是命运石之门的选择!" 凶真博士发明了能 ...

  6. 将项目部署到github的方法

    GitHub是一个面向开源及私有软件项目的托管平台,因为只支持git 作为唯一的版本库格式进行托管,故名GitHub. GitHub于2008年4月10日正式上线,除了Git代码仓库托管及基本的 We ...

  7. css3(1)

    边框: 盒子圆角:border-radius:5px / 20%: border-radius:5px 4px 3px 2px; 左上,右上,右下,左下. 盒子阴影: box-shadow: box- ...

  8. 【Seleniuem】selenium.common.exceptions.InvalidSelectorException

    selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: An invalid or illega ...

  9. 【RabbitMQ】显示耗时处理进度

    [RabbitMQ]显示耗时处理进度 通过网页提交一个耗时的请求,然后启动处理线程,请求返回.处理线程每完成一部分就给前台推送完成的数量,前端显示进度. 依赖jar <?xml version= ...

  10. flask之分析线程和协程

    flask之分析线程和协程 01 思考:每个请求之间的关系 我们每一个请求进来的时候都开一个进程肯定不合理,那么如果每一个请求进来都是串行的,那么根本实现不了并发,所以我们假定每一个请求进来使用的是线 ...