In this lesson, you will learn how to implement business classes for your application using the Business Class Library. This library contains the most typical ready-to-use business classes. You will implement a custom Contact class by deriving from the Person class available in this library, and implement several additional properties. You will also learn the basics of automatic user interface construction based on data.

在本课中,您将学习如何使用 Business 类库为应用程序实现业务类。此库包含最典型的即用型业务类。您将通过从此库中可用的 Person 类派生来实现自定义联系人类,并实现多个附加属性。您还将学习基于数据的自动用户界面构造的基础知识。

  • Typically, business classes should be implemented in a platform-independent module project, so that the same objects will be available in both WinForms and ASP.NET applications. To simplify the implementation of XAF-specific classes, several Visual Studio templates are supplied. In this lesson, you will use the XPO Business Object template to implement a persistent business class. Right-click the Business Objects folder in the MySolution.Module project, and choose Add DevExpress Item | New Item... to invoke Template Gallery.Then select the XAF Business Object | XPO Business Object template, specify Contact.cs as the new item's name and press Add Item. As a result, you will get an automatically generated code file with a single class declaration.

  • 通常,业务类应在独立于平台的模块项目中实现,以便 WinForms 和ASP.NET应用程序中都提供相同的对象。为了简化 XAF 特定类的实现,提供了多个可视化工作室模板。在本课中,您将使用 XPO 业务对象模板来实现持久性业务类。右键单击 MySolution.模块项目中的业务对象文件夹,然后选择"添加 DevExpress 项目" |新项目...调用模板库,然后选择 XAF 业务对象 |XPO 业务对象模板,将Contact.cs指定为新项目的名称,然后按"添加项"。因此,您将获得一个自动生成的代码文件,其中只有一个类声明。

    The auto-generated Contact class is a BaseObject class descendant, which is one of the base persistent classes. You should inherit one of these classes when implementing a persistent class from scratch is required, or use Business Class Library classes (which are derived from the BaseObject class as well). For a general overview of the business class concept, refer to the Business Classes vs Database Tables topic.

  • 自动生成的 Contact 类是 BaseObject 类后代,它是基持久性类之一。当需要从头开始实现持久类时,应继承这些类之一,或使用 Business 类库类(也派生自 BaseObject 类)。有关业务类概念的概述,请参阅业务类与数据库表主题。
  • Replace the automatically generated class declaration with the following code.

  • 将自动生成的类声明替换为以下代码。

        C#
    VB.NET [DefaultClassOptions]
    public class Contact : Person {
    public Contact(Session session) : base(session) { }
    private string webPageAddress;
    public string WebPageAddress {
    get { return webPageAddress; }
    set { SetPropertyValue(nameof(WebPageAddress), ref webPageAddress, value); }
    }
    private string nickName;
    public string NickName {
    get { return nickName; }
    set { SetPropertyValue(nameof(NickName), ref nickName, value); }
    }
    private string spouseName;
    public string SpouseName {
    get { return spouseName; }
    set { SetPropertyValue(nameof(SpouseName), ref spouseName, value); }
    }
    private TitleOfCourtesy titleOfCourtesy;
    public TitleOfCourtesy TitleOfCourtesy {
    get { return titleOfCourtesy; }
    set { SetPropertyValue(nameof(TitleOfCourtesy), ref titleOfCourtesy, value); }
    }
    private DateTime anniversary;
    public DateTime Anniversary {
    get { return anniversary; }
    set { SetPropertyValue(nameof(Anniversary), ref anniversary, value); }
    }
    private string notes;
    [Size()]
    public string Notes {
    get { return notes; }
    set { SetPropertyValue(nameof(Notes), ref notes, value); }
    }
    }
    public enum TitleOfCourtesy { Dr, Miss, Mr, Mrs, Ms };

    As you can see, the Contact class ancestor is changed from BaseObject to Person, and several custom properties are implemented. Note that the Contact constructor and the SetPropertyValue method is used in property setters. These are specifics of the eXpress Persistent Objects (XPO)

  • 如您所见,联系人类祖先从"基本对象"更改为"人",并实现了多个自定义属性。请注意,在属性设置器中使用了 Contact 构造函数和 SetPropertyValue 方法。这些是电子压持久对象 (XPO) 的具体细节

object-relational mapper utilized by XAF. You can refer to the XPO Best Practices

XAF 使用的对象关系映射器。您可以参考 XPO 最佳实践

knowledge base article and the Simplified Property Syntax topic in the XPO documentation for details.

知识库文章和 XPO 文档中的简化属性语法主题的详细信息。

Note the use of the DefaultClassOptionsAttribute attribute. In this tutorial, this attribute means that the following capabilities will be available for the Contact business class.

