Exemplo n.º 1
0
        /// <summary>
        /// Does validate.
        /// </summary>
        /// <param name="value">Value to validation.</param>
        /// <param name="culture">Culture info.</param>
        /// <param name="context">Cell validation context.</param>
        /// <returns>Validation result.</returns>
        public override ValidationResult Validate(object value,
                                                  CultureInfo culture,
                                                  CellValidationContext context)
        {
            bool isValid = true;

            string             newValue           = value as string;
            IVrpSolver         solver             = App.Current.Solver;
            NetworkDescription networkDescription = solver.NetworkDescription;

            if (newValue != null && networkDescription != null)
            {
                var wrapper = context.DataItem as RestrictionDataWrapper;

                ICollection <NetworkAttribute> networkAttributes = networkDescription.NetworkAttributes;
                foreach (NetworkAttribute attribute in networkAttributes)
                {
                    // If it is current attribute - find parameter to validate.
                    if (wrapper.Restriction.Name.Equals(attribute.Name,
                                                        StringComparison.OrdinalIgnoreCase))
                    {
                        Debug.Assert(null != attribute.Parameters);
                        NetworkAttributeParameter[] parameters = attribute.Parameters.ToArray();

                        int paramIndex = Parameters.GetIndex(context.Cell.FieldName);

                        // If parameter index was found.
                        if (paramIndex != -1)
                        {
                            var parameter = wrapper.Parameters[paramIndex];

                            // Get corresponding network attribute parameter
                            // and check that value can be converted to parameter type.
                            NetworkAttributeParameter param = parameters.FirstOrDefault(
                                x => x.Name == parameter.Name);

                            // If string is not empty or if parameter doesn't accept empty string -
                            // try to convert value.
                            if ((string)value != string.Empty || !param.IsEmptyStringValid)
                            {
                                try
                                {
                                    Convert.ChangeType(value, param.Type); // NOTE: ignore result
                                }
                                catch
                                {
                                    isValid = false;
                                }
                            }
                        }

                        break;
                    }
                }
            }

            return((isValid) ? ValidationResult.ValidResult :
                   new ValidationResult(false, App.Current.FindString("NotValidValueText")));
        }
    public override ValidationResult Validate( object value, CultureInfo culture, CellValidationContext context, FrameworkElement cellEditor )
    {
      bool cellEditorHasError = ( cellEditor == null ) ? false : ( bool )cellEditor.GetValue( CellEditor.HasErrorProperty );

      if( !cellEditorHasError )
        return ValidationResult.ValidResult;

      return new ValidationResult( false, "An invalid or incomplete value was provided." );
    }
    public override ValidationResult Validate( 
      object value, 
      CultureInfo culture, 
      CellValidationContext context )
    {
      if( m_validationRule == null )
        return ValidationResult.ValidResult;

      return m_validationRule.Validate( value, culture );
    }
Exemplo n.º 4
0
        public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context, FrameworkElement cellEditor)
        {
            bool cellEditorHasError = (cellEditor == null) ? false : ( bool )cellEditor.GetValue(CellEditor.HasErrorProperty);

            if (!cellEditorHasError)
            {
                return(ValidationResult.ValidResult);
            }

            return(new ValidationResult(false, "An invalid or incomplete value was provided."));
        }
