Пример #1
0
		public static bool CanConvert (string text,
					       ValidationDataType type)
		{
			object value;

			return Convert (text, type, out value);
		}
Пример #2
0
        private ValidationDataType GetValidationType(string dataType)
        {
            ValidationDataType valType = ValidationDataType.Date;

            switch (dataType)
            {
            case "Date":
                valType = ValidationDataType.Date;
                break;

            case "String":
                valType = ValidationDataType.String;
                break;

            case "Currency":
                valType = ValidationDataType.Currency;
                break;

            case "Double":
                valType = ValidationDataType.Double;
                break;

            case "Integer":
                valType = ValidationDataType.Integer;
                break;

            default:
                throw new ArgumentException("无法识别的校验类型:" + dataType);
            }
            return(valType);
        }
Пример #3
0
 protected static bool Compare(string left,
                               string right,
                               ValidationCompareOperator op,
                               ValidationDataType type)
 {
     return(BaseCompareValidator.Compare(left, false, right, false, op, type));
 }
Пример #4
0
        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);
        }
Пример #5
0
        public static CompareValidator TypeCheck(string message, string target, ValidationDataType type)
        {
            string typeMessage = "";

            switch (type)
            {
            case ValidationDataType.Double:
                typeMessage = "a number";
                break;

            case ValidationDataType.Integer:
                typeMessage = "a number";
                break;

            case ValidationDataType.String:
                typeMessage = "text";
                break;
            }

            CompareValidator comField = new CompareValidator();

            comField.ErrorMessage      = message + " is not " + typeMessage;
            comField.ControlToValidate = target;
            comField.Operator          = ValidationCompareOperator.DataTypeCheck;
            comField.Type = type;
            comField.EnableClientScript = false;
            comField.Display            = ValidatorDisplay.None;

            return(comField);
        }
Пример #6
0
 public SearchSessionItem(string client, string val, string property, ValidationDataType datatype)
 {
     ClientID     = client;
     Value        = val;
     PropertyName = property;
     DataType     = datatype;
 }
Пример #7
0
        public static bool CanConvert(string text,
                                      ValidationDataType type)
        {
            object value;

            return(Convert(text, type, out value));
        }
Пример #8
0
        protected virtual void AddCompareValidator()
        {
// ignore default
            if (ValidationDataType.Equals(ValidationDataType.String))
            {
                return;
            }

            if (ValidationDataType == ValidationDataType.Date)
            {
                CompareValidatorErrorMessage = " Invalid date";
            }
            _cv = new CompareValidator()
            {
                ControlToValidate = this.ID,
                ID                 = this.ID + "_compareValidator",
                Type               = ValidationDataType,
                Operator           = ValidationCompareOperator.DataTypeCheck,
                Display            = ValidatorDisplay.Dynamic,
                EnableClientScript = false,
                ErrorMessage       = " " + CompareValidatorErrorMessage
            };
            if (this.ValidationGroup != String.Empty)
            {
                _cv.ValidationGroup = this.ValidationGroup;
            }
            Controls.Add(_cv);
        }
Пример #9
0
 private void AddValidators(TableCell Cell, string ControlID, ValidationDataType Type, string MinValue, string MaxValue, string RegEx, bool Required)
 {
     if (MinValue != null && MaxValue != null)
     {
         RangeValidator gvali = new RangeValidator();
         gvali.Type              = ValidationDataType.Double;
         gvali.MinimumValue      = Double.Parse(MinValue).ToString();
         gvali.MaximumValue      = Double.Parse(MaxValue).ToString();
         gvali.ControlToValidate = ControlID;
         gvali.ErrorMessage      = gvali.MinimumValue + ".." + gvali.MaximumValue;
         gvali.Attributes.Add("class", "searchValue");
         Cell.Controls.Add(new LiteralControl("&nbsp;"));
         Cell.Controls.Add(gvali);
     }
     else if (RegEx != null)
     {
         RegularExpressionValidator xvali = new RegularExpressionValidator();
         xvali.ValidationExpression = RegEx;
         xvali.ControlToValidate    = ControlID;
         xvali.ErrorMessage         = "Bitte gültiges Format angeben";
         xvali.Attributes.Add("class", "searchValue");
         Cell.Controls.Add(new LiteralControl("&nbsp;"));
         Cell.Controls.Add(xvali);
     }
 }
