In this lesson, you will learn how to implement business classes from scratch. For this purpose, the Department and Position business classes will be implemented. These classes will be used in the Contact class, implemented previously. You will also learn the basics of automatic user interface construction for referenced objects.

在本课中,您将学习如何从头开始实现业务类。为此,将实施"部"和"职位"业务课程。这些类将在以前实现的"联系人"类中使用。您还将学习引用对象的自动用户界面构造基础知识。

Note

Before proceeding, take a moment to review the Inherit from the Business Class Library Class (XPO) lesson.

注意
在继续之前,请花点时间复习从商务舱库类 (XPO) 课程继承。

  • Add the following Department and Position persistent classes to the Contact.cs (Contact.vb) file.

  • 将以下部门和职位持久性类添加到Contact.cs (Contact.vb) 文件中。

    [DefaultClassOptions]
    [System.ComponentModel.DefaultProperty(nameof(Title))]
    public class Department : BaseObject {
    public Department(Session session) : base(session) { }
    private string title;
    public string Title {
    get { return title; }
    set { SetPropertyValue(nameof(Title), ref title, value); }
    }
    private string office;
    public string Office {
    get { return office; }
    set { SetPropertyValue(nameof(Office), ref office, value); }
    }
    }
    [DefaultClassOptions]
    [System.ComponentModel.DefaultProperty(nameof(Title))]
    public class Position : BaseObject {
    public Position(Session session) : base(session) { }
    private string title;
    public string Title {
    get { return title; }
    set { SetPropertyValue(nameof(Title), ref title, value); }
    }
    }

    These new classes are persistent, as they are BaseObject class descendants.

这些新类是持久性的,因为它们是 BaseObject 类后代。

Note

The DefaultProperty attribute is used in the code above. This attribute is used to specify the default property of the class. You can specify the most descriptive property of your class in the DefaultProperty attribute, and its values will be displayed in the following.

