示例#1
0
        public static bool Validate(OrderImportRowData rowData, out string errorMsg)
        {
            //-- 基础数据验证
            Type type = rowData.GetType();

            PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
            for (int i = 0; i < properties.Length; i++)
            {
                PropertyInfo property = properties[i];
                if (property.PropertyType.IsAssignableFrom(typeof(OrderImportCellData)))
                {
                    OrderImportCellData cellData = (OrderImportCellData)property.GetValue(rowData, null);
                    ParseValidationAttribute(property, cellData);
                    if (cellData.Validators != null && cellData.Validators.Count > 0)
                    {
                        foreach (var validator in cellData.Validators)
                        {
                            if (!validator.Validate(rowData, cellData, out errorMsg))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            errorMsg = null;
            return(true);
        }
 public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg)
 {
     if (!string.IsNullOrWhiteSpace(cellData.Value) && cellData.Value.Length > MaxLength)
     {
         errorMsg = string.Format("{0}的值超过最大长度限制{1}!", cellData.Comment, MaxLength);
         return(false);
     }
     errorMsg = null;
     return(true);
 }
 public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg)
 {
     if (string.IsNullOrWhiteSpace(cellData.Value))
     {
         errorMsg = string.Format("{0}的值不能为空!", cellData.Comment);
         return(false);
     }
     errorMsg = null;
     return(true);
 }
 public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg)
 {
     if (!RegexExpression.IsMatch(cellData.Value))
     {
         errorMsg = string.Format("{0}的格式不正确!", cellData.Comment);
         return(false);
     }
     errorMsg = null;
     return(true);
 }
        public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg)
        {
            decimal value;

            if (!decimal.TryParse(cellData.Value, out value))
            {
                errorMsg = string.Format("{0}的值必须是整数或小数!", cellData.Comment);
                return(false);
            }
            errorMsg = null;
            return(true);
        }
示例#6
0
 private static void ParseValidationAttribute(PropertyInfo property, OrderImportCellData cellData)
 {
     object[] customerAttributes = property.GetCustomAttributes(false);
     if (customerAttributes != null && customerAttributes.Length > 0)
     {
         for (int i = 0; i < customerAttributes.Length; i++)
         {
             if (typeof(IDataValidate).IsAssignableFrom(customerAttributes[i].GetType()))
             {
                 cellData.Validators.Add((IDataValidate)customerAttributes[i]);
             }
         }
     }
 }
示例#7
0
        public bool Validate(OrderImportRowData rowData, OrderImportCellData cellData, out string errorMsg)
        {
            decimal value;

            decimal.TryParse(cellData.Value, out value);

            decimal minValue  = Convert.ToDecimal(this.MinValue);
            bool    isInValid = !this.Inclusive ? value < minValue : value <= minValue;

            if (isInValid)
            {
                errorMsg = string.Format("{0}的值必须大于{1}{2}!", cellData.Comment, (this.Inclusive ? "等于" : ""), this.MinValue);
                return(false);
            }

            errorMsg = null;
            return(true);
        }