コード例 #1
0
        /// <summary>
        /// 检查类型是否匹配,长度是否超长,必填项是否已填,取值范围是否正确等等.....
        /// </summary>
        /// <returns>检查成功返回true,不成功返回false</returns>
        public string ItemCheck()
        {
            string nameCN = this.ItemNameCN.IsEmpty() ? "控件ID:" + this.ID : this.ItemNameCN;
            string data   = this.Text.TrimString();

            // 必填项检查
            if (this.ItemIsRequired && data.IsEmpty())
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataRequired(nameCN);
                return(this._ErrorMessage);
            }

            if (data.IsEmpty())
            {
                return("");
            }

            // 数据类型检查
            if (!DataUtility.CheckDataType(data, ((IDataItem)this).ItemType))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataType(nameCN, ((IDataItem)this).ItemType);
                return(this._ErrorMessage);
            }

            // 数据格式检查
            data = DataUtility.FormatData(data, ((IDataItem)this).ItemType, ((IDataItem)this).ItemFormat);
            if (data.IsEmpty())
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataFormat(nameCN, ((IDataItem)this).ItemType, ((IDataItem)this).ItemFormat);
                return(this._ErrorMessage);
            }

            this.Text = data;

            // 最小值数据类型检查
            if (!DataUtility.CheckDataType(this.MinData, ((IDataItem)this).ItemType))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataType(nameCN + "(最小值)", ((IDataItem)this).ItemType);
                return(this._ErrorMessage);
            }
            // 最大值数据类型检查
            if (!DataUtility.CheckDataType(this.MaxData, ((IDataItem)this).ItemType))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataType(nameCN + "(最大值)", ((IDataItem)this).ItemType);
                return(this._ErrorMessage);
            }
            // 数据取值范围检查
            if (!DataUtility.CheckDataRange(data, ((IDataItem)this).ItemType, this.MinData, this.MaxData))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataRange(nameCN, ((IDataItem)this).ItemType, this.MinData, this.MaxData);
                return(this._ErrorMessage);
            }


            //等等.....


            return(string.Empty);
        }
コード例 #2
0
        /// <summary>
        /// 检查类型是否匹配,长度是否超长,必填项是否已填,取值范围是否正确等等.....
        /// </summary>
        /// <returns>检查成功返回true,不成功返回false</returns>
        public string ItemCheck()
        {
            string nameCN = this.ItemNameCN.IsEmpty() ? "控件ID:" + this.ID : this.ItemNameCN;
            string data   = this.Text.TrimString();

            // 必填项检查
            if (this.ItemIsRequired && data.IsEmpty())
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataRequired(nameCN);
                return(this._ErrorMessage);
            }

            if (data.IsEmpty())
            {
                return("");
            }

            // 数据长度检查
            if (this.MinLength > 0 || this.MaxLength > 0)
            {
                int dl = Encoding.Default.GetByteCount(data);
                if (this.MinLength > dl || this.MaxLength < dl)
                {
                    this.Focus();
                    this._ErrorMessage = DataUtility.GetErrorMessage_DataLengthRange(nameCN, this.ItemType, this.MinLength, this.MaxLength);
                    return(this._ErrorMessage);
                }
            }

            // 数据类型检查
            if (!DataUtility.CheckDataType(data, this.ItemType))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataType(nameCN, this.ItemType);
                return(this._ErrorMessage);
            }

            // 数据格式检查
            data = DataUtility.FormatData(data, this.ItemType, this.ItemFormat);
            if (data.IsEmpty())
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataFormat(nameCN, this.ItemType, this.ItemFormat);
                return(this._ErrorMessage);
            }

            this.Text = data;


            // 最小值数据类型检查
            if (!DataUtility.CheckDataType(this.MinData, this.ItemType))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataType(nameCN + "(最小值)", this.ItemType);
                return(this._ErrorMessage);
            }
            // 最大值数据类型检查
            if (!DataUtility.CheckDataType(this.MaxData, this.ItemType))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataType(nameCN + "(最大值)", this.ItemType);
                return(this._ErrorMessage);
            }
            // 数据取值范围检查
            if (!DataUtility.CheckDataRange(data, this.ItemType, this.MinData, this.MaxData))
            {
                this.Focus();
                this._ErrorMessage = DataUtility.GetErrorMessage_DataRange(nameCN, this.ItemType, this.MinData, this.MaxData);
                return(this._ErrorMessage);
            }


            //等等.....


            return(string.Empty);
        }