public bool Validate(string value, out string errorMessage, int columnIndex) { if (columnIndex < 0 || columnIndex > VariableNames.Count()) { throw new ArgumentOutOfRangeException("column index is out of range"); } bool valid = false; errorMessage = string.Empty; if (VariableHasType <double>(columnIndex)) { if (string.IsNullOrWhiteSpace(value)) { valid = true; } else { double val; valid = double.TryParse(value, out val); if (!valid) { errorMessage = "Invalid Value (Valid Value Format: \"" + FormatPatterns.GetDoubleFormatPattern() + "\")"; } } } else if (VariableHasType <string>(columnIndex)) { valid = value != null; if (!valid) { errorMessage = "Invalid Value (string must not be null)"; } } else if (VariableHasType <DateTime>(columnIndex)) { DateTime date; valid = DateTime.TryParse(value, out date); if (!valid) { errorMessage = "Invalid Value (Valid Value Format: \"" + CultureInfo.CurrentCulture.DateTimeFormat + "\""; } } else { throw new ArgumentException("column " + columnIndex + " contains a non supported type."); } return(valid); }
private static bool ValidateNewValue(string value, out string errorMessage) { double val; bool valid = double.TryParse(value, out val); errorMessage = string.Empty; if (!valid) { var sb = new StringBuilder(); sb.Append("Invalid Value (Valid Value Format: \""); sb.Append(FormatPatterns.GetDoubleFormatPattern()); sb.Append("\")"); errorMessage = sb.ToString(); } return(valid); }
protected virtual bool Validate(string value, out string errorMessage) { long val; bool valid = long.TryParse(value, out val); errorMessage = string.Empty; if (!valid) { StringBuilder sb = new StringBuilder(); sb.Append("Invalid Value (Valid Value Format: \""); sb.Append(FormatPatterns.GetIntFormatPattern()); sb.Append("\")"); errorMessage = sb.ToString(); } return(valid); }
private void qualityTextBox_Validating(object sender, CancelEventArgs e) { double val; if ((!string.IsNullOrEmpty(qualityTextBox.Text)) && (!double.TryParse(qualityTextBox.Text, out val))) { e.Cancel = true; StringBuilder sb = new StringBuilder(); sb.Append("Invalid Value (Valid Value Format: \""); sb.Append(FormatPatterns.GetDoubleFormatPattern()); sb.Append("\")"); errorProvider.SetError(qualityTextBox, sb.ToString()); qualityTextBox.SelectAll(); CancelButton = null; } }