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 BKYDemo.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).
[XafDisplayName("水果基类")]
//什么意思了??
[NonPersistent]
public class FruitsBase : XPBaseObject
{
// Inherit from a different class to provide a custom primary key, concurrency and deletion behavior, etc. (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument113146.aspx).
public FruitsBase(Session session) : base(session)
{
}
[XafDisplayName("自增ID")]
[Key(AutoGenerate = true), Browsable(false)]
public int GID {
get {
return GetPropertyValue<int>(nameof(GID));
}
set
{
SetDelayedPropertyValue(nameof(GID), value);
}
}
[XafDisplayName("水果编号")]
public string Code {
get {
return GetPropertyValue<string>(nameof(Code));
}
set {
SetDelayedPropertyValue(nameof(Code), value);
}
}
[XafDisplayName("水果名称")]
//为空判断
[RuleRequiredField("RuleRequiredFiled.FruitsBase.Name", DefaultContexts.Save, "名称不能为空")]
public string Name {
get {
return GetPropertyValue<string>(nameof(Name));
}
set {
SetPropertyValue(nameof(Name),value);
}
}
[XafDisplayName("水果种类")]
public EnumFruitType Type
{
get
{
return GetPropertyValue<EnumFruitType>(nameof(Type));
}
set
{
SetPropertyValue(nameof(Type), value);
}
}
/// <summary>
/// 水果种类
/// </summary>
public enum EnumFruitType
{
[XafDisplayName("苹果")]
One = 1,
[XafDisplayName("香蕉")]
Two = 2,
[XafDisplayName("葡萄")]
Three = 3,
[XafDisplayName("火龙果")]
Four = 4,
[XafDisplayName("龙眼")]
Five = 5,
}
[XafDisplayName("水果介绍"),Size(2000)]
//文件大小给了2000kb
public string Desc
{
get
{
return GetPropertyValue<string>(nameof(Desc));
}
set
{
SetPropertyValue(nameof(Desc), value);
}
}
[XafDisplayName("水果图片")]
[ImageEditor(ImageEditorMode.PopupPictureEdit,ImageEditorMode.PictureEdit)]
//图片可编辑?
public byte[] ImageData
{
get
{
return GetPropertyValue<byte[]>(nameof(ImageData));
}
set
{
SetPropertyValue(nameof(ImageData), value);
}
}
[XafDisplayName("水果产地")]
public string Place
{
get
{
return GetPropertyValue<string>(nameof(Place));
}
set
{
SetPropertyValue(nameof(Place), value);
}
}
[XafDisplayName("创建人")]
public string Creater
{
get
{
return GetPropertyValue<string>(nameof(Creater));
}
set
{
SetPropertyValue(nameof(Creater), value);
}
}
[XafDisplayName("创建时间")]
public DateTime CreateTime
{
get
{
return GetPropertyValue<DateTime>(nameof(CreateTime));
}
set
{
SetPropertyValue(nameof(CreateTime), value);
}
}
[XafDisplayName("推荐价格")]
public decimal Price
{
get
{
return GetPropertyValue<decimal>(nameof(Price));
}
set
{
SetPropertyValue(nameof(Price), value);
}
}
public override void AfterConstruction()
{
base.AfterConstruction();
// Place your initialization code here (https://documentation.devexpress.com/eXpressAppFramework/CustomDocument112834.aspx).
}
//private 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";
//}
}
}
原文地址:XAF框架学习:如何创建业务实体类和菜单页面视图布局 - 小小邪 - 博客园 (cnblogs.com)