Simulating a composite control with a dynamic control (ii)

Source: Internet
Author: User
Tags abstract

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; }
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.