NumberTextBox
public abstract class NumberTextBox<T> : BaseTextBox where T : IComparable<T> { private T minValue = default(T); public virtual T MinValue { get { return minValue; } set { minValue = value; } } private T maxValue = default(T); public virtual T MaxValue { get { return maxValue; } set { maxValue = value; } } protected abstract T DefaultMinValue { get; } protected abstract T DefaultMaxValue { get; } protected ValidationDataType type; public virtual ValidationDataType Type { get { return type; } set { type = value; } } public NumberTextBox() { this.FilterType = FilterTypes.Numbers; this.Options = TextBoxOptions.Required | TextBoxOptions.Filtered; this.MaxValue = this.DefaultMaxValue; this.MinValue = this.DefaultMinValue; } protected override void BuildValidatorControls() { base.BuildValidatorControls(); //添加额外的控件 if ((this.MinValue.CompareTo(this.DefaultMinValue) != 0) && (this.MaxValue.CompareTo(this.DefaultMaxValue) != 0)) { RangeValidator rv = new RangeValidator(); rv.ID = "rv_" + this.ID; rv.ControlToValidate = this.ID; rv.MaximumValue = this.MaxValue.ToString(); rv.MinimumValue = this.MinValue.ToString(); rv.SetFocusOnError = true; rv.Type = this.Type; rv.ErrorMessage = string.Format("{0}的值应该位于{1}和{2}之间", this.DisplayName, this.MinValue, this.MaxValue); this.AddValidator(rv); } else if (this.MinValue.CompareTo(this.DefaultMinValue) != 0) { CompareValidator cv = new CompareValidator(); cv.ID = "rv_" + this.ID; cv.ControlToValidate = this.ID; cv.SetFocusOnError = true; cv.Type = this.Type; cv.Operator = ValidationCompareOperator.GreaterThanEqual; cv.ValueToCompare = this.MinValue.ToString(); cv.ErrorMessage = string.Format("{0}的值应该大于{1}", this.DisplayName, this.MinValue); this.AddValidator(cv); } else if ((this.MaxValue.CompareTo(this.DefaultMaxValue) != 0)) { CompareValidator cv = new CompareValidator(); cv.ID = "rv_" + this.ID; cv.ControlToValidate = this.ID; cv.SetFocusOnError = true; cv.Type = this.Type; cv.Operator = ValidationCompareOperator.LessThanEqual; cv.ValueToCompare = this.MaxValue.ToString(); cv.ErrorMessage = string.Format("{0}的值应该小于{1}", this.DisplayName, this.MaxValue); this.AddValidator(cv); } } } public class NumberTextBox : NumberTextBox<int> { public NumberTextBox() { this.Type = ValidationDataType.Integer; } protected override int DefaultMinValue { get { return int.MinValue; } } protected override int DefaultMaxValue { get { return int.MaxValue; } } } public class MoneyTextBox : NumberTextBox<decimal> { public MoneyTextBox() { this.Type = ValidationDataType.Currency; } protected override decimal DefaultMinValue { get { return decimal.MinValue; } } protected override decimal DefaultMaxValue { get { return decimal.MaxValue; } } }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索return
, this
, public
, cv ait ey
, cv 32f
, type
, protected
, cv svm
动态this
c 复合控件、android 复合控件、复合控件、delphi 复合控件、动态复合开关,以便于您获取更多的相关知识。
时间: 2025-01-21 16:01:22