Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="val"></param>
        /// <param name="PropertyName"></param>
        protected void Authentication(object val, string PropertyName)
        {
            for (int i = 0; i < CheckAttributeList.Count; i++)
            {
                CheckAttribute _ColumnAttribute = CheckAttributeList[i];
                if (_ColumnAttribute.Name != PropertyName)
                {
                    continue;
                }

                //if (val == null) { throw new MyExceptionMessageBox(_ColumnAttribute.Name + "(" + _ColumnAttribute.Des + ")" + " 不允许为null"); }

                string output = DoCheck(val.ToString2(), _ColumnAttribute);
                if (!string.IsNullOrEmpty(output))
                {
                    //抛出异常
                    throw new MyExceptionMessageBox(output);
                }
            }
            SetDataEmpty(PropertyName);
        }
Пример #2
0
        private string DoCheck(string value, CheckAttribute _CheckAttribute)
        {
            string output = "";

            if (string.IsNullOrEmpty(value))//为空
            {
                if (_CheckAttribute.NotEmpty)
                {
                    output = _CheckAttribute.Des + " " + msg1;
                }

                return(output);
            }

            switch (_CheckAttribute.Type.Name.ToLower().Replace("?", ""))
            {
            case "string":
                if (value.JDoubleByteToTwoByte().Length < _CheckAttribute.Min)    //最小
                {
                    output = _CheckAttribute.Des + " " + msg2 + _CheckAttribute.Min.ToString();
                }
                else if (value.JDoubleByteToTwoByte().Length > _CheckAttribute.Max)    //最大
                {
                    output = _CheckAttribute.Des + " " + msg3 + _CheckAttribute.Max.ToString();
                }
                else if (!RegEmail.IsMatch(value) && _CheckAttribute.IsEmail)    //邮箱
                {
                    output = _CheckAttribute.Des + " " + msg4;
                }
                else if (!RegPhone.IsMatch(value) && _CheckAttribute.IsPhone)    //电话
                {
                    output = _CheckAttribute.Des + " " + msg5;
                }
                else if (!RegMoney.IsMatch(value) && _CheckAttribute.IsMoney)    //货币
                {
                    output = _CheckAttribute.Des + " " + msg6;
                }
                else if (RegChinese.IsMatch(value) && _CheckAttribute.NotSupportChinese)    //中文
                {
                    output = _CheckAttribute.Des + " " + msg7;
                }
                else if (!RegNumber.IsMatch(value) && _CheckAttribute.IsNumber)    //数字
                {
                    output = _CheckAttribute.Des + " " + msg8;
                }

                break;

            case "int":
            case "int32":
            case "int16":
                if (!RegNumber.IsMatch(value))
                {
                    output = _CheckAttribute.Des + " " + msg8;
                }
                else if (int.Parse(value) < _CheckAttribute.Min)    //最小值
                {
                    output = _CheckAttribute.Des + " " + msg9 + _CheckAttribute.Min.ToString();
                }
                else if (int.Parse(value) > _CheckAttribute.Max)    //最大值
                {
                    output = _CheckAttribute.Des + " " + msg10 + _CheckAttribute.Max.ToString();
                }
                break;

            case "double":
                if (!RegMoney.IsMatch(value) && _CheckAttribute.IsMoney)    //货币
                {
                    output = _CheckAttribute.Des + " " + msg6;
                }
                break;

            default:
                break;
            }

            return(output);
        }