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

            if (Name.IsNullOrEmpty())
            {
                throw new ArgumentNullException(__.Name, _.Name.DisplayName + "不能为空!");
            }
            if (Password.IsNullOrEmpty())
            {
                throw new ArgumentNullException(__.Password, _.Password.DisplayName + "不能为空!");
            }
            //if (Password.Length != 16 && Password.Length != 32) throw new ArgumentOutOfRangeException(__.Password, _.Password.DisplayName + "非法!");
            //if (Name.Length < 8) throw new ArgumentOutOfRangeException(__.Name, _.Name.DisplayName + "最短8个字符!" + Name);
            //if (Name.Length > 16) throw new ArgumentOutOfRangeException(__.Name, _.Name.DisplayName + "最长16个字符!" + Name);

            // 修正显示名
            if (!NickName.IsNullOrEmpty() && NickName.Length > 16)
            {
                NickName = NickName.Substring(0, 16);
            }

            // 建议先调用基类方法,基类方法会对唯一索引的数据进行验证
            base.Valid(isNew);
        }
Exemple #2
0
        /// <summary>显示友好名称</summary>
        /// <returns></returns>
        public override String ToString()
        {
            if (!NickName.IsNullOrEmpty())
            {
                return(NickName);
            }

            return(Name);
        }
Exemple #3
0
        /// <summary>从响应数据中获取信息</summary>
        /// <param name="dic"></param>
        protected override void OnGetInfo(IDictionary <String, String> dic)
        {
            base.OnGetInfo(dic);

            if (dic.TryGetValue("uname", out var str))
            {
                UserName = str.Trim();
            }
            if (dic.TryGetValue("realname", out str))
            {
                NickName = str.Trim();
            }
            //if (dic.TryGetValue("userdetail", out str)) Detail = str.Trim();

            // 修改性别数据,1男0女,而本地是1男2女
            if (dic.TryGetValue("sex", out str) && str.ToInt() == 0)
            {
                dic["sex"] = "2";
            }

            // small image: http://tb.himg.baidu.com/sys/portraitn/item/{$portrait}
            // large image: http://tb.himg.baidu.com/sys/portrait/item/{$portrait}
            if (dic.TryGetValue("portrait", out str))
            {
                Avatar = "http://tb.himg.baidu.com/sys/portrait/item/" + str.Trim();
            }

            // 百度升级协议后,用户名带有星号,不能要
            if (!UserName.IsNullOrEmpty() && UserName.Contains("*"))
            {
                if (NickName.IsNullOrEmpty())
                {
                    NickName = UserName;
                }
                UserName = null;
            }
        }
Exemple #4
0
 /// <summary>已重载。显示友好名称</summary>
 /// <returns></returns>
 public override String ToString() => !NickName.IsNullOrEmpty() ? NickName : Name;