Exemplo n.º 1
0
        /// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
        /// <param name="isNew">是否插入</param>
        public override void Valid(Boolean isNew)
        {
            // 如果没有脏数据,则不需要进行任何处理
            if (!HasDirty)
            {
                return;
            }

            // 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
            if (Name.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Name), "Name不能为空!");
            }
            if (DisplayName.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(DisplayName), "DisplayName不能为空!");
            }
            if (Description.IsNullOrEmpty())
            {
                throw new ArgumentNullException(nameof(Description), "Description不能为空!");
            }

            // 在新插入数据或者修改了指定字段时进行修正

            // 检查唯一索引
            // CheckExist(isNew, __.Name);
        }
Exemplo n.º 2
0
        /// <summary>针对指定实体对象计算DisplayName,替换其中变量</summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public String GetDisplayName(IExtend data)
        {
            if (DisplayName.IsNullOrEmpty())
            {
                return(null);
            }

            return(_reg.Replace(DisplayName, m => data[m.Groups[1].Value + ""] + ""));
        }
Exemplo n.º 3
0
 /// <summary>显示友好名称</summary>
 /// <returns></returns>
 public override string ToString()
 {
     if (!DisplayName.IsNullOrEmpty())
     {
         return(DisplayName);
     }
     else
     {
         return(Name);
     }
 }
Exemplo n.º 4
0
        /// <summary>加载后触发</summary>
        protected override void OnLoaded()
        {
            if (IsNew)
            {
                var asmx = SysAssembly;

                Name        = asmx?.Name ?? "NewLife.Cube";
                Version     = asmx?.Version ?? "0.1";
                DisplayName = (asmx?.Title ?? asmx?.Name) ?? "魔方平台";
                Company     = asmx?.Company ?? "新生命开发团队";
                //Address = "新生命开发团队";

                if (DisplayName.IsNullOrEmpty())
                {
                    DisplayName = "系统设置";
                }
            }

            base.OnLoaded();
        }
Exemplo n.º 5
0
        /// <summary>加载后触发</summary>
        protected override void OnLoaded()
        {
            if (IsNew)
            {
                var asmx = SysAssembly;

                Name        = asmx?.Name ?? "NewLife.Cube";
                Version     = asmx?.Version ?? "0.1";
                DisplayName = (asmx?.Title ?? asmx?.Name) ?? "魔方平台";
                Company     = asmx?.Company ?? "新生命开发团队";
                //Address = "新生命开发团队";

                if (DisplayName.IsNullOrEmpty())
                {
                    DisplayName = "系统设置";
                }
            }

            // 本地实例,取IPv4地址后两段
            if (Instance <= 0)
            {
                try
                {
                    var ip  = NetHelper.MyIP();
                    var buf = ip.GetAddressBytes();
                    Instance = (buf[2] << 8) | buf[3];
                }
                catch
                {
                    // 异常时随机
                    Instance = Rand.Next(1, 1024);
                }
            }

            base.OnLoaded();
        }
        ///// <summary>加载后</summary>
        //protected override void OnLoad()
        //{
        //    base.OnLoad();

        //    RoleIds = Roles.SplitAsInt();
        //}

        /// <summary>已重载。显示系统名称</summary>
        /// <returns></returns>
        public override String ToString() => DisplayName.IsNullOrEmpty() ? Name : DisplayName;