/////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////// private void App_ApplicationInitialized(object sender, EventArgs e) { App.Current.ProjectLoaded += new EventHandler(_ProjectLoaded); App.Current.ProjectClosing += new EventHandler(_ProjectClosing); _projectsPage = (ProjectsPage)_Application.MainWindow.GetPage(PagePaths.ProjectsPagePath); _projectsPage.XceedGrid.SelectionChanged += new Xceed.Wpf.DataGrid.DataGridSelectionChangedEventHandler(XceedGrid_SelectionChanged); _UpdateState(); }
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); }