示例#1
0
        protected string GetValue(object objValue, string strDisplayFormat = null)
        {
            string strReturn = string.Empty;

            if (objValue == DBNull.Value)
            {
                return(strReturn);
            }
            if (objValue == null)
            {
                return(strReturn);
            }
            if (strDisplayFormat == null)
            {
                strReturn = objValue.ToString();
            }
            else if (Type.GetType("System.String") == objValue.GetType())
            {
                char[] value = objValue.ToString().ToCharArray();
                for (int i = 0; i < value.Length; i++)
                {
                    strDisplayFormat = strDisplayFormat.Replace("{" + i.ToString() + "}", value[i].ToString());
                }
                strReturn = strDisplayFormat;
            }
            else if (DataValidateManager.ValidateNumberFormat(objValue))
            {
                var number = Decimal.Parse(objValue.ToString());
                strReturn = number.ToString(strDisplayFormat);
            }
            else if (DataValidateManager.ValidateDateFormat(objValue))
            {
                strReturn = DateTime.Parse(objValue.ToString()).ToString(strDisplayFormat);
            }
            else
            {
                try
                {
                    char[] value = objValue.ToString().ToCharArray();
                    for (int i = 0; i < value.Length; i++)
                    {
                        strDisplayFormat = strDisplayFormat.Replace("{" + i.ToString() + "}", value[i].ToString());
                    }
                    strReturn = strDisplayFormat;
                }
                catch (Exception)
                {
                    strReturn = objValue.ToString();
                }
            }
            return(strReturn);
        }
示例#2
0
        protected virtual ValidateData ValidateUpdateDate(object objValidateData, bool boolNullable, bool boolExist)
        {
            ValidateData validateData = new ValidateData();

            try
            {
                // 初始化参数
                validateData.Result     = true;
                validateData.Message    = string.Empty;
                validateData.Parameters = new string[5];
                validateData.IsNull     = false;
                validateData.IsExist    = false;

                // 传入参数赋值
                validateData.Value         = objValidateData;
                validateData.Nullable      = boolNullable;
                validateData.Exist         = boolExist;
                validateData.Parameters[0] = "更新时间";
                validateData.Parameters[1] = "null";
                validateData.Parameters[2] = "null";

                // 空验证
                if (DataValidateManager.ValidateIsNull(validateData.Value) == false)
                {
                    // 数值格式验证
                    if (DataValidateManager.ValidateDateFormat(validateData.Value, null, null) == false)
                    {
                        validateData.Message = MessageManager.GetMessageInfo(MessageManager.HINT_MSGID_0005, validateData.Parameters);
                        validateData.Result  = false;
                    }
                    else
                    {
                        // 数据存在验证
                        if (validateData.Exist == true)
                        {
                            if (AJAX_IsExist("UpdateDate", validateData.Value.ToString()) == true)
                            {
                                validateData.IsExist = true;
                                validateData.Message = @"更新时间已存在,请再换一个。";
                                validateData.Result  = false;
                            }
                            else
                            {
                                validateData.Message = @"更新时间不存在,可以使用。";
                                validateData.Result  = true;
                            }
                        }
                        else
                        {
                            validateData.Result = true;
                        }
                    }
                }
                else
                {
                    validateData.IsNull = true;
                    if (validateData.Nullable == false)
                    {
                        validateData.Message = MessageManager.GetMessageInfo(MessageManager.HINT_MSGID_0002, validateData.Parameters);
                        validateData.Result  = false;
                    }
                }
            }
            catch (Exception)
            {
                validateData.Result = false;
            }
            return(validateData);
        }