你的位置:首页 > 软件开发 > ASP.net > XAF应用开发教程(二)业务对象模型之简单类型属性

XAF应用开发教程(二)业务对象模型之简单类型属性

发布时间:2015-12-22 12:00:15
使用过ORM的朋友对这一部分理解起来会非常快,如果没有请自行补习吧:D.不说废话,首先,我们来开发一个简单的CRM系统,CRM系统第一个信息当然是客户信息。我们只做个简单 的客户信息来了解一下XAF好了。 新建项之后,可以看到如下代码界面:using System;using ...

使用过ORM的朋友对这一部分理解起来会非常快,如果没有请自行补习吧:D.

不说废话,首先,我们来开发一个简单的CRM系统,CRM系统第一个信息当然是客户信息。我们只做个简单 的客户信息来了解一下XAF好了。

 XAF应用开发教程(二)业务对象模型之简单类型属性

新建项之后,可以看到如下代码界面:

using System;using System.Linq;using System.Text;using DevExpress.Xpo;using DevExpress.ExpressApp;using System.ComponentModel;using DevExpress.ExpressApp.DC;using DevExpress.Data.Filtering;using DevExpress.Persistent.Base;using System.Collections.Generic;using DevExpress.ExpressApp.Model;using DevExpress.Persistent.BaseImpl;using DevExpress.Persistent.Validation;namespace XCRMDemo.Module.BusinessObjects{  [DefaultClassOptions]  //[ImageName("BO_Contact")]  //[DefaultProperty("DisplayMemberNameForLookupEditorsOfThisType")]  //[DefaultListViewOptions(MasterDetailMode.ListViewOnly, false, NewItemRowPosition.None)]  //[Persistent("DatabaseTableName")]  // Specify more UI options using a declarative approach (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112701.aspx).  public class 客户 : BaseObject  { // Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).    public 客户(Session session)      : base(session)    {    }    public override void AfterConstruction()    {      base.AfterConstruction();      // Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx).    }    //private get='_blank'>string _PersistentProperty;    //[XafDisplayName("My display name"), ToolTip("My hint message")]    //[ModelDefault("EditMask", "(000)-00"), Index(0), VisibleInListView(false)]    //[Persistent("DatabaseColumnName"), RuleRequiredField(DefaultContexts.Save)]    //public string PersistentProperty {    //  get { return _PersistentProperty; }    //  set { SetPropertyValue("PersistentProperty", ref _PersistentProperty, value); }    //}    //[Action(Caption = "My UI Action", ConfirmationMessage = "Are you sure?", ImageName = "Attention", AutoCommit = true)]    //public void ActionMethod() {    //  // Trigger a custom business logic for the current record in the UI (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112619.aspx).    //  this.PersistentProperty = "Paid";    //}  }}
Oid是在BaseObject中定义的,所以客户类会自动建立这个字段。OptimisticLockField:是XAF为了解决并发冲突而建立的字段。GCRecord:继承自BaseObject的类在删除记录时只是逻辑删除,即只是将GCRecord中记录一个值,而没有删除的记录则为Null.
 39     private string _姓名; 40 41     public string 姓名 42     { 43       get { return _姓名; } 44       set { SetPropertyValue("姓名", ref _姓名, value); } 45     }
这个属性和以往开发中的方法没有什么大的不同,仅是在set部分调用了SetPropertyValue方法,xpo为我们提供了一系列基类,SetPropertyValue是多数类中都有的,它的功能是可以在有值被设置时,需要得到属性变化时可以及时的得到通知。可以看到,字符串类型的姓名,在界面上最终显示成了一个文本框,XAF中内置了很多这样的控件,与类型做出了对应关系,当我们使用对应的类型时,就会自动使用对应的控件,这里的控件被叫做编辑器(PropertyEditor)。接下来,有禁用属性:
    private bool _禁用;    public bool 禁用    {      get { return _禁用; }      set { SetPropertyValue("禁用", ref _禁用, value); }    }
除了自动建立的3个字段外,别的字段都是与代码有对应关系的映射了,xpo默认支持以下几种类型的映射:
C# System data typeAdvantageAsaAseDB2FirebirdMySQLMS AccessMSSQLMSSQL CEOraclePervasive SQLPostgre SQLVistaDB
System.Booleanlogicalbitbitchar(1)char(1)bitbitbitbitnumber(1,0)bitboolBit
System.Byteshorttinyinttinyintsmallintnumeric(3,0)tinyint unsignedbytetinyinttinyintnumber(3,0)smallintsmallintInt
System.SByteshortnumeric(3,0)numeric(3,0)numeric(3,0)numeric(3,0)tinyintshortnumeric(3,0)numeric(3,0)number(3,0)numeric(3,0)smallintSmallInt
System.Charchar(1)char(1)nchar(1)char(1)char CHARACTER SET UNICODE_FSScharchar(1)nchar(1)nchar(1)ncharchar(1)char(1)NChar
System.Decimalmoneymoneymoneydecimal(28,4)decimal(18,4)doublecurrencymoneynumeric(19,4)number(19,5)decimal(20,4)decimal(28,8)Decimal
System.Doubledoubledouble precisiondouble precisiondouble precisiondouble precisiondoubledoubledouble precisionfloatdouble precisiondoubledouble precisionFloat
System.SingledoublefloatfloatfloatfloatrealsinglefloatrealfloatrealrealFloat
System.Int16shortsmallintsmallintsmallintsmallintsmallintshortsmallintsmallintnumber(5,0)smallintsmallintSmallInt
System.UInt16integernumeric(5,0)numeric(5,0)numeric(5,0)numeric(5,0)smallint unsignedintnumeric(5,0)numeric(5,0)number(5,0)numeric(5,0)numeric(5,0)Int
System.Int32integerintnumeric(10,0)intintegerintintintintintintegerintInt
System.UInt32moneynumeric(10,0)numeric(10,0)numeric(10,0)numeric(10,0)int unsigneddecimal(10,0)numeric(10,0)numeric(10,0)numeric(10,0)numeric(10,0)numeric(10,0)BigInt
System.Int64moneybigintnumeric(20,0)bigintbigintbigintdecimal(20,0)bigintbigintnumber(20,0)bigintbigintBigInt
System.UInt64moneynumeric(20,0)numeric(20,0)numeric(20,0)numeric(18,0)bigint unsigneddecimal(20,0)numeric(20,0)numeric(20,0)number(20,0)numeric(20,0)numeric(20,0)BigInt
System.Guidchar(36)UNIQUEIDENTIFIERSTRchar(36)char(36)char(36)char(38)guiduniqueidentifieruniqueidentifierchar(36)char(36)char(36)UniqueIdentifier
System.Enumunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying typeunderlying type
System.Stringcharvarcharnvarcharvarcharchar varyingvarcharvarcharnvarcharnvarcharnvarchar2varcharvarcharNVarChar
System.DateTimetimestampdatetimedatetimetimestamptimestampdatetimedatetimedatetimedatetimedatetimestamptimestampDateTime
System.TimeSpandoubledouble precisiondouble precisiondouble precisiondouble precisiondoubledoubledouble precisionfloatdouble precisiondoubledouble precisionFloat
System.Byte[]blobimageimageblobblobLONGBLOBlongbinaryimage, in SQL ServerXAF应用开发教程(二)业务对象模型之简单类型属性
[Size(SizeAttribute.Unlimited), VisibleInListView(true)]    [ImageEditor(ListViewImageEditorMode = ImageEditorMode.PictureEdit,      DetailViewImageEditorMode = ImageEditorMode.PictureEdit,      ListViewImageEditorCustomHeight = 40)]    public byte[] 照片    {      get { return GetPropertyValue<byte[]>("照片"); }      set { SetPropertyValue<byte[]>("照片", value); }    }
因为本节主要介绍业务对象的创建方法,不扩展讨论Attribute的用法,后续章节详细描述。下节介绍几种常见的关系型数据库节构在ORM中的实现方法。
QQ:4603528 QQ群:50185791

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:XAF应用开发教程(二)业务对象模型之简单类型属性

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录