Rookey.Frame之实体类

     上周跟大家分享了Rookey.Frame框架的初始化功能,今天继续给大家介绍实体类的设计。

     先看下下面菜单实体示例代码:

 

using Rookey.Frame.EntityBase;
using Rookey.Frame.EntityBase.Attr;
using Rookey.Frame.Model.EnumSpace;
using ServiceStack.DataAnnotations;
using System;

namespace Rookey.Frame.Model.Sys
{
    /// <summary>
    /// 菜单管理
    /// </summary>
    [ModuleConfig(Name = "菜单管理", Sort = 4, PrimaryKeyFields = "Name", TitleKey = "Name", StandardJsFolder = "System")]
    public class Sys_Menu : BaseSysEntity
    {
        /// <summary>
        /// 菜单名称
        /// </summary>
        [FieldConfig(Display = "菜单名称", RowNum = 1, ColNum = 1, IsFrozen = true, IsUnique = true, IsRequired = true, HeadSort = 1)]
        [StringLength(100)]
        public string Name { get; set; }

        /// <summary>
        /// 显示名称
        /// </summary>
        [FieldConfig(Display = "显示名称", RowNum = 1, ColNum = 2, IsRequired = true,DefaultValue="{Name}", HeadSort = 2)]
        [StringLength(100)]
        public string Display { get; set; }

        /// <summary>
        /// 上级菜单Id
        /// </summary>
        [FieldConfig(Display = "上级菜单", ControlType = (int)ControlTypeEnum.ComboTree, Url = "/SystemAsync/LoadFolderMenuTree.html", RowNum = 2, ColNum = 1, HeadSort = 3, ForeignModuleName = "菜单管理")]
        public Guid? ParentId { get; set; }

        /// <summary>
        /// 上级菜单名称
        /// </summary>
        [Ignore]
        public string ParentName { get; set; }

        /// <summary>
        /// 模块Id
        /// </summary>
        [FieldConfig(Display = "模块", ControlType = (int)ControlTypeEnum.ComboBox, RowNum = 2, ColNum = 2, HeadSort = 4, ForeignModuleName = "模块管理")]
        public Guid? Sys_ModuleId { get; set; }

        /// <summary>
        /// 模块名称
        /// </summary>
        [Ignore]
        public string Sys_ModuleName { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        [FieldConfig(Display = "排序", ControlType = (int)ControlTypeEnum.IntegerBox, RowNum = 3, ColNum = 1, HeadSort = 5)]
        public int Sort { get; set; }

        /// <summary>
        /// 是否启用
        /// </summary>
        [FieldConfig(Display = "是否启用", ControlType = (int)ControlTypeEnum.SingleCheckBox, RowNum = 3, ColNum = 2, HeadSort = 6)]
        public bool IsValid { get; set; }

        /// <summary>
        /// 是否是叶子节点
        /// </summary>
        [FieldConfig(Display = "叶子节点", RowNum = 4, ColNum = 1, ControlType = (int)ControlTypeEnum.SingleCheckBox, HeadSort = 7)]
        public bool IsLeaf { get; set; }

        /// <summary>
        /// 菜单图标
        /// </summary>
        [FieldConfig(Display = "菜单图标", ControlType = (int)ControlTypeEnum.IconBox, RowNum = 4, ColNum = 2, IsAllowGridSearch = false, HeadSort = 8)]
        [StringLength(100)]
        public string Icon { get; set; }

        /// <summary>
        /// 菜单URL
        /// </summary>
        [FieldConfig(Display = "菜单URL", RowNum = 5, ColNum = 1, HeadSort = 9, ControlWidth = 490, HeadWidth = 250)]
        [StringLength(500)]
        public string Url { get; set; }

        /// <summary>
        /// 新窗口打开
        /// </summary>
        [FieldConfig(Display = "新窗口打开", ControlType = (int)ControlTypeEnum.SingleCheckBox, RowNum = 6, ColNum = 1, HeadSort = 10)]
        public bool IsNewWinOpen { get; set; }

        /// <summary>
        /// 菜单路径
        /// </summary>
        //public string TreeValuePath { get; set; }
    }

