Example #1
0
        public static ValidValue ValidToDT(ValidData tabValue)
        {
            ValidValue result = new ValidValue()
            {
                Value = new DateTime(0001, 1, 1), Error = String.Empty
            };

            object value = tabValue.Value;

            if (value == DBNull.Value)
            {
                //result.Value = new DateTime(1800, 1, 1);
                result.Error = errNull;
            }
            else
            {
                try
                {
                    result.Value = Convert.ToDateTime(value, CultureInfo.CurrentCulture);
                }
                catch (FormatException)
                {
                    result.Error = errConver;
                }
            }
            return(result);
        }
Example #2
0
        public static ValidValue ValidToDouble(ValidData tabValue)
        {
            ValidValue result = new ValidValue()
            {
                Value = 0m, Error = String.Empty
            };

            object value = tabValue.Value;

            if (value == DBNull.Value)
            {
                if (Properties.Settings.Default.ShowNullDoubleError)
                {
                    result.Error = errNull;
                }
                return(result);
            }


            double outValue;

            switch (value.GetType().Name)
            {
            case "String":
                value = ((string)value).Replace('.', ',');
                if (!Double.TryParse((string)value, out outValue))
                {
                    result.Error = errConver;
                    return(result);
                }
                break;

            case "Double":
                outValue = (double)value;
                break;

            default:
                result.Error = errConver;
                return(result);
            }

            if (tabValue.Size > 0)
            {
                outValue = Math.Round(outValue, tabValue.Size);
            }
            if (tabValue.isPos)
            {
                if (outValue < 0)
                {
                    result.Error = errNegative;
                }
                outValue = Math.Max(outValue, 0);
            }
            result.Value = outValue;

            return(result);
        }
Example #3
0
        public static ValidValue ValidToStr(ValidData value)
        {
            ValidValue result = new ValidValue()
            {
                Value = value.Value.ToString(), Error = String.Empty
            };

            string strResult = (string)value.Value.ToString();

            if ((value.Size > 0) && (strResult.Length > value.Size))
            {
                strResult    = strResult.Substring(0, value.Size);
                result.Error = String.Format("str>{0}", value.Size);
            }
            return(result);
        }