Exemplo n.º 5
0
        public override ValidationResult Validate(object value, CultureInfo cultureInfo,
                                                  CellValidationContext cellValidationContext)
        {
            string pattern = @"^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$";
            Regex  regEx   = new Regex(pattern);

            if (!regEx.IsMatch((string)value))
            {
                return(new ValidationResult(false, "You entered an invalid email"));
            }
            return(new ValidationResult(true, null));
        }
        public override ValidationResult Validate(
            object value,
            CultureInfo culture,
            CellValidationContext context)
        {
            if (m_validationRule == null)
            {
                return(ValidationResult.ValidResult);
            }

            return(m_validationRule.Validate(value, culture));
        }
        public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
        {
            string val = value as string;

            if (!string.IsNullOrEmpty(val))
            {
                CompareInfo compareInfo = CultureInfo.CurrentCulture.CompareInfo;
                if (compareInfo.IsPrefix(val, "ERROR", CompareOptions.IgnoreCase))
                {
                    return(new ValidationResult(false, val));
                }
            }
            return(new ValidationResult(true, null));
        }
 public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
 {
     if (value == null)
     {
         return(new ValidationResult(true, null));
     }
     string[] sides = { "B", "BMV", "S", "SMV", "BC", "BCMV", "SS", "SSMV", "SSB", "SSBMV" };
     if (sides.Contains(value.ToString().ToUpper()))
     {
         context.Cell.ToolTip = null;
         return(new ValidationResult(true, null));
     }
     context.Cell.ToolTip = "Invalid side";
     return(new ValidationResult(false, "Invalid side"));
 }
    public override ValidationResult Validate( 
      object value,
      CultureInfo culture, 
      CellValidationContext context )
    {
      if( this.Validating != null )
      {
        CellValidatingEventArgs cellValidatingEventArgs = 
          new CellValidatingEventArgs( value, culture, context );

        this.Validating( this, cellValidatingEventArgs );
        return cellValidatingEventArgs.Result;
      }

      return ValidationResult.ValidResult;
    }
        public override ValidationResult Validate(
            object value,
            CultureInfo culture,
            CellValidationContext context)
        {
            if (this.Validating != null)
            {
                CellValidatingEventArgs cellValidatingEventArgs =
                    new CellValidatingEventArgs(value, culture, context);

                this.Validating(this, cellValidatingEventArgs);
                return(cellValidatingEventArgs.Result);
            }

            return(ValidationResult.ValidResult);
        }
Exemplo n.º 11
0
        public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
        {
            // Get the DataItem from the context and cast it to a DataRow
            DataRowView dataRowView = context.DataItem as DataRowView;

            // Convert the value to a long to make sure it is numerical.
            // When the value is not numerical, then an InvalidFormatException will be thrown.
            // We let it pass unhandled to demonstrate that an exception can be thrown when validating
            // and the grid will handle it nicely.
            long id = Convert.ToInt64(value, CultureInfo.CurrentCulture);

            // Try to find another row with the same ID
            System.Data.DataRow[] existingRows = dataRowView.Row.Table.Select(context.Cell.FieldName + "=" + id.ToString(CultureInfo.InvariantCulture));

            // If a row is found, we return an error
            if ((existingRows.Length != 0) && (existingRows[0] != dataRowView.Row))
            {
                return(new ValidationResult(false, "The value must be unique"));
            }

            // If no row was found, we return a ValidResult
            return(ValidationResult.ValidResult);
        }
Exemplo n.º 12
0
 public override sealed ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
 {
     return(this.Validate(value, culture, context, context.Cell.CellEditorBoundControl));
 }
 public abstract ValidationResult Validate(
   object value,
   CultureInfo culture,
   CellValidationContext context,
   FrameworkElement cellEditor );
 public override sealed ValidationResult Validate( object value, CultureInfo culture, CellValidationContext context )
 {
   return this.Validate( value, culture, context, context.Cell.CellEditorBoundControl );
 }
Exemplo n.º 15
0
 public abstract ValidationResult Validate(
   object value,
   CultureInfo culture,
   CellValidationContext context );