Пример #10
0
 public CompareValueAttribute(string originalProperty, ValidationCompareOperator op, ValidationDataType type)
     : base(_defaultErrorMessage)
 {
     OriginalProperty = originalProperty;
     Operator         = op;
     Type             = type;
 }
        protected override object PerformTypeCheck(ValidationDataType dataType, object value)
        {
            bool result = (bool)_jsHelper.ExecuteMethod("compareOperator_IsOfType",
                                                        dataType.ToString(), value);

            return(result ? null : new object());
        }
Пример #12
0
        protected void AddCustomField(Object s, EventArgs e)
        {
            string newName = txtName.Text.Trim();

            if (newName == String.Empty)
            {
                return;
            }

            ValidationDataType dataType = (ValidationDataType)Enum.Parse(typeof(ValidationDataType), dropDataType.SelectedValue);
            bool required = chkRequired.Checked;

            CustomField newCustomField = new CustomField(ProjectId, newName, dataType, required);

            if (newCustomField.Save())
            {
                txtName.Text = "";
                dropDataType.SelectedIndex = 0;
                chkRequired.Checked        = false;
                BindCustomFields();
            }
            else
            {
                lblError.Text = "Could not save custom field";
            }
        }
Пример #13
0
 /// <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;
 }
Пример #14
0
        static bool CanConvert(string text,
                               ValidationDataType type,
                               bool cultureInvariant)
        {
            object value;

            return(Convert(text, type, cultureInvariant, out value));
        }
Пример #15
0
 public ValidateRange(string property, object minValue, object maxValue, ValidationDataType dataType)
     : base(property)
 {
     _minValue = minValue;
     _maxValue = maxValue;
     _dataType = dataType;
     Error     = $"{property} must be between {_minValue} and {_maxValue}";
 }
Пример #16
0
 /// <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;
 }
Пример #17
0
 public CustomField(int id, int projectId, string name, ValidationDataType dataType, bool required, string value)
 {
     _Id        = id;
     _ProjectId = projectId;
     _Name      = name;
     _DataType  = dataType;
     _Required  = required;
     _Value     = value;
 }
Пример #18
0
        /// <internalonly/>
        /// <devdoc>
        ///    AddAttributesToRender method
        /// </devdoc>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (RenderUplevel)
            {
                ValidationDataType type = Type;
                if (type != ValidationDataType.String)
                {
                    string         id = ClientID;
                    HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering || IsUnobtrusive) ? writer : null;

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

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

                        string groupChar = info.CurrencyGroupSeparator;
                        // Map non-break space onto regular space for parsing
                        if (groupChar[0] == 160)
                        {
                            groupChar = " ";
                        }
                        AddExpandoAttribute(expandoAttributeWriter, id, "groupchar", groupChar);

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

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

                        // VSWhidbey 504553: The changes of this


                        int currentYear = DateTime.Today.Year;
                        int century     = currentYear - (currentYear % 100);
                        AddExpandoAttribute(expandoAttributeWriter, id, "century", century.ToString(NumberFormatInfo.InvariantInfo), false);
                    }
                }
            }
        }
Пример #19
0
 public new bool Compare(string leftText,
                         string rightText,
                         ValidationCompareOperator op,
                         ValidationDataType type)
 {
     return(BaseCompareValidator.Compare(leftText,
                                         rightText,
                                         op, type));
 }
Пример #20
0
 public void Init()
 {
     _Id = 1;
     _Name = "New Custom Field";
     _Required = true;
     _Value = "ValueTest";
     _DataType = ValidationDataType.String;
     _FieldType = CustomField.CustomFieldType.Text;
 }
Пример #21
0
 public void Init()
 {
     _Id        = 1;
     _Name      = "New Custom Field";
     _Required  = true;
     _Value     = "ValueTest";
     _DataType  = ValidationDataType.String;
     _FieldType = CustomField.CustomFieldType.Text;
 }
Пример #22
0
		public new bool Compare(string leftText,
					string rightText,
					ValidationCompareOperator op,
					ValidationDataType type)
		{
			return BaseCompareValidator.Compare (leftText,
							     rightText,
							     op, type);
		}
 private void IncompatibleCheck(ValidationDataType dataType, object value1, object value2)
 {
     CurrentDataType       = dataType;
     _holder.otherProperty = value1;
     Assert.IsNull(PerformCheck(value2),
                   String.Format(
                       "Check for type {0} ({1}, {2}) should be valid (incompatible types can not be judged",
                       dataType, value1, value2));
 }
