//TODO
		public static ValidationResult DateNullCheckRule(int id, int cnt, string target, ValidationRule rule)
		{
			ValidationResult result = new ValidationResult();
			if (isValid(target)) 
			{
				result.Success = (new SimpleDate(target)).isValidDate();
			}
			result.ErrorMessage = "Please specify both To and From dates.";
			return result;
		}
		public static ValidationResult DateRangeRule(int id, int cnt, string target, ValidationRule rule)
		{
			ValidationResult result = new ValidationResult();
			if (isValid(target)) 
			{
				SimpleDate dt0 = new SimpleDate(target);
				SimpleDate dt1 = new SimpleDate(rule.min);
				SimpleDate dt2 = new SimpleDate(rule.max);
				result.Success = dt0.compare(dt1) >= 0 && dt0.compare(dt2) <= 0;
			}
			result.ErrorMessage = "DateRangeRule violation.";
			return result;
		}
Esempio n. 3
0
        public static ValidationResult DateRangeRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValid(target))
            {
                SimpleDate dt0 = new SimpleDate(target);
                SimpleDate dt1 = new SimpleDate(rule.min);
                SimpleDate dt2 = new SimpleDate(rule.max);
                result.Success = dt0.compare(dt1) >= 0 && dt0.compare(dt2) <= 0;
            }
            result.ErrorMessage = "DateRangeRule violation.";
            return(result);
        }
Esempio n. 4
0
        public static ValidationResult MaskCheckRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                char [] valArray  = target.ToCharArray();
                char [] maskArray = rule.mask.ToCharArray();

                int  len     = valArray.Length;
                bool success = len != maskArray.Length;
                if (success)
                {
                    char val;
                    char mask;
                    for (int i = 0; i < len && success; i++)
                    {
                        val  = valArray[i];
                        mask = maskArray[i];

                        switch (mask)
                        {
                        case 'X':
                            // The value must be a number
                            success = char.IsDigit(val);
                            break;

                        case 'A':
                            // the value must be a letter
                            success = char.IsLetter(val);
                            break;

                        default:
                            // these characters must match
                            success = val == mask;
                            break;
                        }
                    }
                }

                result.Success = success;
            }
            result.ErrorMessage = "Please enter this value in the format requested.";
            return(result);
        }
Esempio n. 5
0
        public static ValidationResult PrecisionRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isNumber(target) != 0)
            {
                result.Success = true;
            }

            result.ErrorMessage = "PrecisionRule violation.";
            return(result);
        }
		public static object[] getValidationParams(Attribute attr, ValidationRule rule)
		{
			string valStr = attr.Value[0].ValueLiteral;
			if (valStr == null) 
				valStr = "";

			// Decrement count of value list if value list contains -10.
			int passCount = attr.Value.Count;
			foreach(Value val in attr.Value )
			{
				if( val.ValueID == (int)ValueIds.NONE )
				{
					passCount --;
					break;
				}
			}

			return new object [] {attr.Type, passCount, valStr, rule};
			//return new object [] {attr.Type, attr.Value.Count + attr.SType, valStr, rule};
		}
Esempio n. 7
0
        public static object[] getValidationParams(Attribute attr, ValidationRule rule)
        {
            string valStr = attr.Value[0].ValueLiteral;

            if (valStr == null)
            {
                valStr = "";
            }

            // Decrement count of value list if value list contains -10.
            int passCount = attr.Value.Count;

            foreach (Value val in attr.Value)
            {
                if (val.ValueID == (int)ValueIds.NONE)
                {
                    passCount--;
                    break;
                }
            }

            return(new object [] { attr.Type, passCount, valStr, rule });
            //return new object [] {attr.Type, attr.Value.Count + attr.SType, valStr, rule};
        }
Esempio n. 8
0
        public static ValidationResult PrecisionRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();
            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isNumber(target) != 0)
            {
                result.Success = true;
            }

            result.ErrorMessage = "PrecisionRule violation.";
            return result;
        }
