Ejemplo n.º 1
0
        public override string FormatErrorMessage(string name)
        {
            List <string> par1, par2;
            string        min = null, max = null;
            IComparable   cmin = _lastModel != null?GetGlobalMinimum(_lastModel, out par1, out par2) as IComparable ?? Minimum : Minimum;

            IComparable cmax = _lastModel != null?GetGlobalMaximum(_lastModel, out par1, out par2) as IComparable ?? Maximum : Maximum;

            cmin = (cmin != null && TargetType == typeof(Week)) ? ((Week)cmin).StartDate() : cmin;
            cmax = (cmax != null && TargetType == typeof(Week)) ? ((Week)cmax).StartDate() : cmax;
            cmin = (cmin != null && TargetType == typeof(Month)) ? ((Month)cmin).ToDateTime() : cmin;
            cmax = (cmax != null && TargetType == typeof(Month)) ? ((Month)cmax).ToDateTime() : cmax;
            if (cmin != null)
            {
                IFormattable fmin = cmin as IFormattable;
                if (fmin != null && MaxMinDisplayFormat != null)
                {
                    min = fmin.ToString(MaxMinDisplayFormat, CultureInfo.CurrentCulture);
                }
                else
                {
                    min = cmin.ToString();
                }
            }
            if (cmax != null)
            {
                IFormattable fmax = cmax as IFormattable;
                if (fmax != null && MaxMinDisplayFormat != null)
                {
                    max = fmax.ToString(MaxMinDisplayFormat, CultureInfo.CurrentCulture);
                }
                else
                {
                    max = cmax.ToString();
                }
            }
            string[] messages = ErrorMessageString.Split(new char[] { '|' }, StringSplitOptions.None);
            string   message;

            if (cmin != null && cmax != null)
            {
                message = messages[0];
            }
            else if (cmin != null)
            {
                message = messages[Math.Min(messages.Length - 1, 1)];
            }
            else if (cmax != null)
            {
                message = messages[Math.Min(messages.Length - 1, 2)];
            }
            else
            {
                message = messages[Math.Min(messages.Length - 1, 3)];
            }
            return(string.Format(message, name, min ?? string.Empty, max ?? string.Empty));
        }
Ejemplo n.º 2
0
        public override string FormatErrorMessage(string name)
        {
            //if (ErrorMessageResourceType != null)
            //{
            //    ResourceManager rm =new ResourceManager(ErrorMessageResourceType);

            //    return rm.GetString(ErrorMessageString).Replace("{0}", name).Replace("{1}", _maxFileSize.ToString());
            //}

            return(ErrorMessageString.Replace("{0}", name).Replace("{1}", _maxFileSize.ToString()));
        }
 protected override ValidationResult IsValid(object value, ValidationContext validationContext)
 {
     if (value == null)
     {
         string errorMessage = null;
         if (ErrorMessageString.Contains(":"))
         {
             string[] tokens = ErrorMessageString.Split(':');
             errorMessage = LocalizedAttributeHelper.GetMessageFromResource(tokens[0], tokens[1], "VALIDATION");
         }
         return(new ValidationResult(errorMessage));
     }
     return(ValidationResult.Success);
 }
Ejemplo n.º 4
0
 public override string FormatErrorMessage(string name)
 {
     return(ErrorMessageString.Replace("{0}", name));
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Applies formatting to an error message, based on the data field where the error occurred.
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override string FormatErrorMessage(string name)
        {
            var displayVals = Values.Convert(typeof(string));

            return(ErrorMessageString.Fmt(name, displayVals.Join(", ")));
        }
Ejemplo n.º 6
0
 public override string FormatErrorMessage(string name)
 {
     return(String.Format(ErrorMessageString.T(), name, OtherPropertyDisplayName ?? OtherProperty));
 }