     示例中BaseSysEntity为系统基类,所有实体基类必须继承自Rookey.Frame.EntityBase中的BaseEntity,在BaseEntity顶层基类中定义了公共字段:

        /// <summary>
        /// ID  主键ID
        /// </summary>
        [FieldConfig(Display = "ID", IsEnableForm = false, IsAllowGridSearch = false, HeadWidth = 60, HeadSort = 0)]
        public Guid Id { get; set; }

        /// <summary>
        /// 创建人ID
        /// </summary>
        [FieldConfig(Display = "创建人", HeadWidth = 80, IsEnableForm = false, IsAllowEdit = false, IsAllowCopy = false, IsAllowBatchEdit = false, HeadSort = 1001, ForeignModuleName = "用户管理")]
        public Guid? CreateUserId { get; set; }

        /// <summary>
        /// 修改人ID
        /// </summary>
        [FieldConfig(Display = "修改人", HeadWidth = 80, IsEnableForm = false, HeadSort = 1002, ForeignModuleName = "用户管理")]
        public Guid? ModifyUserId { get; set; }

        /// <summary>
        /// 创建人
        /// </summary>
        [NoField]
        [StringLength(30)]
        public string CreateUserName { get; set; }

        /// <summary>
        /// 修改人
        /// </summary>
        [NoField]
        [StringLength(30)]
        public string ModifyUserName { get; set; }

        /// <summary>
        /// 创建日期
        /// </summary>
        [FieldConfig(Display = "创建日期", IsEnableForm = false, IsAllowEdit = false, IsAllowCopy = false, IsAllowBatchEdit = false, HeadWidth = 150, HeadSort = 1005)]
        public DateTime? CreateDate { get; set; }

        /// <summary>
        /// 修改日期
        /// </summary>
        [FieldConfig(Display = "修改日期", IsEnableForm = false, HeadWidth = 150, HeadSort = 1006)]
        public DateTime? ModifyDate { get; set; }

        /// <summary>
        /// 是否删除,软删除、回收站需要用到
        /// </summary>
        [NoField]
        [Default(typeof(bool), "0")]
        public bool IsDeleted { get; set; }

        /// <summary>
        /// 删除时间
        /// </summary>
        [NoField]
        public DateTime? DeleteTime { get; set; }

        /// <summary>
        /// 是否草稿,草稿箱标识
        /// </summary>
        [NoField]
        [Default(typeof(bool), "0")]
        public bool IsDraft { get; set; }

        /// <summary>
        /// 单据所属组织,数据权限中使用到
        /// </summary>
        [NoField]
        public Guid? OrgId { get; set; }

在菜单实体类中,类属性标记[ModuleConfig(Name = "菜单管理", Sort = 4, PrimaryKeyFields = "Name", TitleKey = "Name", StandardJsFolder = "System")],是对菜单模块定义,模块名称为“菜单管理”,排序为4,决定表的唯一记录的字段(多个字段以英文逗号分隔)为“Name”,TitleKey字段为“Name”,StandardJsFolder前端JS(/Scripts/model)下的所属文件夹,还有其他参数定义可以看下ModuleConfigAttribute类的定义

    /// <summary>
    /// 模块配置属性类
    /// </summary>
    public class ModuleConfigAttribute : Attribute
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public ModuleConfigAttribute()
        {
            Sort = 100;
            IsAllowAdd = true;
            IsAllowEdit = true;
            IsAllowDelete = true;
        }

        /// <summary>
        /// 数据表名
        /// </summary>
        public string TableName { get; set; }

        /// <summary>
        /// 数据来源类型
        /// </summary>
        public int DataSourceType { get; set; }

