标签:scratch which rom 默认 code 根据 组合 ica 字符
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.
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(4096)] 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)
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.
请注意使用默认类选项属性属性。在本教程中,此属性表示以下功能将可用于联系人业务类。
To apply each of these options separately, use the NavigationItemAttribute, CreatableItemAttribute and VisibleInReportsAttribute attributes.
要单独应用每个选项,请使用导航项属性、可操作项属性和可见中报表属性属性。
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.
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/
.
.
标签:scratch which rom 默认 code 根据 组合 ica 字符
原文地址:https://www.cnblogs.com/foreachlife/p/InheritfromtheBusinessClassLibrary.html