Ejemplo n.º 1
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (validationContext.Items.Count > 0)
            {
                var Model = validationContext.Items["Model"];

                if (ValidateTypeHander.IsValidate(Groups, Model))
                {
                    if (value == null || System.Convert.ToString(value).Equals(""))
                    {
                        string tips = string.Empty;
                        if (!string.IsNullOrEmpty(ErrorMessage))
                        {
                            Message = ErrorMessage;
                        }
                        if (!string.IsNullOrEmpty(Message))
                        {
                            tips = Message;
                        }
                        else if (!string.IsNullOrEmpty(MessageKey))
                        {
                            tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                        }
                        return(new ValidationResult(tips));
                    }
                }
            }
            return(ValidationResult.Success);
        }
Ejemplo n.º 2
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (validationContext.Items.Count > 0)
            {
                var Model = validationContext.Items["Model"];

                if (ValidateTypeHander.IsValidate(Groups, Model))
                {
                    string tips = string.Empty;
                    if (Minimum.GetType() == typeof(int))
                    {
                        var v   = Convert.ToInt32(value);
                        var min = Convert.ToInt32(Minimum);
                        var max = Convert.ToInt32(Maximum);

                        if (v < min || v > max)
                        {
                            if (!string.IsNullOrEmpty(ErrorMessage))
                            {
                                Message = ErrorMessage;
                            }
                            if (!string.IsNullOrEmpty(Message))
                            {
                                tips = Message;
                            }
                            else if (!string.IsNullOrEmpty(MessageKey))
                            {
                                tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                            }
                            return(new ValidationResult(tips));
                        }
                    }
                    else if (Minimum.GetType() == typeof(double))
                    {
                        var v   = Convert.ToDouble(value);
                        var min = Convert.ToDouble(Minimum);
                        var max = Convert.ToDouble(Maximum);

                        if (v < min || v > max)
                        {
                            if (!string.IsNullOrEmpty(ErrorMessage))
                            {
                                Message = ErrorMessage;
                            }
                            if (!string.IsNullOrEmpty(Message))
                            {
                                tips = Message;
                            }
                            else if (!string.IsNullOrEmpty(MessageKey))
                            {
                                tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                            }
                            return(new ValidationResult(tips));
                        }
                    }
                }
            }

            return(ValidationResult.Success);
        }
Ejemplo n.º 3
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            if (validationContext.Items.Count > 0)
            {
                var Model = validationContext.Items["Model"];

                if (ValidateTypeHander.IsValidate(Groups, Model))
                {
                    string tips = string.Empty;

                    var otherProperty      = validationContext.ObjectInstance.GetType().GetProperty(OtherProperty);
                    var otherPropertyValue = otherProperty.GetValue(validationContext.ObjectInstance, null);

                    if (value == null && otherPropertyValue == null)
                    {
                        return(ValidationResult.Success);
                    }
                    if (value == null && otherPropertyValue != null)
                    {
                        if (!string.IsNullOrEmpty(ErrorMessage))
                        {
                            Message = ErrorMessage;
                        }
                        if (!string.IsNullOrEmpty(Message))
                        {
                            tips = Message;
                        }
                        else if (!string.IsNullOrEmpty(MessageKey))
                        {
                            tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                        }
                        return(new ValidationResult(tips));
                    }
                    if (value != null && otherPropertyValue == null)
                    {
                        if (!string.IsNullOrEmpty(ErrorMessage))
                        {
                            Message = ErrorMessage;
                        }
                        if (!string.IsNullOrEmpty(Message))
                        {
                            tips = Message;
                        }
                        else if (!string.IsNullOrEmpty(MessageKey))
                        {
                            tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                        }
                        return(new ValidationResult(tips));
                    }

                    if (value.GetType() == typeof(string))
                    {
                        string v = value.ToString();
                        if (!v.Equals(otherPropertyValue.ToString()))
                        {
                            if (!string.IsNullOrEmpty(ErrorMessage))
                            {
                                Message = ErrorMessage;
                            }
                            if (!string.IsNullOrEmpty(Message))
                            {
                                tips = Message;
                            }
                            else if (!string.IsNullOrEmpty(MessageKey))
                            {
                                tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                            }
                            return(new ValidationResult(tips));
                        }
                    }
                    else if (value.GetType() == typeof(int))
                    {
                        int v = Convert.ToInt32(value);
                        if (v != Convert.ToInt32(otherPropertyValue))
                        {
                            if (!string.IsNullOrEmpty(ErrorMessage))
                            {
                                Message = ErrorMessage;
                            }
                            if (!string.IsNullOrEmpty(Message))
                            {
                                tips = Message;
                            }
                            else if (!string.IsNullOrEmpty(MessageKey))
                            {
                                tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                            }
                            return(new ValidationResult(tips));
                        }
                    }
                    else if (value.GetType() == typeof(double))
                    {
                        double v = Convert.ToDouble(value);
                        if (v != Convert.ToDouble(otherPropertyValue))
                        {
                            if (!string.IsNullOrEmpty(ErrorMessage))
                            {
                                Message = ErrorMessage;
                            }
                            if (!string.IsNullOrEmpty(Message))
                            {
                                tips = Message;
                            }
                            else if (!string.IsNullOrEmpty(MessageKey))
                            {
                                tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                            }
                            return(new ValidationResult(tips));
                        }
                    }
                    else if (value.GetType() == typeof(DateTime))
                    {
                        DateTime v = Convert.ToDateTime(value);
                        if (v != Convert.ToDateTime(otherPropertyValue))
                        {
                            if (!string.IsNullOrEmpty(ErrorMessage))
                            {
                                Message = ErrorMessage;
                            }
                            if (!string.IsNullOrEmpty(Message))
                            {
                                tips = Message;
                            }
                            else if (!string.IsNullOrEmpty(MessageKey))
                            {
                                tips = XMLConfiguartionService.GetXmlConfig(MessageKey);
                            }
                            return(new ValidationResult(tips));
                        }
                    }
                }
            }
            return(ValidationResult.Success);
        }