        /// <summary>
        /// 父模块名称
        /// </summary>
        public string ParentName { get; set; }

        /// <summary>
        /// 模块名称
        /// </summary>
        public string Name { get; set; }

        /// <summary>
        /// 模块标题列
        /// </summary>
        public string TitleKey { get; set; }

        /// <summary>
        /// 主键字段,记录唯一标识,可以是多个字段
        /// </summary>
        public string PrimaryKeyFields { get; set; }

        /// <summary>
        /// 模块图标
        /// </summary>
        public string Logo { get; set; }

        /// <summary>
        /// 是否允许新增
        /// </summary>
        public bool IsAllowAdd { get; set; }

        /// <summary>
        /// 是否允许编辑
        /// </summary>
        public bool IsAllowEdit { get; set; }

        /// <summary>
        /// 是否允许删除
        /// </summary>
        public bool IsAllowDelete { get; set; }

        /// <summary>
        /// 是否允许复制
        /// </summary>
        public bool IsAllowCopy { get; set; }

        /// <summary>
        /// 是否允许导入
        /// </summary>
        public bool IsAllowImport { get; set; }

        /// <summary>
        /// 是否允许导出
        /// </summary>
        public bool IsAllowExport { get; set; }

        /// <summary>
        /// 是否启用附件
        /// </summary>
        public bool IsEnableAttachment { get; set; }

        /// <summary>
        /// 是否启用回收站
        /// </summary>
        public bool IsEnabledRecycle { get; set; }

        /// <summary>
        /// 是否启用批量编辑
        /// </summary>
        public bool IsEnabledBatchEdit { get; set; }

        /// <summary>
        /// 是否允许打印
        /// </summary>
        public bool IsEnabledPrint { get; set; }

        /// <summary>
        /// 排序编码
        /// </summary>
        public int Sort { get; set; }

        /// <summary>
        /// 标准JS所属文件夹
        /// </summary>
        public string StandardJsFolder { get; set; }

        /// <summary>
        /// 引用的其他JS文件
        /// </summary>
        public string OtherJs { get; set; }
    }

对实体类添加该属性标记后,系统初始化时会自动将相关参数初始化到系统中,对于需要自动化表单、列表、权限、流程、字段等相关处理的模块最好加上该配置,对于像权限、日志、监控等相关数据表不需要处理表单、列表等时则可以不需要添加该标记而以[NoModule]来替换,对于后面讲到的字段标记[FieldConfig]也是一样,如果不需要将字段纳入管理时以[NoField]替换,对于既没有添加[ModuleConfig]标记也没有添加[NoModule]标记的实体类,系统会以默认参数的方式初始化,字段也一样,详细请看初始化代码部分。

下面看下字段配置:

    /// <summary>
    /// 表单字段配置
    /// </summary>
    public class FieldConfigAttribute : Attribute
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public FieldConfigAttribute()
        {
            IsAllowAdd = true;
            IsAllowEdit = true;
            IsAllowBatchEdit = false;
            IsAllowCopy = false;
            IsAllowGridSearch = true;
            ControlType = 0; //默认为Textbox控件
            ControlWidth = 180; //默认控件宽度为180
            IsFormVisible = true;
            MinCharLen = 0;
            MaxCharLen = 0;
            IsRequired = false;
            IsUnique = false;
            RowNum = 0;
            ColNum = 0;

            HeadWidth = 120; //网格列宽默认120
            IsFrozen = false; //是否为冻结字段
            IsGroupField = false; //是否为分组字段
            IsGridVisible = true; //字段在网格中是否可见
            HeadSort = 0;

            IsEnableForm = true; //默认启用表单,启用表单后才会初始化表单字段
            IsEnableGrid = true; //默认启用网格,启用网格后才会初始化网格字段

            FieldLen = 300; //默认字段长度为300(数据表字段)
        }

        /// <summary>
        /// 字段名称
        /// </summary>
        public string FieldName { get; set; }

