Exemplo n.º 1
0
 /// <summary>
 /// 验证数据
 /// </summary>
 /// <param name="value"></param>
 /// <param name="ModelInfo"></param>
 /// <param name="errorCode"></param>
 private void CheckValue(string value, ModelInfoAttribute ModelInfo, ref List <string> ErrorCode, ref List <string> ControlName)
 {
     if (value.Length == 0)
     {
         if (ModelInfo.NotEmpty)//不能为空
         {
             ErrorCode.Add(ModelInfo.NotEmptyECode);
             ControlName.Add(ModelInfo.ControlName);
         }
     }
     else
     {
         if (value.Length > ModelInfo.Length && ModelInfo.Length != 0)//长度溢出
         {
             ErrorCode.Add(ModelInfo.RTypeECode);
             ControlName.Add(ModelInfo.ControlName);
         }
         else
         {
             if (ModelInfo.RType != RegularExpressions.RegExpType.Normal)
             {
                 if (!RegularExpressions.IsRegExpType(value, ModelInfo.RType))//格式不正确
                 {
                     ErrorCode.Add(ModelInfo.RTypeECode);
                     ControlName.Add(ModelInfo.ControlName);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 检验表单数据
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="PropertyName">实体属性名称</param>
        /// <param name="value">待验证的属性值</param>
        /// <param name="errorCode">返回的错误List</param>
        /// <param name="t">实体对象</param>
        public void CheckValue <T>(List <string> EName, List <string> EValue, ref List <string> errorCode, ref List <string> ControlName, T t)
        {
            if (EName == null && EValue == null && t == null)
            {
                return;
            }
            if (EName.Count != EValue.Count)
            {
                return;
            }
            ModelInfoAttribute ModelInfo = new ModelInfoAttribute();

            System.Reflection.MemberInfo propInfo = null;
            ModelInfoAttribute           myAttr;
            string PropertyName = string.Empty;

            for (int i = 0; i < EName.Count; i++)
            {
                PropertyName = EName[i];
                if (PropertyName.Trim().Length > 0)
                {
                    propInfo = t.GetType().GetProperty(PropertyName);
                    if (propInfo != null)
                    {
                        myAttr = (ModelInfoAttribute)Attribute.GetCustomAttribute(propInfo, typeof(ModelInfoAttribute));
                        if (myAttr != null)
                        {
                            ModelInfo.Length        = myAttr.Length;
                            ModelInfo.Name          = myAttr.Name;
                            ModelInfo.ControlName   = myAttr.ControlName;
                            ModelInfo.NotEmpty      = myAttr.NotEmpty;
                            ModelInfo.NotEmptyECode = myAttr.NotEmptyECode;
                            ModelInfo.RType         = myAttr.RType;
                            ModelInfo.RTypeECode    = myAttr.RTypeECode;
                            CheckValue(EValue[i], ModelInfo, ref errorCode, ref ControlName);
                        }
                    }
                }
            }
        }