Пример #24
0
        public static bool CompareTypes(string leftText, ValidationDataType type)
        {
            System.Web.UI.WebControls.ValidationDataType vdt =
                (System.Web.UI.WebControls.ValidationDataType)Enum.Parse(
                    typeof(System.Web.UI.WebControls.ValidationDataType),
                    type.ToString());

            return(BaseCompareValidator.CanConvert(leftText, vdt));
        }
        public IComparer GetComparer(ValidationDataType dataType)
        {
            if (_comparers.TryGetValue(dataType, out var comparer))
            {
                return(comparer);
            }

            throw new ArgumentOutOfRangeException(nameof(dataType));
        }
Пример #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:CustomField"/> class.
 /// </summary>
 /// <param name="id">The id.</param>
 /// <param name="projectId">The project id.</param>
 /// <param name="name">The name.</param>
 /// <param name="dataType">Type of the data.</param>
 /// <param name="required">if set to <c>true</c> [required].</param>
 /// <param name="value">The value.</param>
 /// <param name="fieldType">Type of the field.</param>
 public CustomField(int id, int projectId, string name, ValidationDataType dataType, bool required, string value, CustomFieldType fieldType)
 {
     _Id = id;
         _ProjectId = projectId;
         _Name = name;
         _DataType = dataType;
         _Required = required;
         _Value = value;
         _FieldType = fieldType;
 }
Пример #27
0
        // Varsayılan hata mesajlı yapıcı
        public ValidateCompare(string propertyName, string otherPropertyName,
                               ValidationOperator @operator, ValidationDataType dataType)
            : base(propertyName)
        {
            OtherPropertyName = otherPropertyName;
            Operator          = @operator;
            DataType          = dataType;

            Error = propertyName + otherPropertyName + Operator.ToString() + ERRORMESSAGE;
        }
Пример #28
0
 public CompareValidationRule(
     ValidationCompareOperator compareOperator,
     ValidationDataType ruleDataType,
     string valueToCompare, string errorMassage)
     : base("Compare", errorMassage)
 {
     this.compareOperator = compareOperator;
     this.ruleDataType    = ruleDataType;
     this.valueToCompare  = valueToCompare;
 }
        public ValidateCompare(string propertyName, string otherPropertyName,
                               ValidationOperator @operator, ValidationDataType dataType)
            : base(propertyName)
        {
            OtherPropertyName = otherPropertyName;
            Operator          = @operator;
            DataType          = dataType;

            Error = propertyName + " must be " + Operator.ToString() + " than " + otherPropertyName;
        }
Пример #30
0
        public ValidateCompare(string propertyName, string otherPropertyName, 
            ValidationOperator @operator, ValidationDataType dataType )
            : base(propertyName)
        {
            OtherPropertyName = otherPropertyName;
            Operator = @operator;
            DataType = dataType;

            ErrorMessage = propertyName + " must be " + Operator.ToString() + " than " + otherPropertyName;
        }
Пример #31
0
        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);
            }
        }
Пример #32
0
        public void SetDataType(Control control, ValidationDataType dataType)
        {
            if (!this.infos.ContainsKey(control))
            {
                this.AddValidationInfo(control);
            }

            ValidationInfo info = this.infos[control];

            info.DataType = dataType;
        }
Пример #33
0
        static bool Convert(string text,
                            ValidationDataType type,
                            bool cultureInvariant,
                            out object value)
        {
            try
            {
                switch (type)
                {
                case ValidationDataType.String:
                    value = text;
                    return(value != null);

                case ValidationDataType.Integer:
                    IFormatProvider intFormatProvider = (cultureInvariant) ?
                                                        NumberFormatInfo.InvariantInfo :
                                                        NumberFormatInfo.CurrentInfo;
                    value = Int32.Parse(text, intFormatProvider);
                    return(true);

                case ValidationDataType.Double:
                    IFormatProvider doubleFormatProvider = (cultureInvariant) ?
                                                           NumberFormatInfo.InvariantInfo :
                                                           NumberFormatInfo.CurrentInfo;
                    value = Double.Parse(text, doubleFormatProvider);
                    return(true);

                case ValidationDataType.Date:

                    IFormatProvider dateFormatProvider = (cultureInvariant) ?
                                                         DateTimeFormatInfo.InvariantInfo :
                                                         DateTimeFormatInfo.CurrentInfo;

                    value = DateTime.Parse(text, dateFormatProvider);
                    return(true);

                case ValidationDataType.Currency:
                    IFormatProvider currencyFormatProvider = (cultureInvariant) ?
                                                             NumberFormatInfo.InvariantInfo :
                                                             NumberFormatInfo.CurrentInfo;
                    value = Decimal.Parse(text, NumberStyles.Currency, currencyFormatProvider);
                    return(true);

                default:
                    value = null;
                    return(false);
                }
            }
            catch
            {
                value = null;
                return(false);
            }
        }
