예제 #1
0
        /// <summary>
        /// Gets the error message for the property with the given name.
        /// </summary>
        /// <returns>
        /// The error message for the property. The default is an empty string ("").
        /// </returns>
        /// <param name="columnName">The name of the property whose error message to get. </param>
        /// <remarks>
        /// Used by the view through the IDataErrorInfo interface to validate a field onPropertyChanged
        /// </remarks>
        public override string this[string columnName]
        {
            get
            {
                if (columnName == ManualPropertyName)
                {
                    var propertyCode = this.RowCode + ManualPropertyName;

                    var rule = this.DialogViewModel.ValidationErrors.SingleOrDefault(x => x.PropertyName == propertyCode);
                    if (rule != null)
                    {
                        this.DialogViewModel.ValidationErrors.Remove(rule);
                    }

                    var validationMsg = ParameterValueValidator.Validate(this.Manual, this.ParameterType, this.Scale);
                    if (!string.IsNullOrWhiteSpace(validationMsg))
                    {
                        var validationRule = new ValidationService.ValidationRule
                        {
                            ErrorText    = validationMsg,
                            PropertyName = propertyCode
                        };

                        this.DialogViewModel.ValidationErrors.Add(validationRule);
                        return(validationMsg);
                    }

                    return(validationMsg);
                }

                if (columnName == ReferencePropertyName)
                {
                    var propertyCode = this.RowCode + ReferencePropertyName;

                    var rule = this.DialogViewModel.ValidationErrors.SingleOrDefault(x => x.PropertyName == propertyCode);
                    if (rule != null)
                    {
                        this.DialogViewModel.ValidationErrors.Remove(rule);
                    }

                    var validationMsg = ParameterValueValidator.Validate(this.Reference, this.ParameterType, this.Scale);
                    if (!string.IsNullOrWhiteSpace(validationMsg))
                    {
                        var validationRule = new ValidationService.ValidationRule
                        {
                            ErrorText    = validationMsg,
                            PropertyName = propertyCode
                        };

                        this.DialogViewModel.ValidationErrors.Add(validationRule);
                        return(validationMsg);
                    }

                    return(validationMsg);
                }

                return(string.Empty);
            }
        }
예제 #2
0
        /// <summary>
        /// Gets the error message for the property with the given name.
        /// </summary>
        /// <returns>
        /// The error message for the property. The default is an empty string ("").
        /// </returns>
        /// <param name="columnName">The name of the property whose error message to get. </param>
        public override string this[string columnName]
        {
            get
            {
                if ((columnName == "Password" || columnName == "PasswordConfirmation") && !this.PwdEditIsChecked)
                {
                    var validationErrorToRemove =
                        this.ValidationErrors.SingleOrDefault(
                            x => x.PropertyName == "Password" || x.PropertyName == "PasswordConfirmation");
                    if (validationErrorToRemove != null)
                    {
                        this.ValidationErrors.Remove(validationErrorToRemove);
                    }

                    return(null);
                }

                if (!this.PwdEditIsChecked || columnName != "PasswordConfirmation")
                {
                    return(ValidationService.ValidateProperty(columnName, this));
                }

                if (string.IsNullOrWhiteSpace(this.PasswordConfirmation) || this.PasswordConfirmation != this.Password)
                {
                    var rule = new ValidationService.ValidationRule
                    {
                        PropertyName = "PasswordConfirmation",
                        ErrorText    = "The confirmation is different from the password entered."
                    };

                    if (this.ValidationErrors.All(r => r.PropertyName != "PasswordConfirmation"))
                    {
                        this.ValidationErrors.Add(rule);
                    }

                    return(rule.ErrorText);
                }

                // confirmation ok
                var validationError = this.ValidationErrors.SingleOrDefault(x => x.PropertyName == "PasswordConfirmation");
                if (validationError != null)
                {
                    this.ValidationErrors.Remove(validationError);
                }

                return(ValidationService.ValidateProperty(columnName, this));
            }
        }