Compare() public static méthode

Compare two values.
public static Compare ( string leftText, string rightText, ValidationCompareOperator op, ValidationRule vr ) : bool
leftText string
rightText string
op ValidationCompareOperator
vr ValidationRule
Résultat bool
Exemple #1
0
        /// <summary>
        /// Perform Range Validation on a specific control.
        /// </summary>
        private ValidationRule RangeValidate(IControlHabanero ctrl)
        {
            List <ValidationRule> vr         = _validationRules[ctrl];
            ValidationRule        returnRule = new ValidationRule();

            if (vr != null)
            {
                vr.ForEach(delegate(ValidationRule obj)
                {
                    if (this.IsDefaultRange(obj))
                    {
                        returnRule = obj;
                    }
                    else
                    {
                        obj.IsValid = ValidationRule.Compare(ctrl.Text, obj.MinimumValue, ValidationCompareOperator.GreaterThanEqual, obj);

                        if (obj.IsValid)
                        {
                            obj.IsValid = ValidationRule.Compare(ctrl.Text, obj.MaximumValue, ValidationCompareOperator.LessThanEqual, obj);
                        }
                        returnRule = obj;
                    }
                });
            }
            return(returnRule);
        }
Exemple #2
0
        /// <summary>
        /// Perform RequiredField Validation on a specific control.
        /// </summary>
        private ValidationRule RequiredFieldValidate(IControlHabanero ctrl)
        {
            ValidationRule        returnRule = new ValidationRule();
            List <ValidationRule> vr         = _validationRules[ctrl];

            vr.ForEach(delegate(ValidationRule obj)
            {
                if (obj != null && obj.IsRequired)
                {
                    obj.IsValid = obj.IsValid && !ValidationRule.Compare(ctrl.Text, obj.InitialValue, ValidationCompareOperator.Equal, obj);
                }
                returnRule = obj;
            });


            return(returnRule);
        }
Exemple #3
0
        /// <summary>
        /// Set validation rule.
        /// </summary>
        public void SetValidationRule(IControlHabanero inputComponent, ValidationRule vr)
        {
            if (inputComponent != null)
            {
                // only throw error in DesignMode

                if (!this.CanExtend(inputComponent))
                {
                    throw new InvalidOperationException(inputComponent.GetType()
                                                        + " is not supported by the validation provider.");
                }

                if (!this.IsDefaultRange(vr) &&
                    ValidationRule.Compare(vr.MinimumValue, vr.MaximumValue, ValidationCompareOperator.GreaterThanEqual, vr))
                {
                    throw new ArgumentException("MinimumValue must not be greater than or equal to MaximumValue.");
                }


                //ValidationRule vrOld = this._ValidationRules[inputComponent] as ValidationRule;

                // if new rule is valid and in not DesignMode, clone rule
                if ((vr != null))
                {
                    vr = vr.Clone() as ValidationRule;
                }
                if (!this._validationRules.ContainsKey(inputComponent))
                {
                    List <ValidationRule> vrList = new List <ValidationRule>();
                    vrList.Add(vr);
                    this._validationRules.Add(inputComponent, vrList);
                }
                else if ((vr != null) && !this._validationRules[inputComponent].Contains(vr))
                {
                    this._validationRules[inputComponent].Add(vr);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Perform CompareValidate on a specific control.
        /// </summary>
        /// <returns>true if control has no validation rule.</returns>
        private ValidationRule CompareValidate(IControlHabanero ctrl)
        {
            ValidationRule        returnRule = new ValidationRule();
            List <ValidationRule> vr         = _validationRules[ctrl];

            vr.ForEach(delegate(ValidationRule obj)
            {
                if (obj != null)
                {
                    if (this._defaultValidationRule.ValueToCompare.Equals(obj.ValueToCompare) &&
                        this._defaultValidationRule.Operator.Equals(obj.Operator))
                    {
                        returnRule = obj;
                    }
                    else
                    {
                        obj.IsValid = ValidationRule.Compare(ctrl.Text, obj.ValueToCompare, obj.Operator, obj);
                    }
                }
            });


            return(returnRule);
        }