protected override void ProcessValidation()
        {
            OverallValidity = true;

            for (int i = 0; i < Vessels.Count; i++)
            {
                bool validSide = false;
                foreach (HullRace race in HullRaces)
                {
                    if (Vessels[i].Side == race.ID)
                    {
                        validSide = true;
                        break;
                    }
                }
                if (!validSide)
                {
                    ValidationObjectCollection val = new ValidationObjectCollection();
                    foreach (ValidationObject vO in Vessels[i].ValidationCollection)
                    {
                        val.Add(vO);
                    }
                    val.AddValidation("Side", ValidationValue.IsError, Properties.Resources.VesselSideInvalid);

                    OverallValidity = false;
                    Vessels[i].ValidationCollection = val;
                }
            }
        }
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>
        /// A converted value. If the method returns null, the valid null value is used.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //Parameter contains name of property to return validation on.
            //Value must be the ValidationObjectCollection.
            ValidationObject           retVal = null;
            ValidationObjectCollection val    = value as ValidationObjectCollection;

            if (val != null && parameter != null)
            {
                retVal = val.GetValidationResult(parameter.ToString());
            }
            return(retVal);
        }
Пример #3
0
        //static readonly ILog _log = LogManager.GetLogger(typeof(ValidationToBrush));
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString()); }
        //if (_log.IsDebugEnabled) { _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString()); }

        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            //parameter = "propertyMatch|Color If success|Color if Warning|Color if Error
            Brush retVal = null;
            ValidationObjectCollection validation = null;

            if (value != null)
            {
                validation = value as ValidationObjectCollection;

                if (parameter != null)
                {
                    string[]         parms          = parameter.ToString().Split('|');
                    string           key            = parms[0];
                    ValidationObject val            = validation.GetValidationResult(key);
                    string           colorOnSuccess = parms[1];
                    string           colorOnWarn    = parms[2];
                    string           colorOnError   = parms[3];
                    BrushConverter   cnv            = new BrushConverter();
                    switch (val.Code)
                    {
                    case ValidationValue.IsValid:
                        retVal = cnv.ConvertFromInvariantString(colorOnSuccess) as Brush;
                        break;

                    case ValidationValue.IsWarnState:
                        retVal = cnv.ConvertFromInvariantString(colorOnWarn) as Brush;
                        break;

                    case ValidationValue.IsError:
                        retVal = cnv.ConvertFromInvariantString(colorOnError) as Brush;
                        break;
                    }
                }
            }
            return(retVal);
        }