private void Save_Click(object sender, RoutedEventArgs e) { // Validate favorite name. if (Favorite.IsTitleInvalid(MyTitle.Text)) { var errorWindow = DialogWindow.ErrorWindow($"Please enter a valid name for this favorite set."); errorWindow.Owner = this; errorWindow.ShowDialog(); MyTitle.Focus(); MyTitle.SelectAll(); return; } // Check if favorite title already exists. if (Favorite.TitleExists(MyTitle.Text)) { var warningWindow = DialogWindow.WarningWindow( message: $"{MyTitle.Text} already exists. Would you like to overwrite?", confirmButtonText: "Overwrite"); warningWindow.Owner = this; if (warningWindow.ShowDialog() == true) { // User opted to overwrite existing favorite entry. SaveFavorite(); } } else { // Checks passed. Saving. SaveFavorite(); } }
private void Save_Click(object sender, RoutedEventArgs e) { // Validate favorite name. if (Favorite.IsTitleInvalid(MyTitle.Text)) { var errorWindow = DialogWindow.ErrorWindow(Strings.NewFavorite_Error_InvalidName); errorWindow.Owner = this; errorWindow.ShowDialog(); MyTitle.Focus(); MyTitle.SelectAll(); return; } // Check if favorite title already exists. if (Favorite.TitleExists(MyTitle.Text)) { var warningWindow = DialogWindow.WarningWindow( message: $"{MyTitle.Text} {Strings.NewFavorite_Warn_AlreadyExists}", confirmButtonText: Strings.DialogButton_Overwrite); warningWindow.Owner = this; if (warningWindow.ShowDialog() == true) { // User opted to overwrite existing favorite entry. SaveFavorite(); } } else { // Checks passed. Saving. SaveFavorite(); } }
private void Save_Click(object sender, RoutedEventArgs e) { // Validate column count. if (int.TryParse(MyColumnCount.Text, out ColumnCount) == false || ColumnCount < 1 || ColumnCount > 10) { var errorWindow = DialogWindow.ErrorWindow("Please enter a valid number of columns (between 1 and 10)."); errorWindow.Owner = this; errorWindow.ShowDialog(); MyColumnCount.Focus(); MyColumnCount.SelectAll(); return; } // Validate favorite name. if (Favorite.IsTitleInvalid(MyTitle.Text)) { var errorWindow = DialogWindow.ErrorWindow(Strings.NewFavorite_Error_InvalidName); errorWindow.Owner = this; errorWindow.ShowDialog(); MyTitle.Focus(); MyTitle.SelectAll(); return; } // Split MyHosts string to array, trim each item, then convert to list. Ensure at least one host was entered. HostList = MyHosts.Text.Trim().Split(new char[] { ',', '\n' }).Select(host => host.Trim()).ToList(); if (HostList.All(x => string.IsNullOrWhiteSpace(x))) { var errorWindow = DialogWindow.ErrorWindow("You have not entered any hosts. Provide at least one host for this favorite set."); errorWindow.Owner = this; errorWindow.ShowDialog(); MyHosts.Focus(); MyHosts.SelectAll(); return; } // If creating a new favorite: Check and display warning if title already exists. // If editing a favorite and title has changed: Check and display warning if title already exists. // If editing a favorite and title has not changed: Proceed with save. No warning displayed. if ((!IsExisting && Favorite.TitleExists(MyTitle.Text)) || (IsExisting && !string.Equals(OriginalTitle, MyTitle.Text) && Favorite.TitleExists(MyTitle.Text))) { var warningWindow = DialogWindow.WarningWindow( message: $"{MyTitle.Text} {Strings.NewFavorite_Warn_AlreadyExists}", confirmButtonText: Strings.DialogButton_Overwrite); warningWindow.Owner = this; if (warningWindow.ShowDialog() == true) { // User opted to overwrite existing favorite entry. SaveFavorite(); } } else { // Checks passed. Saving. SaveFavorite(); } }
private void Save_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrWhiteSpace(MyTitle.Text)) { var dialogWindow = new DialogWindow( DialogWindow.DialogIcon.Warning, "Error", $"Please enter a valid name for this favorite set.", "OK", false); dialogWindow.Owner = this; dialogWindow.ShowDialog(); MyTitle.Focus(); MyTitle.SelectAll(); return; } if (Favorite.DoesTitleExist(MyTitle.Text)) { var dialogWindow = new DialogWindow( DialogWindow.DialogIcon.Warning, "Warning", $"{MyTitle.Text} already exists. Would you like to overwrite?", "Overwrite", true); dialogWindow.Owner = this; if (dialogWindow.ShowDialog() == true) { Favorite.SaveFavoriteSet(MyTitle.Text, HostList, ColumnCount); DialogResult = true; } } else { Favorite.SaveFavoriteSet(MyTitle.Text, HostList, ColumnCount); DialogResult = true; } }