protected override bool EvaluateIsValid()
        {
            string control_value;

            control_value = GetControlValidationValue(this.ControlToValidate);
            if (control_value == null)
            {
                return(true);
            }
            control_value = control_value.Trim();
            if (control_value.Length == 0)
            {
                return(true);
            }

            string compare;
            /* ControlToCompare takes precendence, if it's set. */
            string controlToCompare = ControlToCompare;

            compare = (!String.IsNullOrEmpty(controlToCompare) ? GetControlValidationValue(controlToCompare) : ValueToCompare);

            return(BaseCompareValidator.Compare(GetControlValidationValue(ControlToValidate), false,
                                                compare, this.CultureInvariantValues,
                                                Operator, this.Type));
        }
示例#2
0
 protected static bool Compare(string left,
                               string right,
                               ValidationCompareOperator op,
                               ValidationDataType type)
 {
     return(BaseCompareValidator.Compare(left, false, right, false, op, type));
 }
        protected override bool EvaluateIsValid()
        {
            string controlValidationValue = base.GetControlValidationValue(base.ControlToValidate);

            if (controlValidationValue.Trim().Length == 0)
            {
                return(true);
            }
            bool flag = (base.Type == ValidationDataType.Date) && !this.DetermineRenderUplevel();

            if (flag && !base.IsInStandardDateFormat(controlValidationValue))
            {
                controlValidationValue = base.ConvertToShortDateString(controlValidationValue);
            }
            bool   cultureInvariantRightText = false;
            string date = string.Empty;

            if (this.ControlToCompare.Length > 0)
            {
                date = base.GetControlValidationValue(this.ControlToCompare);
                if (flag && !base.IsInStandardDateFormat(date))
                {
                    date = base.ConvertToShortDateString(date);
                }
            }
            else
            {
                date = this.ValueToCompare;
                cultureInvariantRightText = base.CultureInvariantValues;
            }
            return(BaseCompareValidator.Compare(controlValidationValue, false, date, cultureInvariantRightText, this.Operator, base.Type));
        }
        protected override bool EvaluateIsValid()
        {
            string controlValidationValue = base.GetControlValidationValue(base.ControlToValidate);

            if (controlValidationValue.Trim().Length == 0)
            {
                return(true);
            }
            if (((base.Type == ValidationDataType.Date) && !this.DetermineRenderUplevel()) && !base.IsInStandardDateFormat(controlValidationValue))
            {
                controlValidationValue = base.ConvertToShortDateString(controlValidationValue);
            }
            return(BaseCompareValidator.Compare(controlValidationValue, false, this.MinimumValue, base.CultureInvariantValues, ValidationCompareOperator.GreaterThanEqual, base.Type) && BaseCompareValidator.Compare(controlValidationValue, false, this.MaximumValue, base.CultureInvariantValues, ValidationCompareOperator.LessThanEqual, base.Type));
        }
 protected override bool ControlPropertiesValid()
 {
     if (this.ControlToCompare.Length > 0)
     {
         base.CheckControlValidationProperty(this.ControlToCompare, "ControlToCompare");
         if (StringUtil.EqualsIgnoreCase(base.ControlToValidate, this.ControlToCompare))
         {
             throw new HttpException(System.Web.SR.GetString("Validator_bad_compare_control", new object[] { this.ID, this.ControlToCompare }));
         }
     }
     else if ((this.Operator != ValidationCompareOperator.DataTypeCheck) && !BaseCompareValidator.CanConvert(this.ValueToCompare, base.Type, base.CultureInvariantValues))
     {
         throw new HttpException(System.Web.SR.GetString("Validator_value_bad_type", new string[] { this.ValueToCompare, "ValueToCompare", this.ID, PropertyConverter.EnumToString(typeof(ValidationDataType), base.Type) }));
     }
     return(base.ControlPropertiesValid());
 }
        private void ValidateValues()
        {
            string maximumValue = this.MaximumValue;

            if (!BaseCompareValidator.CanConvert(maximumValue, base.Type, base.CultureInvariantValues))
            {
                throw new HttpException(System.Web.SR.GetString("Validator_value_bad_type", new string[] { maximumValue, "MaximumValue", this.ID, PropertyConverter.EnumToString(typeof(ValidationDataType), base.Type) }));
            }
            string minimumValue = this.MinimumValue;

            if (!BaseCompareValidator.CanConvert(minimumValue, base.Type, base.CultureInvariantValues))
            {
                throw new HttpException(System.Web.SR.GetString("Validator_value_bad_type", new string[] { minimumValue, "MinimumValue", this.ID, PropertyConverter.EnumToString(typeof(ValidationDataType), base.Type) }));
            }
            if (BaseCompareValidator.Compare(minimumValue, base.CultureInvariantValues, maximumValue, base.CultureInvariantValues, ValidationCompareOperator.GreaterThan, base.Type))
            {
                throw new HttpException(System.Web.SR.GetString("Validator_range_overalap", new string[] { maximumValue, minimumValue, this.ID }));
            }
        }