请注意使用默认类选项属性属性。在本教程中,此属性表示以下功能将可用于联系人业务类。

  • The Contact item will be added to the main form's navigation control. When clicking this item, a List View will be displayed. This List View represents a list of objects of the Contact type.
  • The Contact item will be added to the submenu of the New () button when objects of another type are displayed in the List View. Click this item to invoke a Contact detail form and create a new Contact object.
  • The Contact objects will be provided as a data source to generate reports (see Create a Report in Visual Studio).
  • 联系人项将添加到主窗体的导航控件中。单击此项目时,将显示列表视图。此列表视图表示联系人类型的对象的列表。
  • 当另一种类型的对象显示在列表视图中时,联系人项将添加到"新建(new_dropdown_btn)"按钮的子菜单中。单击此项目可调用"联系人详细信息"窗体并创建新的"联系人"对象。
  • 联系人对象将作为数据源提供以生成报告(请参阅在 Visual Studio 中创建报表)。

To apply each of these options separately, use the NavigationItemAttribute, CreatableItemAttribute and VisibleInReportsAttribute attributes.

要单独应用每个选项,请使用导航项属性、可操作项属性和可见中报表属性属性。

Note

If you have CodeRush

注意
如果您有代码CodeRush

  • installed, you can use Code Templates when implementing business classes. Using Code Templates decreases code creation time, because it helps avoid having to type the entire code manually and allows you to create regular code sections with only a few keystrokes. To learn about the built-in Code Templates for eXpress Persistent Objects, refer to the XPO and XAF Templates topic.

  • Run the WinForms or ASP.NET application. You will see how the user interface is automatically generated using the specified data structures. There will be a navigation control allowing you to display the Contact list. You will be able to customize this collection using the corresponding editors. If you click the New button or double-click an existing record, the application will show a detail form (Detail View) filled with editors for each data field.

  • 在实现业务类时,可以使用代码模板。使用代码模板可缩短代码创建时间,因为它有助于避免手动键入整个代码,并允许您只需几个击键即可创建常规代码部分。要了解 eXpress 持久对象的内置代码模板,请参阅 XPO 和 XAF 模板主题。

  • 运行 WinForms 或ASP.NET应用程序。您将看到如何使用指定的数据结构自动生成用户界面。将有一个导航控件,允许您显示联系人列表。您将能够使用相应的编辑器自定义此集合。如果单击"新建"按钮或双击现有记录,应用程序将显示一个详细信息表单(详细信息视图),其中填充了每个数据字段的编辑器。

    The following image demonstrates the Detail and List Views in the WinForms application.

  • 下图演示了 WinForms 应用程序中的详细信息视图和列表视图。

    Notice that many elements have been generated in an intuitive manner in very little time. The proper editors are created for data fields, and appropriate editors are used in the grid controls to display data. Note that a combo box editor has been created for Title Of Courtesy (an enumerator). Also note that captions have automatically been transformed from camel-case to space-separated strings, form titles are automatically updated, etc.

  • 请注意,许多元素是在非常少的时间内以直观的方式生成的。为数据字段创建适当的编辑器,并在网格控件中使用适当的编辑器来显示数据。请注意,已为礼貌标题(枚举器)创建了组合框编辑器。另请注意,标题已自动从骆驼大小写转换为空格分隔的字符串,表单标题会自动更新,等等。

  • You can use the grid features to show, hide and rearrange columns, and apply grouping, filtering and sorting to a List View at runtime. In the WinForms application, you can customize the editor layout on the detail form as you like at runtime. For this purpose, right-click an empty space and select Customize Layout. You can now move editors to the required positions. To learn how to customize the editor layout at design time, refer to the Customize the View Items Layout topic. Additionally, you can refer to the View Items Layout Customization and List View Column Generation topics to see how the default Detail View layout and default List View column set are generated.

  • 您可以使用网格要素来显示、隐藏和重新排列列,并在运行时对列表视图应用分组、筛选和排序。在 WinForms 应用程序中,您可以在运行时根据需要自定义详细信息窗体上的编辑器布局。为此,右键单击空白区域并选择"自定义布局"。您现在可以将编辑器移动到所需的位置。要了解如何在设计时自定义编辑器布局,请参阅自定义视图项布局主题。此外,还可以参考"查看项目布局自定义"和"列表视图列生成"主题,以查看如何生成默认"详细信息视图"布局和默认列表视图列集。

You can see the code demonstrated here in the MySolution.Module | Business Objects | Contact.cs (Contact.vb) file of the Main Demo installed with XAF. The MainDemo application is installed in %PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

您可以在 MySolution.模块 |业务对象 |Contact.cs (Contact.vb) 文件的主演示安装与 XAF.默认情况下,主演示应用程序安装在 %PUBLIC%_文档_DevExpress 演示 19.2_组件_eXpressApp 框架_MainDemo 中。ASP.NET版本可在 http://demos.devexpress.com/XAF/MainDemo/ 在线获取%PUBLIC%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo by default. The ASP.NET version is available online at http://demos.devexpress.com/XAF/MainDemo/