注意
DefaultProperty 属性用于上述代码。此属性用于指定类的默认属性。您可以在 DefaultProperty 属性中指定类最具描述性的属性,其值将显示在以下内容中。

  • Detail form captions
  • The leftmost column of a List View
  • The Lookup List Views (These Views will be explained in the last step of this lesson.)
  • 详细信息表单标题
  • 列表视图的最左侧列
  • 查找列表视图(这些视图将在本课的最后一步中介绍。

Refer to the Data Annotations in Data Model topic for additional information.

有关详细信息,请参阅数据模型中的数据注释主题。

  • Add the Department and Position properties to the Contact class. The following code demonstrates this.

  • 将"部门和位置"属性添加到"联系人"类。以下代码演示了这一点。

 [DefaultClassOptions]
public class Contact : Person {
//...
private Department department;
public Department Department {
get {return department;}
set {SetPropertyValue(nameof(Department), ref department, value);}
}
private Position position;
public Position Position {
get {return position;}
set {SetPropertyValue(nameof(Position), ref position, value);}
}
//...
}

The Contact class now exposes the Position and Department reference properties.

联系人类现在公开"位置"和"部门"引用属性。

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.

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

  • Run the WinForms or ASP.NET application. You will see how the user interface is automatically generated using the specified data structures. The navigation control will contain new Department and Position items, which will allow you to access Department and Position objects. Note that in the Contact Detail View, a lookup editor has been created for Department and Position. In this editor, a special type of View, Lookup List View, is used. Typically, this View has a single column corresponding to the class' default property. Using the lookup editor, you can select the required Department (Position) for the current Contact, and add new Department (Position) objects using the New button. In addition, you will also be able to edit existing Department (Position) objects by holding down SHIFT+CTRL and clicking the selected object.

  • 运行 WinForms 或ASP.NET应用程序。您将看到如何使用指定的数据结构自动生成用户界面。导航控件将包含新的"部门和位置"项,这将允许您访问"部门和定位"对象。请注意,在"联系人详细信息"视图中,已为部门和职位创建了查找编辑器。在此编辑器中,使用特殊类型的视图"查找列表视图"。通常,此视图具有对应于类的默认属性的单个列。使用查找编辑器,可以为当前联系人选择所需的部门(位置),并使用"新建"按钮添加新的"部门(位置)"对象。此外,您还可以通过按住 SHIFT_CTRL 并单击所选对象来编辑现有部门(位置)对象。

You can see the code demonstrated in this lesson 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%\Documents\DevExpress Demos 19.2\Components\eXpressApp Framework\MainDemo中。ASP.NET版本可在 http://demos.devexpress.com/XAF/MainDemo/ 在线获取

.

Implement Custom Business Classes and Reference Properties 实现自定义业务类和引用属性(XPO)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Implement Dependent Reference Properties 实现从属引用属性 (XPO)

    In this lesson, you will learn how to implement properties whose values can depend on other properti ...

  5. Implement Dependent Reference Properties实现依赖引用属性 (EF)

    In this lesson, you will learn how to implement properties whose values can depend on other properti ...

  6. [Tailwind] Create Custom Utility Classes in Tailwind

    In this lesson, we learn how to generate custom utility classes in tailwind. We add new properties t ...

  7. properties文件读写工具类

    java代码: import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; ...

  8. Implement Custom Cache Dependencies in ASP.NET 1.x

    Code download available at:CuttingEdge0407.exe(128 KB)   Contents What's a Cache Dependency, Anyway? ...

  9. [Tailwind] Extending Tailwind with Responsive Custom Utility Classes

    You are able to extend the custom css with hover, focus, group-hover, responsive variants class in t ...

随机推荐

  1. Redis入门(一)-Redis简介

    最近几年,Rddis非常的火,受到广大中大型公司,特别是互联网公司的青睐.而作为后端开发,如果你不知道Redis或不会用,没用过,你都不好意思出去找工作.可想而知Redis对于IT行业意义多么重大.对 ...

  2. go语言之数组

    1.go语言的数组和python的列表不一样,python的列表没有限定类型,而go的数组限定的类型,理由是这样的,请看下面的图 go语言的数组会数组中第一个值的内存地址,在我们上面的例子中,数组中的 ...

  3. Spring Boot 配置文件中的花样,看这一篇足矣!

    在快速入门一节中,我们轻松的实现了一个简单的RESTful API应用,体验了一下Spring Boot给我们带来的诸多优点,我们用非常少的代码量就成功的实现了一个Web应用,这是传统的Spring应 ...

  4. (十六)c#Winform自定义控件-文本框哪里去了?-HZHControls

    官网 http://www.hzhcontrols.com 前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kww ...

  5. ASP.NET MVC Action向视图传值之匿名类型

    在使用ASP.NET MVC过程中想必大家都有遇到过一个问题就是我们的Action如何向视图传递匿名类型的值呢,如果不做特殊处理则无法实现. 接下来我们来看一个示例: 在我们的控制中: using S ...

  6. selenium设置谷歌无头浏览器

    from selenium import webdriver from selenium.webdriver.chrome.options import Options def Browse(): c ...

  7. Java中的“浅复制”与“深复制”

    复制 将一个对象的引用复制给另一个对象,一共有三种方式.第一种方式是直接赋值,第二种方式是浅复制,第三种方式是深复制. 1.直接赋值 在Java中,A a1 = a2,这实际上复制的是引用,也就是说 ...

  8. Vue中通过Vue.extend动态创建实例

    Vue中通过Vue.extend动态创建实例 在Vue中,如果我们想要动态地来控制一个组件的显示和隐藏,比如通过点击按钮显示一个对话框或者弹出一条信息.我们通常会提前写好这个组件,然后通过v-if = ...

  9. Django用websocket实现聊天室之筑基篇

    最近闲来无事,无意发现一个聊天室的前端UI,看着挺好看的但是没有聊天室的通信代码,于是想给它安装电池(通信部分),先看UI: 开始通信部分的工作: 使用的组件: Django1.11.13 chann ...

  10. Spring Boot 2 使用自定义配置

    在application.yml定义配置后,可以使用Environment来读取配置,也可以使用@Value注解让业务代码去读取配置.如果属性较多,可以定义属性映射对象. 开发环境:IntelliJ ...