示例#7
0
        public static void DoBaseCompareValidatorAddAttributes(WhidbeyBaseCompareValidator validator, IBaseCompareValidatorAccessor validatorAccessor) {
            if (validatorAccessor.RenderUpLevel) {
                ValidationDataType type = validator.Type;
                if (type != ValidationDataType.String) {
                    string id = validator.ClientID;

                    ValidatorHelper.AddExpandoAttribute(validator, id, "type", PropertyConverter.EnumToString(typeof(ValidationDataType), type), false);

                    NumberFormatInfo info = NumberFormatInfo.CurrentInfo;
                    if (type == ValidationDataType.Double) {
                        string decimalChar = info.NumberDecimalSeparator;
                        ValidatorHelper.AddExpandoAttribute(validator, id, "decimalchar", decimalChar);
                    }
                    else if (type == ValidationDataType.Currency) {
                        string decimalChar = info.CurrencyDecimalSeparator;
                        ValidatorHelper.AddExpandoAttribute(validator, id, "decimalchar", decimalChar);

                        string groupChar = info.CurrencyGroupSeparator;
                        if (groupChar[0] == 160)
                            groupChar = " ";
                        ValidatorHelper.AddExpandoAttribute(validator, id, "groupchar", groupChar);

                        int digits = info.CurrencyDecimalDigits;
                        ValidatorHelper.AddExpandoAttribute(validator, id, "digits", digits.ToString(NumberFormatInfo.InvariantInfo), false);

                        int groupSize = GetCurrencyGroupSize(info);
                        if (groupSize > 0) {
                            ValidatorHelper.AddExpandoAttribute(validator, id, "groupsize", groupSize.ToString(NumberFormatInfo.InvariantInfo), false);
                        }
                    }
                    else if (type == ValidationDataType.Date) {
                        ValidatorHelper.AddExpandoAttribute(validator, id, "dateorder", validatorAccessor.GetDateElementOrder(), false);
                        ValidatorHelper.AddExpandoAttribute(validator, id, "cutoffyear", validatorAccessor.CutoffYear.ToString(NumberFormatInfo.InvariantInfo), false);

                        int currentYear = DateTime.Today.Year;
                        int century = currentYear - (currentYear % 100);
                        ValidatorHelper.AddExpandoAttribute(validator, id, "century", century.ToString(NumberFormatInfo.InvariantInfo), false);
                    }
                }
            }
        }
示例#8
0
        protected override bool ControlPropertiesValid()
        {
            if ((this.Operator != ValidationCompareOperator.DataTypeCheck) && ControlToCompare.Length == 0 &&
                !BaseCompareValidator.CanConvert(this.ValueToCompare, this.Type, this.CultureInvariantValues))
            {
                throw new HttpException(
                          String.Format("Unable to convert the value: {0} as a {1}", ValueToCompare,
                                        Enum.GetName(typeof(ValidationDataType), this.Type)));
            }

            if (ControlToCompare.Length > 0)
            {
                if (string.CompareOrdinal(ControlToCompare, ControlToValidate) == 0)
                {
                    throw new HttpException(String.Format("Control '{0}' cannot have the same value '{1}' for both ControlToValidate and ControlToCompare.", ID, ControlToCompare));
                }
                CheckControlValidationProperty(ControlToCompare, "");
            }

            return(base.ControlPropertiesValid());
        }
示例#9
0
 protected static bool Convert(string text,
                               ValidationDataType type,
                               out object value)
 {
     return(BaseCompareValidator.Convert(text, type, false, out value));
 }