Esempio n. 1
0
        public override void SetData(object data)
        {
            var templated = this.IsTemplated;

            Label   title        = null;
            Label   desc         = null;
            TextBox innerControl = null;
            var     setting      = this.Field == null ? null : (NumberFieldSetting)this.Field.FieldSetting;
            var     digits       = Math.Min(setting == null || !setting.Digits.HasValue ? 2 : setting.Digits.Value, 29);
            var     format       = "F" + digits;

            if (templated)
            {
                title        = GetLabelForTitleControl() as Label;
                desc         = GetLabelForDescription() as Label;
                innerControl = GetInnerControl() as TextBox;

                if (this.Field != null)
                {
                    if (title != null)
                    {
                        title.Text = HttpUtility.HtmlEncode(this.Field.DisplayName);
                    }
                    if (desc != null)
                    {
                        desc.Text = Sanitizer.Sanitize(this.Field.Description);
                    }
                }

                if (desc != null)
                {
                    var text       = SR.GetString(SR.FieldControls.Number_ValidFormatIs);
                    var formatDesc = text + ((decimal)1234.56).ToString(format);
                    var descText   = desc.Text;
                    if (string.IsNullOrEmpty(descText) || descText.EndsWith("."))
                    {
                        desc.Text = string.Concat(descText, " ", formatDesc).Trim(' ');
                    }
                    else
                    {
                        desc.Text = string.Concat(descText, ". ", formatDesc).Trim(' ');
                    }
                }
            }

            if (data == null)
            {
                _inputTextBox.Text = string.Empty;

                if (innerControl != null)
                {
                    innerControl.Text = string.Empty;
                }

                return;
            }

            decimal decimalData;
            var     stringData = data as string;

            if (stringData != null)
            {
                if (stringData == string.Empty)
                {
                    decimalData = ActiveSchema.DecimalMinValue;
                }
                else if (!Decimal.TryParse(stringData, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.GetCultureInfo("en-us"), out decimalData))
                {
                    throw new ApplicationException(String.Concat(
                                                       "Default decimal value is not in a correct format. ContentType: ", this.Field.Content.ContentType.Name,
                                                       " Field Name: ", this.FieldName));
                }
            }
            else
            {
                decimalData = (decimal)data;

                if (setting.ShowAsPercentage.HasValue && setting.ShowAsPercentage.Value)
                {
                    decimalData *= 100;
                }
            }

            _inputTextBox.Text = decimalData <= ActiveSchema.DecimalMinValue ? string.Empty : decimalData.ToString(format);

            if (!templated)
            {
                return;
            }

            if (innerControl != null)
            {
                innerControl.Text = decimalData <= ActiveSchema.DecimalMinValue
                    ? string.Empty
                    : decimalData.ToString(format);
            }


            var perc = GetLabelForPercentageControl();

            if (perc != null)
            {
                if (!SkinManager.IsNewSkin())
                {
                    perc.Text    = GetPercentageSign();
                    perc.Visible = !string.IsNullOrEmpty(perc.Text);
                }
                else
                {
                    var percentageSign = GetPercentageSign();
                    perc.CssClass = "percentage";
                    perc.Attributes.Add("data-percentage", (!string.IsNullOrEmpty(percentageSign)).ToString());
                }
            }

            if (innerControl != null)
            {
                if (setting.MinValue.HasValue)
                {
                    innerControl.Attributes.Add("data-min", setting.MinValue.Value.ToString());
                }

                if (setting.MaxValue.HasValue)
                {
                    innerControl.Attributes.Add("data-max", setting.MaxValue.Value.ToString());
                }

                if (setting.Step.HasValue)
                {
                    innerControl.Attributes.Add("data-step", setting.Step.Value.ToString());
                }

                innerControl.Attributes.Add("data-digits", digits.ToString());
            }

            var formats = GetNumberFormatControl();

            if (formats != null)
            {
                formats.Text = NumberFormatSerializer.GetJson(GetNumberFormatInfo());
            }
        }
Esempio n. 2
0
        // Methods //////////////////////////////////////////////////////////////////////
        public override void SetData(object data)
        {
            var setting = this.Field == null ? null : (IntegerFieldSetting)this.Field.FieldSetting;

            if (data == null)
            {
                _inputTextBox.Text = string.Empty;
            }
            else
            {
                _inputTextBox.Text = Convert.ToInt32(data) == int.MinValue ? string.Empty : data.ToString();
            }

            #region template

            if (!IsTemplated)
            {
                return;
            }

            SetTitleAndDescription();

            var innerControl = GetInnerControl() as TextBox;
            var perc         = GetLabelForPercentageControl();

            if (innerControl != null)
            {
                innerControl.Text = Convert.ToString(_inputTextBox.Text);
            }
            if (perc != null)
            {
                if (!SkinManager.IsNewSkin())
                {
                    perc.Text    = GetPercentageSign();
                    perc.Visible = !string.IsNullOrEmpty(perc.Text);
                }
                else
                {
                    perc.CssClass = "percentage";
                    perc.Attributes.Add("data-percentage", (!string.IsNullOrEmpty(GetPercentageSign())).ToString());
                }
            }

            if (innerControl != null)
            {
                if (setting.MinValue.HasValue)
                {
                    innerControl.Attributes.Add("data-min", setting.MinValue.Value.ToString());
                }

                if (setting.MaxValue.HasValue)
                {
                    innerControl.Attributes.Add("data-max", setting.MaxValue.Value.ToString());
                }

                if (setting.Step.HasValue)
                {
                    innerControl.Attributes.Add("data-step", setting.Step.Value.ToString());
                }
            }

            var formats = GetNumberFormatControl();
            if (formats != null)
            {
                formats.Text = NumberFormatSerializer.GetJson();
            }

            #endregion
        }