/// <summary> /// Initializes a new instance of the CompareStringValidator class /// </summary> /// <param name="ignoreCase">A boolean value to indicate whether to ignore case or not</param> /// <param name="compareOperator">Enumerator for types of operators</param> /// <param name="valueToCompare">First string to compare</param> /// <param name="compareToValue">Second string to compare</param> public CompareStringValidator(bool ignoreCase, ValidationCompareOperator compareOperator, object valueToCompare, object compareToValue) { _ignoreCase = ignoreCase; _compareOperator = compareOperator; _valueToCompare = Convert.ToString(valueToCompare); _compareToValue = Convert.ToString(compareToValue); }
private static bool Compare(ValidationCompareOperator compareOperator, ValidationDataType dataType, object value, object otherValue) { int num = 0; try { switch (dataType) { case ValidationDataType.String: num = string.Compare(value != null ? value.ToString() : String.Empty, otherValue != null ? otherValue.ToString() : String.Empty, false, CultureInfo.CurrentCulture); break; case ValidationDataType.Integer: num = ((int)value).CompareTo(otherValue); break; case ValidationDataType.Double: num = ((double)value).CompareTo(otherValue); break; case ValidationDataType.Date: num = ((DateTime)value).CompareTo(otherValue); break; case ValidationDataType.Time: num = ((TimeSpan)value).CompareTo(otherValue); break; case ValidationDataType.Currency: num = ((decimal)value).CompareTo(otherValue); break; } } catch { return(false); } switch (compareOperator) { case ValidationCompareOperator.Equal: return(num == 0); case ValidationCompareOperator.NotEqual: return(num != 0); case ValidationCompareOperator.GreaterThan: return(num > 0); case ValidationCompareOperator.GreaterThanEqual: return(num >= 0); case ValidationCompareOperator.LessThan: return(num < 0); case ValidationCompareOperator.LessThanEqual: return(num <= 0); } return(true); }
public ModelClientValidationRequiredConditionalRule(string otherPropertyName, string type, IEnumerable<object> conditionValues, bool any, ValidationCompareOperator compareOperator, string errorMessage) { ErrorMessage = errorMessage; ValidationType = RuleName; ValidationParameters.Add("otherprop", otherPropertyName); ValidationParameters.Add("type", type); ValidationParameters.Add("operator", compareOperator.GetJavascriptOperator()); ValidationParameters.Add("any", any.ToString(CultureInfo.InvariantCulture).ToLowerInvariant()); ValidationParameters.Add("vals", String.Format("[{0}]", MvcHtmlString.Create( String.Join(",", conditionValues.Select(val => { var str = val==null?string.Empty: val.ToString(); if (val is bool) { str = str.ToLower(); } return String.Format("|{0}|", str); }) )) ) ); }
public CompareValueAttribute(string originalProperty, ValidationCompareOperator op, ValidationDataType type) : base(_defaultErrorMessage) { OriginalProperty = originalProperty; Operator = op; Type = type; }
protected static bool Compare(string left, string right, ValidationCompareOperator op, ValidationDataType type) { return(BaseCompareValidator.Compare(left, false, right, false, op, type)); }
/// <summary> /// /// </summary> /// <param name="originalProperty">相比较的属性名称</param> /// <param name="op">关系。ValidationCompareOperator枚举值</param> /// <param name="type">数据类型。ValidationDataType枚举值</param> public MyCompareAttribute(string originalProperty, ValidationCompareOperator op, ValidationDataType type) : base(_defaultErrorMessage) { this.originalProperty = originalProperty; this.op = op; this.type = type; }
/// <summary> /// Constructor /// </summary> /// <param name="originalProperty"></param> /// <param name="valueToCompare"></param> /// <param name="compareOperator"></param> /// <param name="dataType"></param> public CompareAttribute(string originalProperty, object valueToCompare, ValidationCompareOperator compareOperator, ValidationDataType dataType) : base(DefaultErrorMessage) { OtherProperty = originalProperty; ValueToCompare = valueToCompare; Operator = compareOperator; DataType = dataType; }
public new bool Compare(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type) { return BaseCompareValidator.Compare (leftText, rightText, op, type); }
public new bool Compare(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type) { return(BaseCompareValidator.Compare(leftText, rightText, op, type)); }
public CompareValidationRule( ValidationCompareOperator compareOperator, ValidationDataType ruleDataType, string valueToCompare, string errorMassage) : base("Compare", errorMassage) { this.compareOperator = compareOperator; this.ruleDataType = ruleDataType; this.valueToCompare = valueToCompare; }
public ModelClientValidationCompareValuesRule(string otherPropertyName, string type, ValidationCompareOperator compareOperator, string errorMessage) { ErrorMessage = errorMessage; ValidationType = RuleName; Contract.Assume(ValidationParameters != null); ValidationParameters.Add("otherprop", otherPropertyName); ValidationParameters.Add("type", type); ValidationParameters.Add("operator", compareOperator.GetJavascriptOperator()); }
static bool Compare(string left, bool cultureInvariantLeftText, string right, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { object lo, ro; if (!Convert(left, type, cultureInvariantLeftText, out lo)) { return(false); } /* DataTypeCheck is a unary operator that only * depends on the lhs */ if (op == ValidationCompareOperator.DataTypeCheck) { return(true); } /* pretty crackladen, but if we're unable to * convert the rhs to @type, the comparison * succeeds */ if (!Convert(right, type, cultureInvariantRightText, out ro)) { return(true); } int comp = ((IComparable)lo).CompareTo((IComparable)ro); switch (op) { case ValidationCompareOperator.Equal: return(comp == 0); case ValidationCompareOperator.NotEqual: return(comp != 0); case ValidationCompareOperator.LessThan: return(comp < 0); case ValidationCompareOperator.LessThanEqual: return(comp <= 0); case ValidationCompareOperator.GreaterThan: return(comp > 0); case ValidationCompareOperator.GreaterThanEqual: return(comp >= 0); default: return(false); } }
public void SetCompareOperator(Control control, ValidationCompareOperator compareOperator) { if (!this.infos.ContainsKey(control)) { this.AddValidationInfo(control); } ValidationInfo info = this.infos[control]; info.CompareOperator = compareOperator; }
/// <summary> /// Compare two values. /// </summary> /// <param name="leftText"></param> /// <param name="rightText"></param> /// <param name="op"></param> /// <param name="vr"></param> /// <returns></returns> public static bool Compare(string leftText, string rightText, ValidationCompareOperator op, ValidationRule vr) { if (false == vr.IsCaseSensitive && vr.DataType == ValidationDataType.String) { leftText = leftText.ToLower(); rightText = rightText.ToLower(); } return(ValidationUtil.CompareValues(leftText, rightText, op, vr.DataType)); }
private static CompareValidator IntCompareValidator( ControlValidatorInjector controlValidator, int value, string errorMessageFormat, ValidationCompareOperator equation) { string errorMessage = string.Format(errorMessageFormat, value); var validator = controlValidator.AddValidator <CompareValidator>(errorMessage); validator.ValueToCompare = value.ToString(CultureInfo.InvariantCulture); validator.Operator = equation; validator.Type = ValidationDataType.Double; return(validator); }
/// <summary> /// Compare two values using provided operator and data type. /// </summary> /// <param name="leftText"></param> /// <param name="rightText"></param> /// <param name="op"></param> /// <param name="type"></param> /// <returns></returns> public static bool CompareValues(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type) { System.Web.UI.WebControls.ValidationCompareOperator vco = (System.Web.UI.WebControls.ValidationCompareOperator)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationCompareOperator), op.ToString()); System.Web.UI.WebControls.ValidationDataType vdt = (System.Web.UI.WebControls.ValidationDataType)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationDataType), type.ToString()); return ValidationUtil.Compare(leftText, rightText, vco, vdt); }
private static CompareValidator CreateDateComparer( ControlValidatorInjector controlValidator, string errorMessageFormat, DateTime date, ValidationCompareOperator compare) { string errorMessage = string.Format(errorMessageFormat, date); var validator = controlValidator.AddValidator <CompareValidator>(errorMessage); validator.ValueToCompare = date.ToString("yyyy-MM-dd"); validator.Operator = compare; validator.Type = ValidationDataType.Date; return(validator); }
/// <summary> Adds a validator to the control and registers it in the page. </summary> /// <param name="controlValidator"> The control to be validated. </param> /// <param name="controlToCompare"> The control to compare </param> /// <param name="compareOperator"> Compare operator. </param> /// <param name="type"> The type of comparison. </param> /// <returns> The created <see cref="CompareValidator"/> object.</returns> public static CompareValidator CompareToControl( this ControlValidatorInjector controlValidator, WebControl controlToCompare, ValidationCompareOperator compareOperator, ValidationDataType type) { var validator = controlValidator.AddValidator <CompareValidator>(Resources.Validation.ComparedControlValuesDontMatch); validator.ControlToCompare = controlToCompare.ID; validator.Operator = compareOperator; validator.Type = type; return(validator); }
/// <summary> /// Compare two values using provided operator and data type. /// </summary> /// <param name="leftText"></param> /// <param name="rightText"></param> /// <param name="op"></param> /// <param name="type"></param> /// <returns></returns> public static bool CompareValues(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type) { System.Web.UI.WebControls.ValidationCompareOperator vco = (System.Web.UI.WebControls.ValidationCompareOperator)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationCompareOperator), op.ToString()); System.Web.UI.WebControls.ValidationDataType vdt = (System.Web.UI.WebControls.ValidationDataType)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationDataType), type.ToString()); return(ValidationUtil.Compare(leftText, rightText, vco, vdt)); }
private static CompareValidator CreateDateComparer( ControlValidatorInjector controlValidator, string errorMessageFormat, Control control, string source, string name, ValidationCompareOperator compare) { string errorMessage = string.Format(errorMessageFormat, source, name); var validator = controlValidator.AddValidator <CompareValidator>(errorMessage); validator.ControlToCompare = control.ID; validator.Operator = compare; validator.Type = ValidationDataType.Date; return(validator); }
/// <summary> /// Compare two values using provided operator and data type. /// </summary> /// <param name="leftText"></param> /// <param name="rightText"></param> /// <param name="op"></param> /// <param name="type"></param> /// <returns></returns> public static bool CompareValues(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type) { System.Web.UI.WebControls.ValidationCompareOperator vco = (System.Web.UI.WebControls.ValidationCompareOperator)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationCompareOperator), op.ToString()); System.Web.UI.WebControls.ValidationDataType vdt = (System.Web.UI.WebControls.ValidationDataType)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationDataType), type.ToString()); //if(rightText=="" && op==ValidationCompareOperator.Equal) //{ // return String.Equals("", leftText); //} return(MyValidator.CompareValues(leftText, rightText, vco, vdt)); }
/// <summary> /// Compare two values using provided operator and data type. /// </summary> /// <param name="leftText"></param> /// <param name="rightText"></param> /// <param name="op"></param> /// <param name="type"></param> /// <returns></returns> public static bool CompareValues(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type) { System.Web.UI.WebControls.ValidationCompareOperator vco = (System.Web.UI.WebControls.ValidationCompareOperator)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationCompareOperator), op.ToString()); System.Web.UI.WebControls.ValidationDataType vdt = (System.Web.UI.WebControls.ValidationDataType)Enum.Parse( typeof(System.Web.UI.WebControls.ValidationDataType), type.ToString()); //if(rightText=="" && op==ValidationCompareOperator.Equal) //{ // return String.Equals("", leftText); //} return MyValidator.CompareValues(leftText, rightText, vco, vdt); }
public DateTimeCompareValidatorProperties(ValidationCompareOperator Operator, DatePicker CompareTo, Page Page, string FieldHeader, string CompareToHeader) { ClientValidationFunction = "DateTimeCompareValidator"; EnableClientScript = true; ControlValidate = true; ServerValidate = ServerValidate_DateTimeCompareValidator; this.Operator = Operator; this.CompareTo = CompareTo; this.Page = Page; this.FieldHeader = FieldHeader; this.CompareToHeader = CompareToHeader; switch (Operator) { case ValidationCompareOperator.Equal: break; case ValidationCompareOperator.GreaterThan: this.ErrorMessage = string.Format(Resources.EFieldMustBeMoreOfField, FieldHeader, CompareToHeader); break; case ValidationCompareOperator.GreaterThanEqual: this.ErrorMessage = string.Format(Resources.EFieldMustBeMoreOrEqualsOfField, FieldHeader, CompareToHeader); break; case ValidationCompareOperator.LessThan: this.ErrorMessage = string.Format(Resources.EFieldMustBeLessOfField, FieldHeader, CompareToHeader); break; case ValidationCompareOperator.LessThanEqual: this.ErrorMessage = string.Format(Resources.EFieldMustBeLessOrEqualsOfField, FieldHeader, CompareToHeader); break; case ValidationCompareOperator.NotEqual: break; default: break; } }
private ValidationCompareOperator GetValidationOperator(string oper) { ValidationCompareOperator operType = ValidationCompareOperator.DataTypeCheck; switch (oper) { case "DataTypeCheck": operType = ValidationCompareOperator.DataTypeCheck; break; case "Equal": operType = ValidationCompareOperator.Equal; break; case "GreaterThan": operType = ValidationCompareOperator.GreaterThan; break; case "GreaterThanEqual": operType = ValidationCompareOperator.GreaterThanEqual; break; case "LessThan": operType = ValidationCompareOperator.LessThan; break; case "LessThanEqual": operType = ValidationCompareOperator.LessThanEqual; break; case "NotEqual": operType = ValidationCompareOperator.NotEqual; break; default: throw new ArgumentException("无法识别的比较类型:" + oper); } return(operType); }
private static bool Compare <T>(Nullable <T> left, Nullable <T> right, ValidationCompareOperator oper) where T : struct, IComparable <T> { int compareResult; if (!left.HasValue && !right.HasValue) { compareResult = 0;//equal because both null } else if (!left.HasValue && right.HasValue) { compareResult = -1; } else if (left.HasValue && !right.HasValue) { compareResult = 1; } else { compareResult = left.Value.CompareTo(right.Value); } return(IsCompareResultValid(compareResult, oper)); }
private static bool IsCompareResultValid(int compareResult, ValidationCompareOperator oper) { switch (oper) { case ValidationCompareOperator.Equal: return(compareResult == 0); case ValidationCompareOperator.NotEqual: return(compareResult != 0); case ValidationCompareOperator.GreaterThan: return(compareResult > 0); case ValidationCompareOperator.GreaterThanEqual: return(compareResult >= 0); case ValidationCompareOperator.LessThan: return(compareResult < 0); case ValidationCompareOperator.LessThanEqual: return(compareResult <= 0); } return(true); }
protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { return default(bool); }
/// <summary> /// Initializes a new instance of the CompareStringValidator class /// </summary> /// <param name="ignoreCase">A boolean value to indicate whether to ignore case or not</param> /// <param name="compareOperator">Enumerator for types of operators</param> /// <param name="valueToCompare">First string to compare</param> /// <param name="compareToValue">Second string to compare</param> public CompareStringValidator(bool ignoreCase, ValidationCompareOperator compareOperator, string valueToCompare, string compareToValue) : base(compareOperator, valueToCompare, compareToValue) { _ignoreCase = ignoreCase; }
private static bool Compare(string left, string right, ValidationCompareOperator oper) { int compareResult = string.Compare(left, right); return(IsCompareResultValid(compareResult, oper)); }
/// <summary> /// Determines whether [is compare valid] [the specified value]. /// </summary> /// <param name="value">The value.</param> /// <param name="comparisonValue">The comparison value.</param> /// <param name="oper">The oper.</param> /// <returns> /// <c>true</c> if [is compare valid] [the specified value]; otherwise, <c>false</c>. /// </returns> public static bool IsCompareValid(string value, string comparisonValue, ValidationCompareOperator oper) { return(Compare(value, comparisonValue, oper)); }
private static bool Compare <T>(T left, T right, ValidationCompareOperator oper) where T : struct, IComparable <T> { int compareResult = left.CompareTo(right); return(IsCompareResultValid(compareResult, oper)); }
protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { object obj2; int num; if (!Convert(leftText, type, cultureInvariantLeftText, out obj2)) { return false; } if (op != ValidationCompareOperator.DataTypeCheck) { object obj3; if (!Convert(rightText, type, cultureInvariantRightText, out obj3)) { return true; } switch (type) { case ValidationDataType.String: num = string.Compare((string) obj2, (string) obj3, false, CultureInfo.CurrentCulture); goto Label_00AC; case ValidationDataType.Integer: num = ((int) obj2).CompareTo(obj3); goto Label_00AC; case ValidationDataType.Double: num = ((double) obj2).CompareTo(obj3); goto Label_00AC; case ValidationDataType.Date: num = ((DateTime) obj2).CompareTo(obj3); goto Label_00AC; case ValidationDataType.Currency: num = ((decimal) obj2).CompareTo(obj3); goto Label_00AC; } } return true; Label_00AC: switch (op) { case ValidationCompareOperator.Equal: return (num == 0); case ValidationCompareOperator.NotEqual: return (num != 0); case ValidationCompareOperator.GreaterThan: return (num > 0); case ValidationCompareOperator.GreaterThanEqual: return (num >= 0); case ValidationCompareOperator.LessThan: return (num < 0); case ValidationCompareOperator.LessThanEqual: return (num <= 0); } return true; }
/// <summary> /// Determines whether [is compare valid] [the specified value]. /// </summary> /// <param name="value">The value.</param> /// <param name="comparisonValue">The comparison value.</param> /// <param name="oper">The oper.</param> /// <returns> /// <c>true</c> if [is compare valid] [the specified value]; otherwise, <c>false</c>. /// </returns> public static bool IsCompareValid <T>(T value, T comparisonValue, ValidationCompareOperator oper) where T : struct, IComparable <T> { return(Compare(value, comparisonValue, oper)); }
public void SetCompareOperator(Control control, ValidationCompareOperator compareOperator) { if (!this.infos.ContainsKey(control)) { this.AddValidationInfo(control); } ValidationInfo info = this.infos[control]; info.CompareOperator = compareOperator; }
protected static bool Compare(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type) { return Compare(leftText, false, rightText, false, op, type); }
protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { object leftObject; if (!Convert(leftText, type, cultureInvariantLeftText, out leftObject)) { return(false); } if (op == ValidationCompareOperator.DataTypeCheck) { return(true); } object rightObject; if (!Convert(rightText, type, cultureInvariantRightText, out rightObject)) { return(true); } int compareResult; switch (type) { case ValidationDataType.String: compareResult = String.Compare((string)leftObject, (string)rightObject, false, CultureInfo.CurrentCulture); break; case ValidationDataType.Integer: compareResult = ((int)leftObject).CompareTo(rightObject); break; case ValidationDataType.Double: compareResult = ((double)leftObject).CompareTo(rightObject); break; case ValidationDataType.Date: compareResult = ((DateTime)leftObject).CompareTo(rightObject); break; case ValidationDataType.Currency: compareResult = ((Decimal)leftObject).CompareTo(rightObject); break; default: Debug.Fail("Unknown Type"); return(true); } switch (op) { case ValidationCompareOperator.Equal: return(compareResult == 0); case ValidationCompareOperator.NotEqual: return(compareResult != 0); case ValidationCompareOperator.GreaterThan: return(compareResult > 0); case ValidationCompareOperator.GreaterThanEqual: return(compareResult >= 0); case ValidationCompareOperator.LessThan: return(compareResult < 0); case ValidationCompareOperator.LessThanEqual: return(compareResult <= 0); default: Debug.Fail("Unknown Operator"); return(true); } }
protected static bool Compare (string left, bool cultureInvariantLeftText, string right, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { object lo, ro; if (!Convert(left, type, cultureInvariantLeftText, out lo)) return false; /* DataTypeCheck is a unary operator that only * depends on the lhs */ if (op == ValidationCompareOperator.DataTypeCheck) return true; /* pretty crackladen, but if we're unable to * convert the rhs to @type, the comparison * succeeds */ if (!Convert(right, type, cultureInvariantRightText, out ro)) return true; int comp = ((IComparable)lo).CompareTo((IComparable)ro); switch (op) { case ValidationCompareOperator.Equal: return comp == 0; case ValidationCompareOperator.NotEqual: return comp != 0; case ValidationCompareOperator.LessThan: return comp < 0; case ValidationCompareOperator.LessThanEqual: return comp <= 0; case ValidationCompareOperator.GreaterThan: return comp > 0; case ValidationCompareOperator.GreaterThanEqual: return comp >= 0; default: return false; } }
protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { return default(bool); }
/// <summary> /// Initializes a new instance of the CompareDoubleValidator class /// </summary> /// <param name="compareOperator">Operator used for comparison</param> /// <param name="valueToCompare">The first value to compare</param> /// <param name="compareToValue">The second value to compare</param> public CompareDoubleValidator(ValidationCompareOperator compareOperator, object valueToCompare, object compareToValue) { _compareOperator = compareOperator; _valueToCompare = Convert.ToDouble(valueToCompare); _compareToValue = Convert.ToDouble(compareToValue); }
/// <summary> /// Constructor /// </summary> /// <param name="originalProperty"></param> /// <param name="compareOperator"></param> /// <param name="dataType"></param> public CompareAttribute(string originalProperty, ValidationCompareOperator compareOperator, ValidationDataType dataType) : this(originalProperty, null, compareOperator, dataType) { }
/// <summary> /// Initializes a new instance of the CompareValidatorBase class /// </summary> /// <param name="compareOperator">Operator used for comparison</param> /// <param name="valueToCompare">First value to compare</param> /// <param name="compareToValue">Second value to compare to</param> public CompareValidatorBase(ValidationCompareOperator compareOperator, object valueToCompare, object compareToValue) { _compareOperator = compareOperator; _valueToCompare = valueToCompare; _compareToValue = compareToValue; }
static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { object left = null, right = null; if(!Convert(leftText, type, cultureInvariantLeftText, out left)) { return false; } if(op == ValidationCompareOperator.DataTypeCheck) { return true; } if(!Convert(rightText, type, cultureInvariantRightText, out right)) { return true; } int compareResult = 0; switch(type) { case ValidationDataType.String: compareResult = ((String)left).CompareTo(right); break; case ValidationDataType.Integer: compareResult = ((int)left).CompareTo(right); break; case ValidationDataType.Double: compareResult = ((Double)left).CompareTo(right); break; case ValidationDataType.Date: compareResult = ((DateTime)left).CompareTo(right); break; case ValidationDataType.Currency: compareResult = ((Decimal)left).CompareTo(right); break; } switch(op) { case ValidationCompareOperator.Equal: return (compareResult == 0); case ValidationCompareOperator.NotEqual: return (compareResult != 0); case ValidationCompareOperator.GreaterThan: return (compareResult > 0); case ValidationCompareOperator.GreaterThanEqual: return (compareResult >= 0); case ValidationCompareOperator.LessThan: return (compareResult < 0); case ValidationCompareOperator.LessThanEqual: return (compareResult <= 0); } return false; }
/// <summary> /// Initializes a new instance of the CompareDateTimeValidator class /// </summary> /// <param name="compareOperator">Operator used for comparison</param> /// <param name="valueToCompare">The first value to compare</param> /// <param name="compareToValue">The second value to compare</param> public CompareDateTimeValidator(ValidationCompareOperator compareOperator, DateTime valueToCompare, DateTime compareToValue) : base(compareOperator, valueToCompare, compareToValue) { }
protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { object leftObject; if (!Convert(leftText, type, cultureInvariantLeftText, out leftObject)) return false; if (op == ValidationCompareOperator.DataTypeCheck) return true; object rightObject; if (!Convert(rightText, type, cultureInvariantRightText, out rightObject)) return true; int compareResult; switch (type) { case ValidationDataType.String: compareResult = String.Compare((string)leftObject, (string) rightObject, false, CultureInfo.CurrentCulture); break; case ValidationDataType.Integer: compareResult = ((int)leftObject).CompareTo(rightObject); break; case ValidationDataType.Double: compareResult = ((double)leftObject).CompareTo(rightObject); break; case ValidationDataType.Date: compareResult = ((DateTime)leftObject).CompareTo(rightObject); break; case ValidationDataType.Currency: compareResult = ((Decimal)leftObject).CompareTo(rightObject); break; default: Debug.Fail("Unknown Type"); return true; } switch (op) { case ValidationCompareOperator.Equal: return compareResult == 0; case ValidationCompareOperator.NotEqual: return compareResult != 0; case ValidationCompareOperator.GreaterThan: return compareResult > 0 ; case ValidationCompareOperator.GreaterThanEqual: return compareResult >= 0 ; case ValidationCompareOperator.LessThan: return compareResult < 0 ; case ValidationCompareOperator.LessThanEqual: return compareResult <= 0 ; default: Debug.Fail("Unknown Operator"); return true; } }
internal static CCompareValidator CreateCompareValidator(string ControlID, string ValidationGroup, ValidationDataType DataType, string ValueToCompare, ValidationCompareOperator CompareOperator, string ErrorMessageResourceKey) { return(new CCompareValidator { ControlToValidate = ControlID, ID = "vldcmpr" + ControlID, ValidationGroup = ValidationGroup, Type = DataType, Operator = CompareOperator, ValueToCompare = ValueToCompare, ErrorMessageResourceKey = ErrorMessageResourceKey, }); }
/// <summary> /// /// </summary> /// <param name="errorMessage"></param> /// <param name="Original"></param> /// <param name="op"></param> /// <param name="type"></param> public ModelClientValidationMyCompareRule(string errorMessage, string Original, ValidationCompareOperator op, string type) { ValidationType = "compareto"; ErrorMessage = errorMessage; string oprtor = ""; switch (op) { case ValidationCompareOperator.Equal: oprtor = "=="; break; case ValidationCompareOperator.GreaterThan: oprtor = ">"; break; case ValidationCompareOperator.GreaterThanEqual: oprtor = ">="; break; case ValidationCompareOperator.LessThan: oprtor = "<"; break; case ValidationCompareOperator.LessThanEqual: oprtor = "<="; break; case ValidationCompareOperator.NotEqual: oprtor = "!="; break; } ValidationParameters["original"] = Original; ValidationParameters["op"] = oprtor; ValidationParameters["type"] = type; }
/// <summary> /// Initializes a new instance of the CompareIntegerValidator class /// </summary> /// <param name="compareOperator">Operator used for comparison</param> /// <param name="valueToCompare">The first value to compare</param> /// <param name="compareToValue">The second value to compare</param> public CompareIntegerValidator(ValidationCompareOperator compareOperator, object valueToCompare, object compareToValue) { _compareOperator = compareOperator; _valueToCompare = Convert.ToInt32(valueToCompare); _compareToValue = Convert.ToInt32(compareToValue); }
/// <summary> /// Initializes a new instance of the CompareIntegerValidator class /// </summary> /// <param name="compareOperator">Operator used for comparison</param> /// <param name="valueToCompare">The first value to compare</param> /// <param name="compareToValue">The second value to compare</param> public CompareIntegerValidator(ValidationCompareOperator compareOperator, int valueToCompare, int compareToValue) : base(compareOperator, valueToCompare, compareToValue) { }
/// <summary> /// Initializes a new instance of the CompareDoubleValidator class /// </summary> /// <param name="compareOperator">Operator used for comparison</param> /// <param name="valueToCompare">The first value to compare</param> /// <param name="compareToValue">The second value to compare</param> public CompareDoubleValidator(ValidationCompareOperator compareOperator, double valueToCompare, double compareToValue) : base(compareOperator, valueToCompare, compareToValue) { }
/// <summary> /// Compare two values. /// </summary> /// <param name="leftText"></param> /// <param name="rightText"></param> /// <param name="op"></param> /// <param name="vr"></param> /// <returns></returns> public static bool Compare( string leftText, string rightText, ValidationCompareOperator op, ValidationRule vr) { if (false == vr.IsCaseSensitive && vr.DataType == ValidationDataType.String) { leftText = leftText.ToLower(); rightText = rightText.ToLower(); } return ValidationUtil.CompareValues(leftText, rightText, op, vr.DataType); }
protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type) { object obj2; int num; if (!Convert(leftText, type, cultureInvariantLeftText, out obj2)) { return(false); } if (op != ValidationCompareOperator.DataTypeCheck) { object obj3; if (!Convert(rightText, type, cultureInvariantRightText, out obj3)) { return(true); } switch (type) { case ValidationDataType.String: num = string.Compare((string)obj2, (string)obj3, false, CultureInfo.CurrentCulture); goto Label_00AC; case ValidationDataType.Integer: num = ((int)obj2).CompareTo(obj3); goto Label_00AC; case ValidationDataType.Double: num = ((double)obj2).CompareTo(obj3); goto Label_00AC; case ValidationDataType.Date: num = ((DateTime)obj2).CompareTo(obj3); goto Label_00AC; case ValidationDataType.Currency: num = ((decimal)obj2).CompareTo(obj3); goto Label_00AC; } } return(true); Label_00AC: switch (op) { case ValidationCompareOperator.Equal: return(num == 0); case ValidationCompareOperator.NotEqual: return(num != 0); case ValidationCompareOperator.GreaterThan: return(num > 0); case ValidationCompareOperator.GreaterThanEqual: return(num >= 0); case ValidationCompareOperator.LessThan: return(num < 0); case ValidationCompareOperator.LessThanEqual: return(num <= 0); } return(true); }
/// <summary> /// Initializes a new instance of the CompareDecimalValidator class /// </summary> /// <param name="compareOperator">Operator used for comparison</param> /// <param name="valueToCompare">The first value to compare</param> /// <param name="compareToValue">The second value to compare</param> public CompareDecimalValidator(ValidationCompareOperator compareOperator, decimal valueToCompare, decimal compareToValue) : base(compareOperator, valueToCompare, compareToValue) { }