Esempio n. 9
0
        public static ValidationResult RequiredRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();
            result.Success = cnt > 0;
            result.ErrorMessage = "RequiredRule violation.";

            return result;
        }
Esempio n. 10
0
 public static ValidationResult MotorUKValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         result.Success = checkUKVin(target);
     }
     return result;
 }
Esempio n. 11
0
        public static ValidationResult MultiSelectMinNumberValuesRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();
            try
            {
                result.Success = cnt > int.Parse(rule.min);
            }
            catch(Exception)
            {
            }

            result.ErrorMessage = "Please make no fewer than [" + rule.min + "] selections.";
            return result;
        }
Esempio n. 12
0
 public static ValidationResult IntRangeValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         try
         {
             double val = double.Parse(target);
             result.Success = (val >= int.Parse(rule.min)) && (val <= int.Parse(rule.max));
         }
         catch(Exception)
         {
         }
     }
     result.ErrorMessage = "Please enter an value between [" + rule.min + "] and [" + rule.max + "].";
     return result;
 }
Esempio n. 13
0
 public static ValidationResult MaxDoubleValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         try
         {
             result.Success = double.Parse(target) < double.Parse(rule.max);
         }
         catch(Exception)
         {
         }
     }
     result.ErrorMessage = "Please enter a value less than [" + rule.max + "].";
     return result;
 }
Esempio n. 14
0
        public static ValidationResult UrlValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                result.Success = checkUri(target, rule.protocol, rule.invalidhost, rule.invalidhostoverride);
            }
            else
            {
                result.Success = true;
            }
            result.ErrorMessage = "UrlValidationRule violation.";
            return(result);
        }
Esempio n. 15
0
 public static ValidationResult DateValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValid(target))
     {
         int full = rule.full;
         result.Success = checkDate(target, full);
     }
     result.ErrorMessage = "Argument must be a valid date.";
     return result;
 }
Esempio n. 16
0
        public static ValidationResult StringLengthRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id))
            {
                result.Success      = true;            // cnt > 0;
                result.ErrorMessage = "Please select a valid item.";
            }
            else if (isValid(target))
            {
                int len = target.Length;
                result.Success      = (0 < len && len <= rule.length);
                result.ErrorMessage = "Please enter no more than [" + rule.length + "] character(s).";
            }
            else
            {
                result.Success = true;
            }

            return(result);
        }
Esempio n. 17
0
        public static ValidationResult ThousandsSeparatorNotAllowedRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                string separator = rule.separator;
                result.Success = target.IndexOf(separator) == -1;
            }
            result.ErrorMessage = "Please enter a number with no thousands separators.";
            return(result);
        }
Esempio n. 18
0
        //TODO
        public static ValidationResult SimpleRuleSetRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else
            {
                result.Success = true;
            }
            return(result);
        }
Esempio n. 19
0
        public static ValidationResult RegularExpressionValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                Regex           regex = new Regex(rule.regex);
                MatchCollection mc    = regex.Matches(target);
                result.Success = mc.Count > 0;
            }
            result.ErrorMessage = "Please enter this value in the format requested: " + rule.regex;
            return(result);
        }
Esempio n. 20
0
        public static ValidationResult MultiSelectMinNumberValuesRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            try
            {
                result.Success = cnt > int.Parse(rule.min);
            }
            catch (Exception)
            {
            }

            result.ErrorMessage = "Please make no fewer than [" + rule.min + "] selections.";
            return(result);
        }
Esempio n. 21
0
        public static ValidationResult StringLengthRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();
            if (isValidId(id))
            {
                result.Success = true; // cnt > 0;
                result.ErrorMessage = "Please select a valid item.";
            }
            else if (isValid(target))
            {
                int len = target.Length;
                result.Success = (0 < len && len <= rule.length);
                result.ErrorMessage = "Please enter no more than [" + rule.length + "] character(s).";
            }
            else
            {
                result.Success = true;
            }

            return result;
        }
Esempio n. 22
0
        public static ValidationResult VinValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                int year = 1981;                 // TODO!
                result.Success = checkVin(target, year);
            }
            return(result);
        }
