//Check if data looks okay one last time and Finalize the Output private void FinalizeRecipe_Button_Click(object sender, RoutedEventArgs e) { CheckIfButtonCanBePressed(); // Check if user is attempting to save a file with a similiar name and prevent it List <Recipes> ListofRecipes = MainWindow.UpdateObjectsFromFiles(); foreach (var item in ListofRecipes) { if (item.RecipeName == RecipeName_TextBox.Text && IsThisAnEdit == false) { FinalizeRecipe_Button.IsEnabled = false; InformUserOfName informUserOfName = new InformUserOfName(); informUserOfName.Owner = this; informUserOfName.WindowStartupLocation = WindowStartupLocation.Manual; informUserOfName.Top = this.Top + 120; informUserOfName.Left = this.Left + 30; System.Media.SystemSounds.Hand.Play(); informUserOfName.ShowDialog(); RecipeName_TextBox.Text = ""; } } // Check if button is still enabled if (FinalizeRecipe_Button.IsEnabled == true) { if (IsThisAnEdit) { System.IO.File.Delete(OldRecipePath); } Recipes recipe = new Recipes(RecipeCategory_ComboBox.SelectedItem.ToString(), RecipeName_TextBox.Text, new TextRange(Directions_RichTextBox.Document.ContentStart, Directions_RichTextBox.Document.ContentEnd).Text.ToString(), ParseListInfo(EnterNewRecipe_IngredientListView), Int16.Parse(RecipeDifficulty_ComboBox.Text.ToString()), IsFavorite_Checkbox.IsChecked == true); this.Close(); Recipe_JsonHandler.WriteToJsonFile(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Recipe Rack\\Recipes\\" + recipe.RecipeName.Trim() + ".json", recipe); } }
//Check if data looks okay one last time and Finalize the Output private void FinalizeRecipe_Button_Click(object sender, RoutedEventArgs e) { CheckIfButtonCanBePressed(); // Check if user is attempting to save a recipe with a similiar name and prevent it List <Recipe> ListofRecipes = SqliteDataAccess.LoadAllRecipes(); foreach (var item in ListofRecipes) { if (item.RecipeName == RecipeName_TextBox.Text && IsThisAnEdit == false) { FinalizeRecipe_Button.IsEnabled = false; InformUserOfName informUserOfName = new InformUserOfName(); informUserOfName.Owner = this; informUserOfName.WindowStartupLocation = WindowStartupLocation.Manual; informUserOfName.Top = this.Top + 120; informUserOfName.Left = this.Left + 30; System.Media.SystemSounds.Hand.Play(); informUserOfName.ShowDialog(); RecipeName_TextBox.Text = ""; } } // Check if button is still enabled, If it is write the Recipe to the SQLite DB. if (FinalizeRecipe_Button.IsEnabled == true) { if (IsThisAnEdit) { SqliteDataAccess.DeleteRecipe(OldRecipeName); } Recipe recipe = new Recipe(RecipeCategory_ComboBox.SelectedItem.ToString(), RecipeName_TextBox.Text, new TextRange(Directions_RichTextBox.Document.ContentStart, Directions_RichTextBox.Document.ContentEnd).Text.ToString(), ConvertListToString(ParseListInfo(EnterNewRecipe_IngredientListView)), Int16.Parse(RecipeDifficulty_ComboBox.Text.ToString()), ConvertBoolToInt(IsFavorite_Checkbox.IsChecked.Value)); this.Close(); SqliteDataAccess.SaveRecipe(recipe); } }