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); }
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); }
public override string InitValue() { ValidValue result = Validator(new ValidData() { Value = XlsRow[xlsName], Size = DataSize, isPos = this.isPos }); ResRow[ResName] = result.Value; if (result.Error != String.Empty) { result.Error = String.Format("{0}:{1};", ResName, result.Error); } return(result.Error); }
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); }
public override string InitValue() { ValidValue result = Validator(new ValidData() { Value = xlsName, Size = DataSize }); if (result.Error == "") { value = result.Value; } else { result.Error = String.Format("{0}:{1};", ResName, result.Error); value = null; } return(result.Error); }
public string InitMultValue(string fieldName) { string FieldValue = fieldName.Substring(XlsName.Length, fieldName.Length - XlsName.Length); ValidValue result = Validator(new ValidData() { Value = FieldValue, Size = DataSize, }); ResRow[NameVal1] = result.Value; if (result.Error != String.Empty) { result.Error = String.Format("{0}:{1};", ResName, result.Error); } string result1 = result.Error; result = Validator1(new ValidData() { Value = XlsRow[fieldName], Size = DataSize, }); ResRow[NameVal2] = result.Value; if (result.Error != String.Empty) { result.Error = String.Format("{0}:{1};", ResName, result.Error); } string result2 = result.Error; return(result1 + result2); }