Пример #34
0
 internal static string ConvertCultureInvariantToCurrentCultureFormat(string valueInString,
                                                               ValidationDataType type) {
     object value;
     Convert(valueInString, type, true, out value);
     if (value is DateTime) {
         return ((DateTime)value).ToShortDateString();
     }
     else {
         return System.Convert.ToString(value, CultureInfo.CurrentCulture);
     }
 }
        // Varsayılan hata mesajlı yapıcı
        public ValidateCompare(string propertyName, string otherPropertyName, 
            ValidationOperator @operator, ValidationDataType dataType )
            : base(propertyName)
        {
            
            OtherPropertyName = otherPropertyName;
            Operator = @operator;
            DataType = dataType;

            Error = propertyName + otherPropertyName + Operator.ToString() + ERRORMESSAGE;
        }
Пример #36
0
 public ValidatorParams(bool enabled, double minValue, double maxValue, ValidationDataType contenType,
                        string errorMessage, TextBoxMode textBoxTextMode, bool enableRequireValidator)
 {
     Enabled                 = enabled;
     MinValue                = minValue.ToString();
     MaxValue                = maxValue.ToString();
     ContentType             = contenType;
     ErrorMessage            = errorMessage;
     TextBoxTextMode         = textBoxTextMode;
     RequireValidatorEnabled = enableRequireValidator;
 }
Пример #37
0
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (base.RenderUplevel)
            {
                ValidationDataType enumValue = this.Type;
                if (enumValue != ValidationDataType.String)
                {
                    string         clientID = this.ClientID;
                    HtmlTextWriter writer2  = base.EnableLegacyRendering ? writer : null;
                    base.AddExpandoAttribute(writer2, clientID, "type", PropertyConverter.EnumToString(typeof(ValidationDataType), enumValue), false);
                    NumberFormatInfo currentInfo = NumberFormatInfo.CurrentInfo;
                    switch (enumValue)
                    {
                    case ValidationDataType.Double:
                    {
                        string numberDecimalSeparator = currentInfo.NumberDecimalSeparator;
                        base.AddExpandoAttribute(writer2, clientID, "decimalchar", numberDecimalSeparator);
                        return;
                    }

                    case ValidationDataType.Currency:
                    {
                        string currencyDecimalSeparator = currentInfo.CurrencyDecimalSeparator;
                        base.AddExpandoAttribute(writer2, clientID, "decimalchar", currencyDecimalSeparator);
                        string currencyGroupSeparator = currentInfo.CurrencyGroupSeparator;
                        if (currencyGroupSeparator[0] == '\x00a0')
                        {
                            currencyGroupSeparator = " ";
                        }
                        base.AddExpandoAttribute(writer2, clientID, "groupchar", currencyGroupSeparator);
                        base.AddExpandoAttribute(writer2, clientID, "digits", currentInfo.CurrencyDecimalDigits.ToString(NumberFormatInfo.InvariantInfo), false);
                        int currencyGroupSize = GetCurrencyGroupSize(currentInfo);
                        if (currencyGroupSize > 0)
                        {
                            base.AddExpandoAttribute(writer2, clientID, "groupsize", currencyGroupSize.ToString(NumberFormatInfo.InvariantInfo), false);
                            return;
                        }
                        break;
                    }

                    case ValidationDataType.Date:
                    {
                        base.AddExpandoAttribute(writer2, clientID, "dateorder", GetDateElementOrder(), false);
                        base.AddExpandoAttribute(writer2, clientID, "cutoffyear", CutoffYear.ToString(NumberFormatInfo.InvariantInfo), false);
                        int year = DateTime.Today.Year;
                        base.AddExpandoAttribute(writer2, clientID, "century", (year - (year % 100)).ToString(NumberFormatInfo.InvariantInfo), false);
                        break;
                    }
                    }
                }
            }
        }
