Ejemplo n.º 1
0
 private bool ValidateRequired(Ctrl ctrl)
 {
     var c = (RequiredCtrl)ctrl;
         string val = GetText(c.source);
         if (!string.IsNullOrEmpty(val))
         {
             SetText(c.target, string.Empty);
             return true;
         }
         if (string.IsNullOrEmpty(c.msg)) SetText(c.target, c.name + " is required.");
         else SetText(c.target, c.msg);
         return false;
 }
Ejemplo n.º 2
0
 private bool validateRegex(Ctrl ctrl)
 {
     var c = (RegexCtrl)ctrl;
         string val = GetText(c.source);
         if (Regex.IsMatch(c.Regexp, val))
         {
             SetText(c.target, string.Empty);
             return true;
         }
         if (string.IsNullOrEmpty(c.msg)) SetText(c.target, c.name + " is in invalid format.");
         else SetText(c.target, c.msg);
         return false;
 }
Ejemplo n.º 3
0
 private bool validateCustom(Ctrl ctrl)
 {
     var c = (CustomCtrl)ctrl;
         if (c.test(c))
         {
             SetText(c.target, string.Empty);
             return true;
         }
         SetText(c.target, c.msg);
         return false;
 }
Ejemplo n.º 4
0
 private bool ValidateRange(Ctrl ctrl)
 {
     var c = (RangeCtrl)ctrl;
         string val = GetText(c.source);
         if (!(val.Length < c.min || val.Length > c.max))
         {
             SetText(c.target, string.Empty);
             return true;
         }
         if (string.IsNullOrEmpty(c.msg)) SetText(c.target, c.name + "'s length is out of specified range.");
         else SetText(c.target, c.msg);
         return false;
 }
Ejemplo n.º 5
0
 public void Set(Ctrl[] cs)
 {
     foreach (var c in cs)
         {
             if (c is RequiredCtrl)
                 c.Validate = ValidateRequired;
             else if (c is RangeCtrl)
                 c.Validate = ValidateRange;
             else if (c is RegexCtrl)
                 c.Validate = validateRegex;
             else if (c is CustomCtrl)
                 c.Validate = validateCustom;
         }
         this.cs = cs;
         msgs = new List<string>(cs.Length);
 }