        /// <summary>
        /// 字段类型(针对数据库)
        /// </summary>
        public string FieldType { get; set; }

        /// <summary>
        /// 字段长度(针对数据库)
        /// </summary>
        public int FieldLen { get; set; }


        /// <summary>
        /// 字段显示名称
        /// </summary>
        public string Display { get; set; }

        /// <summary>
        /// 外键模块名称,定义外键字段时该字段不能为空
        /// </summary>
        public string ForeignModuleName { get; set; }

        /// <summary>
        /// 输入控件后的注释内容
        /// </summary>
        public string AfterContent { get; set; }

        #region 表单配置

        /// <summary>
        /// 是否是启用表单字段配置,为否是将不会插入到表单字段表中
        /// </summary>
        public bool IsEnableForm { get; set; }

        /// <summary>
        /// 控件类型
        /// </summary>
        public int ControlType { get; set; }

        /// <summary>
        /// 是否是表单显示控件
        /// </summary>
        public bool IsFormVisible { get; set; }

        /// <summary>
        /// 控件宽度
        /// </summary>
        public int ControlWidth { get; set; }

        /// <summary>
        /// 默认值
        /// </summary>
        public string DefaultValue { get; set; }

        /// <summary>
        /// 最小字符长度
        /// </summary>
        public int MinCharLen { get; set; }

        /// <summary>
        /// 最大字符长度
        /// </summary>
        public int MaxCharLen { get; set; }

        /// <summary>
        /// 是否必填
        /// </summary>
        public bool IsRequired { get; set; }

        /// <summary>
        /// 是否唯一
        /// </summary>
        public bool IsUnique { get; set; }

        /// <summary>
        /// 是否允许新增
        /// </summary>
        public bool IsAllowAdd { get; set; }

        /// <summary>
        /// 是否允许编辑
        /// </summary>
        public bool IsAllowEdit { get; set; }

        /// <summary>
        /// 是否允许批量编辑
        /// </summary>
        public bool IsAllowBatchEdit { get; set; }

        /// <summary>
        /// 是否允许复制
        /// </summary>
        public bool IsAllowCopy { get; set; }

        /// <summary>
        /// 表单行号,从1开始
        /// </summary>
        public int RowNum { get; set; }

        /// <summary>
        /// 表单列号,从1开始
        /// </summary>
        public int ColNum { get; set; }

        /// <summary>
        /// 分组名称
        /// </summary>
        public string GroupName { get; set; }

        /// <summary>
        /// 分组图标
        /// </summary>
        public string GroupIcon { get; set; }

        /// <summary>
        /// 标签页名称
        /// </summary>
        public string TabName { get; set; }

        /// <summary>
        /// 标签页图标
        /// </summary>
        public string TabIcon { get; set; }

        /// <summary>
        /// 空文本时提示文字
        /// </summary>
        public string NullTipText { get; set; }

        /// <summary>
        /// 值字段名
        /// </summary>
        public string ValueField { get; set; }

        /// <summary>
        /// 文本字段名
        /// </summary>
        public string TextField { get; set; }

        /// <summary>
        /// 数据加载Url
        /// </summary>
        public string Url { get; set; }

        /// <summary>
        /// 是否多选
        /// </summary>
        public bool IsMultiSelect { get; set; }

        #endregion

        #region 列表配置

        /// <summary>
        /// 是否是启用视图字段配置,为否是将不会插入到视图字段表中
        /// </summary>
        public bool IsEnableGrid { get; set; }

        /// <summary>
        /// 视图字段宽度
        /// </summary>
        public int HeadWidth { get; set; }

        /// <summary>
        /// 是否冻结
        /// </summary>
        public bool IsFrozen { get; set; }

        /// <summary>
        /// 是否分组字段
        /// </summary>
        public bool IsGroupField { get; set; }

        /// <summary>
        /// 是否可见
        /// </summary>
        public bool IsGridVisible { get; set; }

