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 ();
Add an extra control
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. The value of Format ("{0}" should be between {1} and {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. The value of Format (' {0} ' should be greater than {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. The value for Format (' {0} ' should be less than {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; }
}
}