Пример #1
0
        //验证字符窜处理相关...
        private bool validatedString(MB.WinBase.Common.ColumnPropertyInfo colPropertyInfo, object inputValue, ref string errMsg)
        {
            bool b = true;

            if (colPropertyInfo.MaxLength > 0)
            {
                b = MB.Util.DataValidated.Instance.ValidatedLength(colPropertyInfo.MaxLength, inputValue.ToString());
                if (b == false)
                {
                    //如果检验不通过输出错误的信息
                    int leng = colPropertyInfo.MaxLength / 2;
                    errMsg = CLL.Message(MSG_CHECKED_LENGTH, new string[] { colPropertyInfo.Description,
                                                                            colPropertyInfo.MaxLength.ToString(), leng.ToString() });
                    return(false);
                }
            }
            if (colPropertyInfo.FitLength > 0)
            {
                b = MB.Util.DataValidated.Instance.ValidatedFitLength(colPropertyInfo.FitLength, inputValue.ToString());
                if (!b)
                {
                    errMsg = CLL.Message(MSG_CHECKED_FIT, new string[] { colPropertyInfo.Description, colPropertyInfo.FitLength.ToString() });
                }
            }
            return(b);
        }
Пример #2
0
        //验证数字
        private bool validatedNumber(MB.WinBase.Common.ColumnPropertyInfo colPropertyInfo, object inputValue, ref string errMsg)
        {
            double val = MB.Util.MyConvert.Instance.ToDouble(inputValue);

            //判断最大最小值
            if (val < colPropertyInfo.MinValue || val > colPropertyInfo.MaxValue)
            {
                errMsg = CLL.Message(MSG_MIN_MAX_VALUE, colPropertyInfo.Description, colPropertyInfo.MinValue.ToString(), colPropertyInfo.MaxValue.ToString());
                return(false);
            }
            //判断小数点位数
            if (colPropertyInfo.MaxDecimalPlaces >= 0)
            {
                string sv = val.ToString();
                if (sv.IndexOf('.') >= 0)
                {
                    int position = sv.Length - sv.LastIndexOf('.') - 1;
                    if (position > colPropertyInfo.MaxDecimalPlaces)
                    {
                        errMsg = CLL.Message(MSG_MAX_PLACES, colPropertyInfo.Description, colPropertyInfo.MaxDecimalPlaces.ToString());
                        return(false);
                    }
                }
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// 验证日期格式的字段
        /// </summary>
        /// <param name="colPropertyInfo">对该字段列的客户端配置属性</param>
        /// <param name="inputValue">该列的值</param>
        /// <param name="errMsg">错误信息,ref参数,在方法中定义错误信息并传出</param>
        /// <returns>验证字段值是否正确,true表示验证正确,false表示验证错误</returns>
        private bool validatedDateTime(MB.WinBase.Common.ColumnPropertyInfo colPropertyInfo, object inputValue, ref string errMsg)
        {
            DateTime val = Convert.ToDateTime(inputValue);

            //判断是不是DateTime初始值,如果是初始值,则认为是空
            if (!colPropertyInfo.IsNull && val == DateTime.MinValue)
            {
                string nameDesc = (colPropertyInfo.Description != null && colPropertyInfo.Description.Length > 0) ? colPropertyInfo.Description : colPropertyInfo.Name;
                errMsg = CLL.Message(MSG_NOTNULL, nameDesc);
                return(false);
            }
            return(true);
        }
Пример #4
0
        //根据指定的ColumnPropertyInfo 判断输入的值是否符合要求。
        private bool validated(MB.WinBase.Common.ColumnPropertyInfo colPropertyInfo, MB.WinBase.Common.ColumnEditCfgInfo colEditProInfo, object inputValue, ref string errMsg)
        {
            bool          b;
            StringBuilder msgStr = new StringBuilder();

            //得到要检验的这个列
            //如果是字符窜类型需要检验长度
            //如果值为空不需要检验数据类型
            if (colPropertyInfo.IsNull == true && (inputValue == null || inputValue.ToString().Length == 0))
            {
                return(true);
            }
            if (colPropertyInfo.IsNull != true && (inputValue == null || inputValue.ToString().Length == 0))
            {
                string nameDesc = (colPropertyInfo.Description != null && colPropertyInfo.Description.Length > 0) ? colPropertyInfo.Description : colPropertyInfo.Name;
                msgStr.Append(nameDesc + ":不能为空");
                //如果检验不通过输出错误的信息
                errMsg = CLL.Message(MSG_NOTNULL, new string[] { nameDesc });
                return(false);
            }
            Type sType = MB.Util.General.CreateSystemType(colPropertyInfo.DataType, false);

            if (sType == null)
            {
                throw new MB.Util.APPException(string.Format("XML 文件中列{0} 的类型配置信息有误,请检查XML 文件配置", colPropertyInfo.Description));
            }

            b = MB.Util.DataValidated.Instance.ValidatedDataType(sType, inputValue);

            if (b == true)
            {
                if (string.Compare(sType.Name, "String", true) == 0)
                {
                    b = validatedString(colPropertyInfo, inputValue, ref errMsg);
                }
                else if (Array.IndexOf(NUMBER_DATA_TYPE, sType.Name.ToUpper()) >= 0)
                {
                    b = validatedNumber(colPropertyInfo, inputValue, ref errMsg);
                }
                else if (Array.IndexOf(DATETIME_DATA_TYPE, sType.Name.ToUpper()) >= 0)
                {
                    b = validatedDateTime(colPropertyInfo, inputValue, ref errMsg);
                }
                else
                {
                    //其它类型先不做处理  后期根据实际需要再加上
                }
            }
            else
            {
                errMsg = CLL.Message(MSG_MUST_INPUT, new string[] { colPropertyInfo.Description, MB.Util.DataValidated.Instance.GetTypeValidatedErrMsg(sType) });
                return(false);
            }

            if (colEditProInfo != null && colEditProInfo.IsValidateInputFromDataSource)
            {
                b = validateColValueInLookUpSource(colPropertyInfo, colEditProInfo, inputValue, ref errMsg);
            }

            return(b);
        }