Пример #38
0
        public ValidateRange(string propertyName, object min, object max,
            ValidationOperator @operator, ValidationDataType dataType)
            : base(propertyName)
        {
            Min = min;
            Max = max;

            Operator = @operator;
            DataType = dataType;

            ErrorMessage = propertyName + " must be between " + Min + " and " + Max;
        }
		/// <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);
		}
Пример #40
0
	    /// <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 void SetDataType(Control control, ValidationDataType dataType)
        {
            if (!this.infos.ContainsKey(control))
            {
                this.AddValidationInfo(control);
            }

            ValidationInfo info = this.infos[control];
            info.DataType = dataType;
        }
 protected static bool Convert(string text, ValidationDataType type, out object value)
 {
     return Convert(text, type, false, out value);
 }
 // Değiştirilmiş hata mesajlı yapıcı
 public ValidateCompare(string propertyName, string otherPropertyName, string errorMessage,
     ValidationOperator @operator, ValidationDataType dataType )
     : this(propertyName, otherPropertyName, @operator, dataType)
 {
     Error = errorMessage;
 }
 internal string ConvertCultureInvariantToCurrentCultureFormat(string valueInString, ValidationDataType type)
 {
     object obj2;
     Convert(valueInString, type, true, out obj2);
     if (obj2 is DateTime)
     {
         DateTime time = (DateTime) obj2;
         return time.ToShortDateString();
     }
     return System.Convert.ToString(obj2, CultureInfo.CurrentCulture);
 }
        protected static bool Convert(string text, ValidationDataType type, bool cultureInvariant, out object value)
        {
            value = null;
            try
            {
                string str;
                string str3;
                switch (type)
                {
                    case ValidationDataType.String:
                        value = text;
                        goto Label_0118;

                    case ValidationDataType.Integer:
                        value = int.Parse(text, CultureInfo.InvariantCulture);
                        goto Label_0118;

                    case ValidationDataType.Double:
                        if (!cultureInvariant)
                        {
                            break;
                        }
                        str = ConvertDouble(text, CultureInfo.InvariantCulture.NumberFormat);
                        goto Label_0065;

                    case ValidationDataType.Date:
                        if (!cultureInvariant)
                        {
                            goto Label_0094;
                        }
                        value = ConvertDate(text, "ymd");
                        goto Label_0118;

                    case ValidationDataType.Currency:
                        if (!cultureInvariant)
                        {
                            goto Label_00EF;
                        }
                        str3 = ConvertCurrency(text, CultureInfo.InvariantCulture.NumberFormat);
                        goto Label_00FB;

                    default:
                        goto Label_0118;
                }
                str = ConvertDouble(text, NumberFormatInfo.CurrentInfo);
            Label_0065:
                if (str != null)
                {
                    value = double.Parse(str, CultureInfo.InvariantCulture);
                }
                goto Label_0118;
            Label_0094:
                if (!(DateTimeFormatInfo.CurrentInfo.Calendar.GetType() == typeof(GregorianCalendar)))
                {
                    value = DateTime.Parse(text, CultureInfo.CurrentCulture);
                }
                else
                {
                    string dateElementOrder = GetDateElementOrder();
                    value = ConvertDate(text, dateElementOrder);
                }
                goto Label_0118;
            Label_00EF:
                str3 = ConvertCurrency(text, NumberFormatInfo.CurrentInfo);
            Label_00FB:
                if (str3 != null)
                {
                    value = decimal.Parse(str3, CultureInfo.InvariantCulture);
                }
            }
            catch
            {
                value = null;
            }
        Label_0118:
            return (value != null);
        }
Пример #46
0
		public new bool CanConvert(string text,
					   ValidationDataType type)
		{
			return BaseCompareValidator.CanConvert (text, type);
		}
 public static bool CanConvert(string text, ValidationDataType type)
 {
     return CanConvert(text, type, false);
 }
 public static bool CanConvert(string text, ValidationDataType type, bool cultureInvariant)
 {
     object obj2 = null;
     return Convert(text, type, cultureInvariant, out obj2);
 }
 protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, ValidationCompareOperator op, ValidationDataType type)
 {
   return default(bool);
 }
Пример #50
0
		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 Convert(string text, ValidationDataType type, out Object value)
    {
      value = default(Object);

      return default(bool);
    }