.

.

XAF-从业务类继承 (XPO)的更多相关文章

  1. Add a Class from the Business Class Library 从业务类库添加类 (XPO)

    In this lesson, you will learn how to use business classes from the Business Class Library as is. Fo ...

  2. Mybatis-plus 实体类继承关系 插入默认值

    在实际开发中,会定义一些公共字段,而这些公共字段,一般都是在进行操作的时候由程序自动将默认值插入.而公共的字段一般会被封装到一个基础的实体类中,同时实体类中会实现相应的getter setter 方法 ...

  3. Implement Custom Business Classes and Reference Properties 实现自定义业务类和引用属性(XPO)

    In this lesson, you will learn how to implement business classes from scratch. For this purpose, the ...

  4. How to: Generate XPO Business Classes for Existing Data Tables 如何:为现有数据表生成 XPO 业务类

    From the Tutorial and other documentation sources, you learned how to create business classes for yo ...

  5. How to: Handle Renamings and Deletions of Business Classes and their Properties 如何:处理业务类及其属性的重命名和删除

    When developing an XAF application, you may be required to rename a persistent class or property due ...

  6. Implement Custom Business Classes and Reference Properties实现自定义业务类和引用属性(EF)

    In this lesson, you will learn how to implement business classes from scratch. For this purpose, the ...

  7. Quartz总结(二):定时任务中使用业务类(XXService)

    零.引言 上一篇文章:讲到了Spring集成Quartz的几种基本方法. 在实际使用的时候,往往会在定时任务中调用某个业务类中的方法,此时使用QuartzJobBean和MethodInvokeJob ...

  8. java一个类 继承HttpServlet 和实现Servlet区别

    java一个类 继承HttpServlet 和实现Servlet区别 servlet 是一个接口,如果实现这个接口,那么就必须实现接口里面定义的所有方法 而HttpServlet实现了servlet接 ...

  9. 快速部署业务类为webapi服务

    接着前一篇博文,将接口快速打包固定请求格式,不需要修改代码,可以自动完成接口调用,实际上就是生成了一个接口的代理类. 那么仅仅是接口请求代理,没有服务端怎么行?所以需要将实现接口的类部署为webapi ...

随机推荐

  1. Linux下MySQL数据库的my.cnf配置文件,解决中文乱码问题

    系统 CentOS 7.7 MySQL - 5.7.28文件放置目录:/etc/文件权限:644解决问题:存储中文数据乱码 # For advice on how to change settings ...

  2. 面试:Stream#foreach方法摸底三问,你都了解吗

    JAVA8 新增了 Stream API,而在 Stream API 中又为程序员提供了一个遍历集合的 foreach 方法:java.util.stream.Stream#forEach. 那你对这 ...

  3. js 轮播图效果

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  4. MySQL入门——Linux下安装后的配置文件

    MySQL入门——Linux下安装后的配置文件 摘要:本文主要了解了在Linux环境下安装MySQL后的配置文件的位置,以及如何创建配置文件. 查看配置文件的加载顺序 找到mysqld的路径 通过wh ...

  5. Java生鲜电商平台-SpringCloud分布式请求跟踪系统设计与实践

    Java生鲜电商平台-SpringCloud分布式请求跟踪系统设计与实践 Java生鲜电商平台微服务现状 某个服务挂了,导致上游大量报警,如何快速定位哪个服务出问题? 某个核心挂了,导致大量报错,如何 ...

  6. JS While

    JS While 只要指定条件为 true,循环就可以一直执行代码. while 循环 While 循环会在指定条件为真时循环执行代码块. 语法 while (条件) { 需要执行的代码 } whil ...

  7. Spring Boot 2 构建可部署的war包

    默认情况下Spring Boot使用了内嵌的Tomcat服务器,项目最终被打成jar包运行,每个jar包可以被看作一个独立的Web服务器.传统的Web开发,一般会将Web应用打成一个war包,然后将其 ...

  8. 未能找到元数据文件**.dll解决办法

    解决方案里有很多项目.生成时提示100多个错误,都是未能找到元数据文件**.dll. 那就清理一下解决方案,一个一个来吧. 生成GateWay.Utilities项目时,虽然提示成功了,却发现bin/ ...

  9. LeetCode刷题191118

    博主渣渣一枚,刷刷leetcode给自己瞅瞅,大神们由更好方法还望不吝赐教.题目及解法来自于力扣(LeetCode),传送门. 算法: 给定一个包含 m x n 个元素的矩阵(m 行, n 列),请按 ...

  10. 4. 语义"陷阱"

    1. 假定对于下标越界的数组元素取其地址也是非法的,那么对于本书3.6(该标题下为4.6)节中的bufwrite程序应该如何书写? void bufwrite(char *p, int n){ whi ...