Example #1
0
 /// <summary>
 /// 检测正则表达式
 /// </summary>
 /// <param name="modelAttribute"></param>
 /// <param name="value"></param>
 private void CheckRule(ModelAttribute modelAttribute, string value)
 {
     if (!string.IsNullOrEmpty(modelAttribute.Rule))
     {
         if (!IsValidType.RegexMatch(value, modelAttribute.Rule))
         {
             throw new Exception(modelAttribute.Name + ":数据格式不正确.<br/>");
         }
     }
 }
Example #2
0
        /// <summary>
        /// 判断数据类型
        /// </summary>
        /// <param name="modelAttribute"></param>
        /// <param name="value"></param>
        private void CheckType(ModelAttribute modelAttribute, string value)
        {
            switch (modelAttribute.DataType)
            {
            case DbType.AnsiString:
                break;

            case DbType.AnsiStringFixedLength:
                break;

            case DbType.Binary:
                break;

            case DbType.Boolean:
                if (!IsValidType.IsBool(value))
                {
                    throw new Exception(modelAttribute.Name + ":数据类型不对.<br/>");
                }
                break;

            case DbType.Byte:
                break;

            case DbType.Currency:
                break;

            case DbType.Date:
                break;

            case DbType.DateTime:
                if (!IsValidType.IsDateTime(value))
                {
                    throw new Exception(modelAttribute.Name + ":时间格式不对.<br/>");
                }
                break;

            case DbType.DateTime2:
                break;

            case DbType.DateTimeOffset:
                break;

            case DbType.Decimal:
                if (!IsValidType.IsDecimal(value))
                {
                    throw new Exception(modelAttribute.Name + ":数据类型不对.<br/>");
                }
                break;

            case DbType.Double:
                if (!IsValidType.IsDouble(value))
                {
                    throw new Exception(modelAttribute.Name + ":数据类型不对.<br/>");
                }
                break;

            case DbType.Guid:
                break;

            case DbType.Int16:
                if (!IsValidType.IsInt16(value))
                {
                    throw new Exception(modelAttribute.Name + ":数据类型不对.<br/>");
                }
                break;

            case DbType.Int32:
                if (!IsValidType.IsInt32(value))
                {
                    throw new Exception(modelAttribute.Name + ":数据类型不对.<br/>");
                }
                break;

            case DbType.Int64:
                if (!IsValidType.IsInt64(value))
                {
                    throw new Exception(modelAttribute.Name + ":数据类型不对.<br/>");
                }
                break;

            case DbType.Object:
                break;

            case DbType.SByte:
                break;

            case DbType.Single:
                break;

            case DbType.String:
                break;

            case DbType.StringFixedLength:
                break;

            case DbType.Time:
                if (!IsValidType.IsDateTime(value))
                {
                    throw new Exception(modelAttribute.Name + ":数据类型不对.<br/>");
                }
                break;

            case DbType.UInt16:
                break;

            case DbType.UInt32:
                break;

            case DbType.UInt64:
                break;

            case DbType.VarNumeric:
                break;

            case DbType.Xml:
                break;

            default:
                break;
            }
        }