Пример #52
0
 public ValidateRange(string propertyName, string errorMessage, object min, object max,
     ValidationOperator @operator, ValidationDataType dataType)
     : this(propertyName,  min,  max,@operator, dataType)
 {
     ErrorMessage = errorMessage;
 }
 protected static bool Compare(string leftText, string rightText, ValidationCompareOperator op, ValidationDataType type)
 {
     return Compare(leftText, false, rightText, false, op, type);
 }
Пример #54
0
		public new bool Convert (string text,
					 ValidationDataType type,
					 out object value)
		{
			return BaseCompareValidator.Convert (text, type, out value);
		}
Пример #55
0
        public static bool CompareTypes(string leftText, ValidationDataType type)
        {
            

            System.Web.UI.WebControls.ValidationDataType vdt =
                (System.Web.UI.WebControls.ValidationDataType)Enum.Parse(
                typeof(System.Web.UI.WebControls.ValidationDataType),
                type.ToString());

            return BaseCompareValidator.CanConvert(leftText, vdt);
        }
 public static bool CanConvert(string text, ValidationDataType type)
 {
   return default(bool);
 }
Пример #57
0
		protected static bool Convert (string text, ValidationDataType type, bool cultureInvariant,out object value)
		{
			try {
				switch (type) {
					case ValidationDataType.String:
						value = text;
						return value != null;

					case ValidationDataType.Integer:
						IFormatProvider intFormatProvider = (cultureInvariant) ? NumberFormatInfo.InvariantInfo :
						NumberFormatInfo.CurrentInfo;
						value = Int32.Parse(text, intFormatProvider);
						return true;

					case ValidationDataType.Double:
						IFormatProvider doubleFormatProvider = (cultureInvariant) ? NumberFormatInfo.InvariantInfo :
						NumberFormatInfo.CurrentInfo;
						value = Double.Parse(text, doubleFormatProvider);
						return true;

					case ValidationDataType.Date:
                        
						IFormatProvider dateFormatProvider = (cultureInvariant) ? DateTimeFormatInfo.InvariantInfo :
						DateTimeFormatInfo.CurrentInfo;

						value = DateTime.Parse(text, dateFormatProvider);
						return true;

					case ValidationDataType.Currency:
						IFormatProvider currencyFormatProvider = (cultureInvariant) ? NumberFormatInfo.InvariantInfo :
						NumberFormatInfo.CurrentInfo;
						value = Decimal.Parse(text, NumberStyles.Currency, currencyFormatProvider);
						return true;

					default:
						value = null;
						return false;
				}
			} catch {
				value = null;
				return false;
			}
		}
        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;
        }
        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 Convert(string text, ValidationDataType type, bool cultureInvariant, out object value) {

            value = null;
            try {
                switch (type) {
                    case ValidationDataType.String:
                        value = text;
                        break;

                    case ValidationDataType.Integer:
                        value = Int32.Parse(text, CultureInfo.InvariantCulture);
                        break;

                    case ValidationDataType.Double: {
                        string cleanInput;
                        if (cultureInvariant) {
                            cleanInput = ConvertDouble(text, CultureInfo.InvariantCulture.NumberFormat);
                        }
                        else {
                            cleanInput = ConvertDouble(text, NumberFormatInfo.CurrentInfo);
                        }

                        if (cleanInput != null) {
                            value = Double.Parse(cleanInput, CultureInfo.InvariantCulture);
                        }
                        break;
                    }

                    case ValidationDataType.Date: {
                        if (cultureInvariant) {
                            value = ConvertDate(text, "ymd");
                        }
                        else {
                            // if the calendar is not gregorian, we should not enable client-side, so just parse it directly:
                            if (!(DateTimeFormatInfo.CurrentInfo.Calendar.GetType() == typeof(GregorianCalendar))) {
                                value = DateTime.Parse(text, CultureInfo.CurrentCulture);
                                break;
                            }

                            string dateElementOrder = GetDateElementOrder();
                            value = ConvertDate(text, dateElementOrder);
                        }
                        break;
                    }

                    case ValidationDataType.Currency: {
                        string cleanInput;
                        if (cultureInvariant) {
                            cleanInput = ConvertCurrency(text, CultureInfo.InvariantCulture.NumberFormat);
                        }
                        else {
                            cleanInput = ConvertCurrency(text, NumberFormatInfo.CurrentInfo);
                        }

                        if (cleanInput != null) {
                            value = Decimal.Parse(cleanInput, CultureInfo.InvariantCulture);
                        }
                        break;
                    }
                }
            }
            catch {
                value = null;
            }
            return (value != null);
        }