using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; using System.Globalization; using CMS.FormControls; using CMS.GlobalHelper; public partial class CMSFormControls_Inputs_TextboxDoubleValidator : FormEngineUserControl { #region "Properties" /// /// Gets or sets the value of this form control. /// [Browsable(false)] public override object Value { get { String val = txtValue.Text.Trim(); if (CultureInfo.CurrentCulture.Name != CultureHelper.EnglishCulture.Name) { // If value is double, convert it to default english format double dVal = ValidationHelper.GetDouble(val, 0.0); if (dVal != 0) { val = dVal.ToString(CultureHelper.EnglishCulture); } } return val; } set { String val = ValidationHelper.GetString(value, String.Empty); if (CultureInfo.CurrentCulture.Name != CultureHelper.EnglishCulture.Name) { // Convert to english value format double dVal = ValidationHelper.GetDouble(val, 0.0, CultureHelper.EnglishCulture); if (dVal != 0) { val = dVal.ToString(); } } txtValue.Text = val; } } /// /// Gets or sets whether this form control is enabled. /// [Browsable(true)] [Description("Determines whether this form control is enabled")] [Category("Form Control")] [DefaultValue(true)] public override bool Enabled { get { return txtValue.Enabled; } set { txtValue.Enabled = value; } } /// /// Max allowed input of textbox /// [Browsable(true)] public int MaxLength { get { return txtValue.MaxLength; } set { txtValue.MaxLength = value; } } #endregion #region "Methods" /// /// Validates control. Returns true, if control contains double or macro. /// public override bool IsValid() { String val = txtValue.Text.Trim(); if (String.IsNullOrEmpty(val)) { return true; } if (ValidationHelper.IsMacro(val) || ValidationHelper.IsDouble(val)) { return true; } ErrorMessage = GetString("ecommerce.settings.doubleormacro"); return false; } #endregion }