/// <summary>
        ///		Adds the HTML attributes and styles that need to be rendered for the control to the specified <see cref='System.Web.UI.HtmlTextWriter'/> object.
        /// </summary>
        /// <param name="writer">A <see cref='System.Web.UI.HtmlTextWriter'/> that contains the output stream for rendering on the client.</param>
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            base.AddAttributesToRender(writer);
            if (RenderUplevel)
            {
                WebControls.ValidationDataType type = Type;
                if (type != WebControls.ValidationDataType.String)
                {
                    string         id = ClientID;
                    HtmlTextWriter expandoAttributeWriter = (EnableLegacyRendering) ? writer : null;

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

                    NumberFormatInfo info = NumberFormatInfo.CurrentInfo;
                    if (type == WebControls.ValidationDataType.Double)
                    {
                        string decimalChar = info.NumberDecimalSeparator;
                        AddExpandoAttribute(expandoAttributeWriter, id, "decimalchar", decimalChar);
                    }
                    else if (type == WebControls.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 == WebControls.ValidationDataType.Date)
                    {
                        AddExpandoAttribute(expandoAttributeWriter, id, "dateorder", GetDateElementOrder(), false);
                        AddExpandoAttribute(expandoAttributeWriter, id, "cutoffyear", CutoffYear.ToString(NumberFormatInfo.InvariantInfo), false);

                        // VSWhidbey 504553: The changes of this bug make client-side script not
                        // using the century attribute anymore, but still generating it for
                        // backward compatibility with Everett pages.
                        int currentYear = DateTime.Today.Year;
                        int century     = currentYear - (currentYear % 100);
                        AddExpandoAttribute(expandoAttributeWriter, id, "century", century.ToString(NumberFormatInfo.InvariantInfo), false);
                    }
                }
            }
        }
示例#2
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));
        }
        /// <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));
        }
示例#4
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));
        }
        /// <summary>
        ///		Determines whether the specified string can be converted to the specified data type. This version of the overloaded method allows you to specify whether values are tested using a culture-neutral format.
        /// </summary>
        /// <param name="text">The string to test.</param>
        /// <param name="type">One of the <see cref='System.Web.UI.WebControls.ValidationDataType'/> enumeration values.</param>
        /// <param name="cultureInvariant">true to test values using a culture-neutral format; otherwise, false.</param>
        /// <returns>true if the specified data string can be converted to the specified data type; otherwise, false.</returns>
        public static bool CanConvert(string text, WebControls.ValidationDataType type, bool cultureInvariant)
        {
            object value = null;

            return(Convert(text, type, cultureInvariant, out value));
        }
 /// <summary>
 ///		Determines whether the specified string can be converted to the specified data type. This version of the overloaded method tests currency, double, and date values using the format used by the current culture.
 /// </summary>
 /// <param name="text">The string to test.</param>
 /// <param name="type">One of the <see cref='System.Web.UI.WebControls.ValidationDataType'/> values.</param>
 /// <returns>true if the specified data string can be converted to the specified data type; otherwise, false.</returns>
 public static bool CanConvert(string text, WebControls.ValidationDataType type)
 {
     return(CanConvert(text, type, false));
 }
        /// <summary>
        ///		Converts a culture invariant to a current culture format.
        /// </summary>
        /// <param name="valueInString"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        internal string ConvertCultureInvariantToCurrentCultureFormat(string valueInString, WebControls.ValidationDataType type)
        {
            object value;

            Convert(valueInString, type, true, out value);
            return
                (value is DateTime
                 // For Date type we explicitly want the date portion only
                                        ? ((DateTime)value).ToShortDateString()
                                        : System.Convert.ToString(value, CultureInfo.CurrentCulture));
        }
        /// <summary>
        ///		Compare two strings using the type and operator
        /// </summary>
        /// <param name="leftText"></param>
        /// <param name="cultureInvariantLeftText"></param>
        /// <param name="rightText"></param>
        /// <param name="cultureInvariantRightText"></param>
        /// <param name="op"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        protected static bool Compare(string leftText, bool cultureInvariantLeftText, string rightText, bool cultureInvariantRightText, WebControls.ValidationCompareOperator op, WebControls.ValidationDataType type)
        {
            object leftObject;

            if (!Convert(leftText, type, cultureInvariantLeftText, out leftObject))
            {
                return(false);
            }

            if (op == WebControls.ValidationCompareOperator.DataTypeCheck)
            {
                return(true);
            }

            object rightObject;

            if (!Convert(rightText, type, cultureInvariantRightText, out rightObject))
            {
                return(true);
            }

            int compareResult;

            switch (type)
            {
            case WebControls.ValidationDataType.String:
                compareResult = String.Compare((string)leftObject, (string)rightObject, false, CultureInfo.CurrentCulture);
                break;

            case WebControls.ValidationDataType.Integer:
                compareResult = ((int)leftObject).CompareTo(rightObject);
                break;

            case WebControls.ValidationDataType.Double:
                compareResult = ((double)leftObject).CompareTo(rightObject);
                break;

            case WebControls.ValidationDataType.Date:
                compareResult = ((DateTime)leftObject).CompareTo(rightObject);
                break;

            case WebControls.ValidationDataType.Currency:
                compareResult = ((Decimal)leftObject).CompareTo(rightObject);
                break;

            default:
                Debug.Fail("Unknown Type");
                return(true);
            }
            switch (op)
            {
            case WebControls.ValidationCompareOperator.Equal:
                return(compareResult == 0);

            case WebControls.ValidationCompareOperator.NotEqual:
                return(compareResult != 0);

            case WebControls.ValidationCompareOperator.GreaterThan:
                return(compareResult > 0);

            case WebControls.ValidationCompareOperator.GreaterThanEqual:
                return(compareResult >= 0);

            case WebControls.ValidationCompareOperator.LessThan:
                return(compareResult < 0);

            case WebControls.ValidationCompareOperator.LessThanEqual:
                return(compareResult <= 0);

            default:
                Debug.Fail("Unknown Operator");
                return(true);
            }
        }
 /// <summary>
 ///		Compare two strings using the type and operator
 /// </summary>
 /// <param name="leftText"></param>
 /// <param name="rightText"></param>
 /// <param name="op"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 protected static bool Compare(string leftText, string rightText, WebControls.ValidationCompareOperator op, WebControls.ValidationDataType type)
 {
     return(Compare(leftText, false, rightText, false, op, type));
 }
示例#10
0
        /// <summary>
        ///		Try to convert the test into the validation data type
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        /// <param name="cultureInvariant"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        protected static bool Convert(string text, WebControls.ValidationDataType type, bool cultureInvariant, out object value)
        {
            value = null;
            try {
                switch (type)
                {
                case WebControls.ValidationDataType.String:
                    value = text;
                    break;

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

                case WebControls.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 WebControls.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 WebControls.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);
        }
示例#11
0
 /// <summary>
 ///		Try to convert the test into the validation data type
 /// </summary>
 /// <param name="text"></param>
 /// <param name="type"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 protected static bool Convert(string text, WebControls.ValidationDataType type, out object value)
 {
     return(Convert(text, type, false, out value));
 }
示例#12
0
 public static bool CompareValues(string leftText, string rightText, System.Web.UI.WebControls.ValidationCompareOperator vco, System.Web.UI.WebControls.ValidationDataType vdt)
 {
     return(BaseCompareValidator.Compare(leftText, rightText, vco, vdt));
 }
示例#13
0
 public static bool CanConvert(string text, System.Web.UI.WebControls.ValidationDataType vdt)
 {
     return(BaseCompareValidator.CanConvert(text, vdt));
 }