Esempio n. 23
0
        public static ValidationResult NumberSeparatorNotAllowedRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                target = target.Trim();
                if (target.StartsWith("-"))
                {
                    target = target.Substring(1, target.Length - 1);
                }
                target = target.Trim();

                char [] ca      = target.ToCharArray();
                int     len     = ca.Length;
                int     i       = 0;
                bool    success = true;
                while (success && i < len)
                {
                    success = char.IsDigit(ca[i]);
                    i++;
                }

                result.Success = success;
            }
            result.ErrorMessage = "Please enter only numeric digits with no symbols.";
            return(result);
        }
Esempio n. 24
0
        //TODO
        public static ValidationResult DateNullCheckRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValid(target))
            {
                result.Success = (new SimpleDate(target)).isValidDate();
            }
            result.ErrorMessage = "Please specify both To and From dates.";
            return(result);
        }
Esempio n. 25
0
 public static ValidationResult DoubleRangeValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         try
         {
             double d = double.Parse(target);
             result.Success = double.Parse(rule.min) <= d && d <= double.Parse(rule.max);
         }
         catch(Exception)
         {
             //Data parsing error
         }
     }
     else
         result.Success = true; // null is okay
     result.ErrorMessage = "Please enter a value between [" + rule.min + "] and [" + rule.max + "].";
     return result;
 }
Esempio n. 26
0
        public static ValidationResult MotorUKValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                result.Success = checkUKVin(target);
            }
            return(result);
        }
Esempio n. 27
0
        public static ValidationResult MaskCheckRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();
            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                char [] valArray = target.ToCharArray();
                char [] maskArray = rule.mask.ToCharArray();

                int len = valArray.Length;
                bool success = len != maskArray.Length;
                if (success)
                {
                    char val;
                    char mask;
                    for(int i=0; i<len && success; i++)
                    {
                        val = valArray[i];
                        mask = maskArray[i];

                        switch(mask)
                        {
                            case 'X':
                                // The value must be a number
                                success = char.IsDigit(val);
                                break;
                            case 'A':
                                // the value must be a letter
                                success = char.IsLetter(val);
                                break;
                            default:
                                // these characters must match
                                success = val == mask;
                                break;
                        }
                    }
                }

                result.Success = success;
            }
            result.ErrorMessage = "Please enter this value in the format requested.";
            return result;
        }
Esempio n. 28
0
        public static ValidationResult MinIntValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                try
                {
                    double val = double.Parse(target);
                    result.Success = val > int.Parse(rule.min);
                }
                catch (Exception)
                {
                }
            }

            result.ErrorMessage = "Please enter an value greater than [" + rule.min + "].";
            return(result);
        }
Esempio n. 29
0
        public static ValidationResult MinIntValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();
            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                try
                {
                    double val = double.Parse(target);
                    result.Success = val > int.Parse(rule.min);
                }
                catch(Exception)
                {
                }
            }

            result.ErrorMessage = "Please enter an value greater than [" + rule.min + "].";
            return result;
        }
Esempio n. 30
0
        public static ValidationResult DateValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValid(target))
            {
                int full = rule.full;
                result.Success = checkDate(target, full);
            }
            result.ErrorMessage = "Argument must be a valid date.";
            return(result);
        }
Esempio n. 31
0
 public static ValidationResult MultiSelectMinMaxNumberValuesRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     result.Success = int.Parse(rule.min) < cnt && cnt < int.Parse(rule.max);
     result.ErrorMessage = "Please make between [" + rule.min + "] and [" + rule.max + "] selections.";
     return result;
 }
Esempio n. 32
0
 public static ValidationResult UrlValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         result.Success = checkUri(target, rule.protocol, rule.invalidhost, rule.invalidhostoverride);
     }
     else
         result.Success = true;
     result.ErrorMessage = "UrlValidationRule violation.";
     return result;
 }
