private void BtnAddNewRecipe_Click(object sender, RoutedEventArgs e) { if (!String.IsNullOrWhiteSpace(TxtBoxRecipeName.Text)) { if (!String.IsNullOrWhiteSpace(TxtBoxCountOfPersonsInRecipe.Text)) { if (ingredientsInNewRecipe.Count != 0) { try { Recipe newRecipe = new Recipe(TxtBoxRecipeName.Text, ingredientsInNewRecipe, int.Parse(TxtBoxCountOfPersonsInRecipe.Text)); dbHandler.NewRecipe(newRecipe); MessageBox.Show("Opskriften blev tilføjet!", "Success!"); TxtBoxRecipeName.Clear(); ingredientsInNewRecipe.Clear(); TxtBoxCountOfPersonsInRecipe.Clear(); listOfAvailableIngredients = dbHandler.GetAllIngredients(); UpdateDataInNewRecipe(); UpdateRecipeList(); } catch (Exception ex) { MessageBox.Show($"Der opstod en fejl! \n{ex.Message}", "Fejl"); } } else { MessageBox.Show("Du kan ikke oprette en opskrift uden nogle ingredienser!", "Fejl!"); } } else { MessageBox.Show("Du skal angive hvor mange personer opskriften er til!", "Fejl!"); } } else { MessageBox.Show("Du skal give opskriften et navn!", "Fejl!"); } //Update Opskrifter fanens data med den nye opskrift //Clear alle felter i Ny opskrift fanen //Tjek om input er null osv }
private void BtnAddNewRecipe_Click(object sender, RoutedEventArgs e) { try { string newRecipeName = TxtBoxRecipeName.Text; int newRecipePersons = int.Parse(TxtBoxCountOfPersonsInRecipe.Text); Recipe newRecipe = new Recipe(newRecipeName, ingredientsInNewRecipe, newRecipePersons); handler.InsertRecipe(newRecipe); ingredientsInNewRecipe.Clear(); DtgItemsInNewRecipe.Items.Refresh(); TxtBoxCountOfPersonsInRecipe.Clear(); TxtBoxRecipeName.Clear(); LblTotalPrice.Content = CalculatePrice(ingredientsInNewRecipe); UpdateSources(); } catch (Exception ex) { MessageBox.Show($"An error has occured.{Environment.NewLine}{Environment.NewLine}{ex.Message}"); } }