博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Rookey.Frame之实体类
阅读量:5252 次
发布时间:2019-06-14

本文共 14399 字,大约阅读时间需要 47 分钟。

     上周跟大家分享了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{    ///     /// 菜单管理    ///     [ModuleConfig(Name = "菜单管理", Sort = 4, PrimaryKeyFields = "Name", TitleKey = "Name", StandardJsFolder = "System")]    public class Sys_Menu : BaseSysEntity    {        ///         /// 菜单名称        ///         [FieldConfig(Display = "菜单名称", RowNum = 1, ColNum = 1, IsFrozen = true, IsUnique = true, IsRequired = true, HeadSort = 1)]        [StringLength(100)]        public string Name { get; set; }        ///         /// 显示名称        ///         [FieldConfig(Display = "显示名称", RowNum = 1, ColNum = 2, IsRequired = true,DefaultValue="{Name}", HeadSort = 2)]        [StringLength(100)]        public string Display { get; set; }        ///         /// 上级菜单Id        ///         [FieldConfig(Display = "上级菜单", ControlType = (int)ControlTypeEnum.ComboTree, Url = "/SystemAsync/LoadFolderMenuTree.html", RowNum = 2, ColNum = 1, HeadSort = 3, ForeignModuleName = "菜单管理")]        public Guid? ParentId { get; set; }        ///         /// 上级菜单名称        ///         [Ignore]        public string ParentName { get; set; }        ///         /// 模块Id        ///         [FieldConfig(Display = "模块", ControlType = (int)ControlTypeEnum.ComboBox, RowNum = 2, ColNum = 2, HeadSort = 4, ForeignModuleName = "模块管理")]        public Guid? Sys_ModuleId { get; set; }        ///         /// 模块名称        ///         [Ignore]        public string Sys_ModuleName { get; set; }        ///         /// 排序        ///         [FieldConfig(Display = "排序", ControlType = (int)ControlTypeEnum.IntegerBox, RowNum = 3, ColNum = 1, HeadSort = 5)]        public int Sort { get; set; }        ///         /// 是否启用        ///         [FieldConfig(Display = "是否启用", ControlType = (int)ControlTypeEnum.SingleCheckBox, RowNum = 3, ColNum = 2, HeadSort = 6)]        public bool IsValid { get; set; }        ///         /// 是否是叶子节点        ///         [FieldConfig(Display = "叶子节点", RowNum = 4, ColNum = 1, ControlType = (int)ControlTypeEnum.SingleCheckBox, HeadSort = 7)]        public bool IsLeaf { get; set; }        ///         /// 菜单图标        ///         [FieldConfig(Display = "菜单图标", ControlType = (int)ControlTypeEnum.IconBox, RowNum = 4, ColNum = 2, IsAllowGridSearch = false, HeadSort = 8)]        [StringLength(100)]        public string Icon { get; set; }        ///         /// 菜单URL        ///         [FieldConfig(Display = "菜单URL", RowNum = 5, ColNum = 1, HeadSort = 9, ControlWidth = 490, HeadWidth = 250)]        [StringLength(500)]        public string Url { get; set; }        ///         /// 新窗口打开        ///         [FieldConfig(Display = "新窗口打开", ControlType = (int)ControlTypeEnum.SingleCheckBox, RowNum = 6, ColNum = 1, HeadSort = 10)]        public bool IsNewWinOpen { get; set; }        ///         /// 菜单路径        ///         //public string TreeValuePath { get; set; }    }

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

///         /// ID  主键ID        ///         [FieldConfig(Display = "ID", IsEnableForm = false, IsAllowGridSearch = false, HeadWidth = 60, HeadSort = 0)]        public Guid Id { get; set; }        ///         /// 创建人ID        ///         [FieldConfig(Display = "创建人", HeadWidth = 80, IsEnableForm = false, IsAllowEdit = false, IsAllowCopy = false, IsAllowBatchEdit = false, HeadSort = 1001, ForeignModuleName = "用户管理")]        public Guid? CreateUserId { get; set; }        ///         /// 修改人ID        ///         [FieldConfig(Display = "修改人", HeadWidth = 80, IsEnableForm = false, HeadSort = 1002, ForeignModuleName = "用户管理")]        public Guid? ModifyUserId { get; set; }        ///         /// 创建人        ///         [NoField]        [StringLength(30)]        public string CreateUserName { get; set; }        ///         /// 修改人        ///         [NoField]        [StringLength(30)]        public string ModifyUserName { get; set; }        ///         /// 创建日期        ///         [FieldConfig(Display = "创建日期", IsEnableForm = false, IsAllowEdit = false, IsAllowCopy = false, IsAllowBatchEdit = false, HeadWidth = 150, HeadSort = 1005)]        public DateTime? CreateDate { get; set; }        ///         /// 修改日期        ///         [FieldConfig(Display = "修改日期", IsEnableForm = false, HeadWidth = 150, HeadSort = 1006)]        public DateTime? ModifyDate { get; set; }        ///         /// 是否删除,软删除、回收站需要用到        ///         [NoField]        [Default(typeof(bool), "0")]        public bool IsDeleted { get; set; }        ///         /// 删除时间        ///         [NoField]        public DateTime? DeleteTime { get; set; }        ///         /// 是否草稿,草稿箱标识        ///         [NoField]        [Default(typeof(bool), "0")]        public bool IsDraft { get; set; }        ///         /// 单据所属组织,数据权限中使用到        ///         [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类的定义

///     /// 模块配置属性类    ///     public class ModuleConfigAttribute : Attribute    {        ///         /// 构造函数        ///         public ModuleConfigAttribute()        {            Sort = 100;            IsAllowAdd = true;            IsAllowEdit = true;            IsAllowDelete = true;        }        ///         /// 数据表名        ///         public string TableName { get; set; }        ///         /// 数据来源类型        ///         public int DataSourceType { get; set; }        ///         /// 父模块名称        ///         public string ParentName { get; set; }        ///         /// 模块名称        ///         public string Name { get; set; }        ///         /// 模块标题列        ///         public string TitleKey { get; set; }        ///         /// 主键字段,记录唯一标识,可以是多个字段        ///         public string PrimaryKeyFields { get; set; }        ///         /// 模块图标        ///         public string Logo { get; set; }        ///         /// 是否允许新增        ///         public bool IsAllowAdd { get; set; }        ///         /// 是否允许编辑        ///         public bool IsAllowEdit { get; set; }        ///         /// 是否允许删除        ///         public bool IsAllowDelete { get; set; }        ///         /// 是否允许复制        ///         public bool IsAllowCopy { get; set; }        ///         /// 是否允许导入        ///         public bool IsAllowImport { get; set; }        ///         /// 是否允许导出        ///         public bool IsAllowExport { get; set; }        ///         /// 是否启用附件        ///         public bool IsEnableAttachment { get; set; }        ///         /// 是否启用回收站        ///         public bool IsEnabledRecycle { get; set; }        ///         /// 是否启用批量编辑        ///         public bool IsEnabledBatchEdit { get; set; }        ///         /// 是否允许打印        ///         public bool IsEnabledPrint { get; set; }        ///         /// 排序编码        ///         public int Sort { get; set; }        ///         /// 标准JS所属文件夹        ///         public string StandardJsFolder { get; set; }        ///         /// 引用的其他JS文件        ///         public string OtherJs { get; set; }    }

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

下面看下字段配置:

///     /// 表单字段配置    ///     public class FieldConfigAttribute : Attribute    {        ///         /// 构造函数        ///         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(数据表字段)        }        ///         /// 字段名称        ///         public string FieldName { get; set; }        ///         /// 字段类型(针对数据库)        ///         public string FieldType { get; set; }        ///         /// 字段长度(针对数据库)        ///         public int FieldLen { get; set; }        ///         /// 字段显示名称        ///         public string Display { get; set; }        ///         /// 外键模块名称,定义外键字段时该字段不能为空        ///         public string ForeignModuleName { get; set; }        ///         /// 输入控件后的注释内容        ///         public string AfterContent { get; set; }        #region 表单配置        ///         /// 是否是启用表单字段配置,为否是将不会插入到表单字段表中        ///         public bool IsEnableForm { get; set; }        ///         /// 控件类型        ///         public int ControlType { get; set; }        ///         /// 是否是表单显示控件        ///         public bool IsFormVisible { get; set; }        ///         /// 控件宽度        ///         public int ControlWidth { get; set; }        ///         /// 默认值        ///         public string DefaultValue { get; set; }        ///         /// 最小字符长度        ///         public int MinCharLen { get; set; }        ///         /// 最大字符长度        ///         public int MaxCharLen { get; set; }        ///         /// 是否必填        ///         public bool IsRequired { get; set; }        ///         /// 是否唯一        ///         public bool IsUnique { get; set; }        ///         /// 是否允许新增        ///         public bool IsAllowAdd { get; set; }        ///         /// 是否允许编辑        ///         public bool IsAllowEdit { get; set; }        ///         /// 是否允许批量编辑        ///         public bool IsAllowBatchEdit { get; set; }        ///         /// 是否允许复制        ///         public bool IsAllowCopy { get; set; }        ///         /// 表单行号,从1开始        ///         public int RowNum { get; set; }        ///         /// 表单列号,从1开始        ///         public int ColNum { get; set; }        ///         /// 分组名称        ///         public string GroupName { get; set; }        ///         /// 分组图标        ///         public string GroupIcon { get; set; }        ///         /// 标签页名称        ///         public string TabName { get; set; }        ///         /// 标签页图标        ///         public string TabIcon { get; set; }        ///         /// 空文本时提示文字        ///         public string NullTipText { get; set; }        ///         /// 值字段名        ///         public string ValueField { get; set; }        ///         /// 文本字段名        ///         public string TextField { get; set; }        ///         /// 数据加载Url        ///         public string Url { get; set; }        ///         /// 是否多选        ///         public bool IsMultiSelect { get; set; }        #endregion        #region 列表配置        ///         /// 是否是启用视图字段配置,为否是将不会插入到视图字段表中        ///         public bool IsEnableGrid { get; set; }        ///         /// 视图字段宽度        ///         public int HeadWidth { get; set; }        ///         /// 是否冻结        ///         public bool IsFrozen { get; set; }        ///         /// 是否分组字段        ///         public bool IsGroupField { get; set; }        ///         /// 是否可见        ///         public bool IsGridVisible { get; set; }        ///         /// 列头排序编号,从0开始        ///         public int HeadSort { get; set; }        ///         /// 是否允许列表中搜索        ///         public bool IsAllowGridSearch { get; set; }        #endregion    }

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

目前支持的表单控件:

///     /// 表单控件类型    ///     public enum ControlTypeEnum    {        ///         /// 文本框        ///         [Description("文本框")]        TextBox = 0,        ///         /// 单选CheckBox        ///         [Description("单选CheckBox")]        SingleCheckBox = 1,        ///         /// 多选CheckBox        ///         [Description("多选CheckBox")]        MutiCheckBox = 2,        ///         /// 下拉列表框        ///         [Description("下拉列表")]        ComboBox = 3,        ///         /// 下拉弹出列表框        ///         [Description("下拉弹出列表")]        ComboGrid = 4,        ///         /// 下拉树        ///         [Description("下拉树")]        ComboTree = 5,        ///         /// 浮点数值输入框        ///         [Description("浮点数值")]        NumberBox = 6,        ///         /// 整型数值输入框        ///         [Description("整型数值")]        IntegerBox = 7,        ///         /// 弹出列表框        ///         [Description("弹出列表框")]        DialogGrid = 8,        ///         /// 单选框组        ///         [Description("单选框组")]        RadioList = 9,        ///         /// 日期输入框        ///         [Description("日期")]        DateBox = 10,        ///         /// 日期时间        ///         [Description("日期时间")]        DateTimeBox = 11,        ///         /// 文本域        ///         [Description("文本域")]        TextAreaBox = 12,        ///         /// 富文本框        ///         [Description("富文本框")]        RichTextBox = 13,        ///         /// 文本框List,暂不支持        ///         [Description("文本框List")]        TextBoxList = 14,        ///         /// 密码输入框,暂不支持        ///         [Description("密码输入框")]        PasswordBox = 15,        ///         /// 图标控件        ///         [Description("图标控件")]        IconBox = 16,        ///         /// 弹出树控件        ///         [Description("弹出树控件")]        DialogTree = 17,        ///         /// 文件上传,暂不支持        ///         [Description("文件上传")]        FileUpload = 25,        ///         /// 图片上传控件        ///         [Description("图片上传")]        ImageUpload = 26,        ///         /// 隐藏控件        ///         [Description("隐藏控件")]        HiddenBox = 30,        ///         /// 显示标签        ///         [Description("显示标签")]        LabelBox = 100,    }

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

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

转载于:https://www.cnblogs.com/rookey/p/5706140.html

你可能感兴趣的文章
android:scaleType属性
查看>>
SuperEPC
查看>>
mysql-5.7 innodb 的并行任务调度详解
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
Js时间处理
查看>>
Java项目xml相关配置
查看>>
三维变换概述
查看>>
第三次作业
查看>>
vue route 跳转
查看>>
【雷电】源代码分析(二)-- 进入游戏攻击
查看>>
Entityframework:“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常。...
查看>>
Linux中防火墙centos
查看>>
mysql新建用户,用户授权,删除用户,修改密码
查看>>
FancyCoverFlow
查看>>
JS博客
查看>>
如何设置映射网络驱动器的具体步骤和方法
查看>>
ASP.NET WebApi 基于OAuth2.0实现Token签名认证
查看>>
283. Move Zeroes把零放在最后面
查看>>
Visual Studio Code 打开.py代码报Linter pylint is not installed解决办法
查看>>