Exemplo n.º 16
0
        public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
        {
            ValidationResult result = null;

            // not empty check
            bool isObjectEmpty = true;

            if (null != value)
            {
                isObjectEmpty = string.IsNullOrEmpty(value.ToString().Trim()); // project name cannot consist only in blanks
            }
            if (isObjectEmpty)
            {
                result = new ValidationResult(false, (string)Application.Current.FindResource("ProjectNameValidationRuleIncorrectNameError"));
            }

            if (null == result)
            {
                string name = value.ToString().Trim();
                if (-1 != name.IndexOfAny(new char[] { '\\', '/', '*', ';', ',', ':', '|', '"' }))
                {
                    result = new ValidationResult(false, (string)Application.Current.FindResource("ProjectNameValidationRuleIncorrectNameError"));
                }
                else
                {
                    ProjectsPage       projectsPage = (ProjectsPage)App.Current.MainWindow.GetPage(PagePaths.ProjectsPagePath);
                    ProjectDataWrapper currentItem  = (ProjectDataWrapper)projectsPage.XceedGrid.CurrentItem;

                    // check duplicate
                    ItemCollection wrappedCollection = projectsPage.XceedGrid.Items;
                    foreach (ProjectDataWrapper wrapper in wrappedCollection)
                    {
                        if (name.Equals(wrapper.Name, StringComparison.InvariantCultureIgnoreCase) && (wrapper != currentItem))
                        {
                            result = new ValidationResult(false, (string)App.Current.FindResource("ProjectNameValidationRuleDuplicateNameError"));
                            break; // NOTE: exit - error founded
                        }
                    }

                    if (null == result)
                    {                                                                 // normal length check
                        string fileName = name + ProjectConfiguration.FILE_EXTENSION; // NOTE: check only one file name,
                        // but real created two files: ProjectConfiguration.FILE_EXTENSION and DatabaseEngine.DATABASE_EXTENSION
                        string filePath = null;
                        try
                        {
                            filePath = _GetDatabaseAbsolutPath(App.Current.ProjectCatalog.FolderPath, fileName);
                        }
                        catch
                        {
                        }

                        // valid name check
                        if (!FileHelpers.IsFileNameCorrect(filePath) || !FileHelpers.ValidateFilepath(filePath))
                        {
                            result = new ValidationResult(false, (string)Application.Current.FindResource("ProjectNameValidationRuleIncorrectNameError"));
                        }
                    }
                }
            }

            return((null == result)? ValidationResult.ValidResult : result);
        }
Exemplo n.º 17
0
        public override ValidationResult Validate(object value, CultureInfo culture, CellValidationContext context)
        {
            // not empty check
            bool isObjectEmpty = true;

            if (null != value)
            {
                isObjectEmpty = string.IsNullOrEmpty(value.ToString().Trim());
            }
            if (isObjectEmpty)
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateEmptyName")));
            }

            // unique name check
            string name = value.ToString();

            if (!string.IsNullOrEmpty(ReportDataWrapper.StartTemplateName))
            {
                if (0 == string.Compare(ReportDataWrapper.StartTemplateName, name, true))
                {
                    return(ValidationResult.ValidResult);
                }
            }

            ReportsGenerator     generator      = App.Current.ReportGenerator;
            ICollection <string> presentedNames = generator.GetPresentedNames(true);

            foreach (string nameTemplate in presentedNames)
            {
                if (0 == string.Compare(nameTemplate, name, true))
                {
                    return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateNotUniqueName")));
                }
            }

            // normal length check
            bool   isLong       = false;
            string templatePath = ReportsGenerator.GetNewTemplatePath(name, ReportDataWrapper.StartTemplatePath);
            string fileName     = null;

            try
            {
                fileName = ReportsGenerator.GetTemplateAbsolutelyPath(templatePath);
                new FileInfo(fileName);
            }
            catch (PathTooLongException)
            {
                isLong = true;
            }
            catch (Exception)
            {
            }

            if (isLong)
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateLongName")));
            }

            // valid name check
            if (!FileHelpers.ValidateFilepath(fileName))
            {
                return(new ValidationResult(false, (string)Application.Current.FindResource("ReportTemplateInvalidName")));
            }

            return(ValidationResult.ValidResult);
        }
Exemplo n.º 18
0
 public abstract ValidationResult Validate(
     object value,
     CultureInfo culture,
     CellValidationContext context);
Exemplo n.º 19
0
 public abstract ValidationResult Validate(
     object value,
     CultureInfo culture,
     CellValidationContext context,
     FrameworkElement cellEditor);