Esempio n. 33
0
        public static ValidationResult NumberSeparatorNotAllowedRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();
            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                target = target.Trim();
                if (target.StartsWith("-"))
                {
                    target = target.Substring(1, target.Length - 1);
                }
                target = target.Trim();

                char [] ca = target.ToCharArray();
                int len = ca.Length;
                int i = 0;
                bool success = true;
                while (success && i < len)
                {
                    success = char.IsDigit(ca[i]);
                    i ++;
                }

                result.Success = success;
            }
            result.ErrorMessage = "Please enter only numeric digits with no symbols.";
            return result;
        }
Esempio n. 34
0
        public static ValidationResult DoubleRangeValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                try
                {
                    double d = double.Parse(target);
                    result.Success = double.Parse(rule.min) <= d && d <= double.Parse(rule.max);
                }
                catch (Exception)
                {
                    //Data parsing error
                }
            }
            else
            {
                result.Success = true;                 // null is okay
            }
            result.ErrorMessage = "Please enter a value between [" + rule.min + "] and [" + rule.max + "].";
            return(result);
        }
Esempio n. 35
0
 public static ValidationResult RegularExpressionValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         Regex regex = new Regex(rule.regex);
         MatchCollection mc = regex.Matches(target);
         result.Success = mc.Count > 0;
     }
     result.ErrorMessage = "Please enter this value in the format requested: " + rule.regex;
     return result;
 }
Esempio n. 36
0
        public static ValidationResult MaxDoubleValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                try
                {
                    result.Success = double.Parse(target) < double.Parse(rule.max);
                }
                catch (Exception)
                {
                }
            }
            result.ErrorMessage = "Please enter a value less than [" + rule.max + "].";
            return(result);
        }
Esempio n. 37
0
 //TODO
 public static ValidationResult SimpleRuleSetRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else
     {
         result.Success = true;
     }
     return result;
 }
Esempio n. 38
0
        public static ValidationResult IntRangeValidationRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            if (isValidId(id) && cnt > 0)
            {
                result.Success = true;
            }
            else if (isValid(target))
            {
                try
                {
                    double val = double.Parse(target);
                    result.Success = (val >= int.Parse(rule.min)) && (val <= int.Parse(rule.max));
                }
                catch (Exception)
                {
                }
            }
            result.ErrorMessage = "Please enter an value between [" + rule.min + "] and [" + rule.max + "].";
            return(result);
        }
Esempio n. 39
0
 public static ValidationResult ThousandsSeparatorNotAllowedRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         string separator = rule.separator;
         result.Success = target.IndexOf(separator) == -1;
     }
     result.ErrorMessage = "Please enter a number with no thousands separators.";
     return result;
 }
Esempio n. 40
0
        public static ValidationResult MultiSelectMinMaxNumberValuesRule(int id, int cnt, string target, ValidationRule rule)
        {
            ValidationResult result = new ValidationResult();

            result.Success      = int.Parse(rule.min) < cnt && cnt < int.Parse(rule.max);
            result.ErrorMessage = "Please make between [" + rule.min + "] and [" + rule.max + "] selections.";
            return(result);
        }
Esempio n. 41
0
 public static ValidationResult VinValidationRule(int id, int cnt, string target, ValidationRule rule)
 {
     ValidationResult result = new ValidationResult();
     if (isValidId(id) && cnt > 0)
     {
         result.Success = true;
     }
     else if (isValid(target))
     {
         int year = 1981; // TODO!
         result.Success = checkVin(target, year);
     }
     return result;
 }
		private IError ValidateAttr(Attribute attr, XmlNode rule)
		{
			ValidationRule v = null;
			ValidationResult result = null;

			try 
			{
				v = new ValidationRule(rule);
				object [] vParams = ValidationParams.getValidationParams(attr, v);
				result = (ValidationResult)SimpleValidator.Validate(v.name, vParams);
			}
			catch(Exception) 
			{
			}

			if (!result.Success) 
			{
				IError err = new Error();
				err.AttrId = attr.attributeID;
				err.RuleName = v.name;
				err.Message = result.ErrorMessage; //SimpleValidator.getErrorMessage(v.name);
				return err;
			}

			return null;
		}