        /// <summary>
        /// 列头排序编号,从0开始
        /// </summary>
        public int HeadSort { get; set; }

        /// <summary>
        /// 是否允许列表中搜索
        /// </summary>
        public bool IsAllowGridSearch { get; set; }

        #endregion
    }

对于实体中只是显示字段,不需要初始化为表字段时将字段添加[Ignore]标记,需要注意的是[NoField]是表字段会初始化,表单、列表字段信息不会初始化,[Ignore]字段是数据表字段、字段信息都不会初始化,[FieldConfig]则是两者都会初始化

目前支持的表单控件:

    /// <summary>
    /// 表单控件类型
    /// </summary>
    public enum ControlTypeEnum
    {
        /// <summary>
        /// 文本框
        /// </summary>
        [Description("文本框")]
        TextBox = 0,

        /// <summary>
        /// 单选CheckBox
        /// </summary>
        [Description("单选CheckBox")]
        SingleCheckBox = 1,

        /// <summary>
        /// 多选CheckBox
        /// </summary>
        [Description("多选CheckBox")]
        MutiCheckBox = 2,

        /// <summary>
        /// 下拉列表框
        /// </summary>
        [Description("下拉列表")]
        ComboBox = 3,

        /// <summary>
        /// 下拉弹出列表框
        /// </summary>
        [Description("下拉弹出列表")]
        ComboGrid = 4,

        /// <summary>
        /// 下拉树
        /// </summary>
        [Description("下拉树")]
        ComboTree = 5,

        /// <summary>
        /// 浮点数值输入框
        /// </summary>
        [Description("浮点数值")]
        NumberBox = 6,

        /// <summary>
        /// 整型数值输入框
        /// </summary>
        [Description("整型数值")]
        IntegerBox = 7,

        /// <summary>
        /// 弹出列表框
        /// </summary>
        [Description("弹出列表框")]
        DialogGrid = 8,

        /// <summary>
        /// 单选框组
        /// </summary>
        [Description("单选框组")]
        RadioList = 9,

        /// <summary>
        /// 日期输入框
        /// </summary>
        [Description("日期")]
        DateBox = 10,

        /// <summary>
        /// 日期时间
        /// </summary>
        [Description("日期时间")]
        DateTimeBox = 11,

        /// <summary>
        /// 文本域
        /// </summary>
        [Description("文本域")]
        TextAreaBox = 12,

        /// <summary>
        /// 富文本框
        /// </summary>
        [Description("富文本框")]
        RichTextBox = 13,

        /// <summary>
        /// 文本框List,暂不支持
        /// </summary>
        [Description("文本框List")]
        TextBoxList = 14,

        /// <summary>
        /// 密码输入框,暂不支持
        /// </summary>
        [Description("密码输入框")]
        PasswordBox = 15,

        /// <summary>
        /// 图标控件
        /// </summary>
        [Description("图标控件")]
        IconBox = 16,

        /// <summary>
        /// 弹出树控件
        /// </summary>
        [Description("弹出树控件")]
        DialogTree = 17,

        /// <summary>
        /// 文件上传,暂不支持
        /// </summary>
        [Description("文件上传")]
        FileUpload = 25,

        /// <summary>
        /// 图片上传控件
        /// </summary>
        [Description("图片上传")]
        ImageUpload = 26,

        /// <summary>
        /// 隐藏控件
        /// </summary>
        [Description("隐藏控件")]
        HiddenBox = 30,

        /// <summary>
        /// 显示标签
        /// </summary>
        [Description("显示标签")]
        LabelBox = 100,
    }

控件类型在表单字段中也可以切换,不过对有些控件切换后前端处理可能会有些问题,一般对于同类型控件,如文本类控件相互切换没有问题

    OK,今天的介绍就到此地,祝大家生活愉快!

posted on 2016-07-26 09:04  rookey  阅读(1273)  评论(1编辑  收藏  举报

导航