//meny public Menu AddRecipeToMenu(string username, Recipe recipe, string weekNumber, string weekDay, string plannedQuantity) { return dal.AddRecipeToMenu(username, recipe, weekNumber, weekDay, plannedQuantity); }
// sparar ett recept till databasen, finns inte recepted - skapas det private void SaveRecipe(object sender, EventArgs e) { currentRecipe = null; string name = textBoxAddRecipeId.Text, cookingTime = comboBoxAddCookingTime.Text, category = comboBoxAddCategory.SelectedItem.ToString(), instructions = textBoxInstructions.Text, servings = comboBoxAddServings.Text; try { Controller.SaveRecipe(ingredients, name, cookingTime, category, instructions, servings, fileNewPath); ClearRecipeFields(); } catch (ArgumentException) { MessageBox.Show(Controller.ErrorMessage); } Search(); AutoComplete(); Controller.ShowAdminRecipe(listBoxAdminAllRecipe); Controller.ShowAdminIngredients(listBoxAdminAllIngredients); }
// "öppnar" ett recept samt tillhörande ingredienser private void ShowRecipe(object sender, EventArgs e) { if (listBoxSearch.SelectedItem != null) { Controller.ChangeComponentVisibility(true, comboBoxRecipeServings, labelIngredientRecipe, labelInstructionsRecipe, labelSearchServings, pictureBoxClock, buttonAddRecipeToMenu, panelSearchTab, comboBoxMenuDay, labelRecipeName, labelRecipeTime, labelRecipeCategory); currentRecipe = Controller.Recipe(listBoxSearch.SelectedItem.ToString()); labelRecipeName.Text = currentRecipe.recipeName; labelRecipeTime.Text = string.Format("{0} minuter", currentRecipe.cookingTime); labelRecipeCategory.Text = "Kategori: " + currentRecipe.category; textBoxRecipeInstructions.Text = currentRecipe.instructions; comboBoxRecipeServings.SelectedItem = currentRecipe.servings.ToString(); try { if (currentRecipe.filePath != null) pictureBoxRecipePicture.Image = Image.FromFile(currentRecipe.filePath); else pictureBoxRecipePicture.Image = null; } catch (FileNotFoundException) { pictureBoxRecipePicture.Image = null; } List<IngredientRecipe> iList = Controller.IngredientRecipe(currentRecipe.recipeName); listBoxRecipeIngredients.Items.Clear(); foreach (IngredientRecipe ir in iList) { Ingredient ing = ir.Ingredient; if (ing != null) listBoxRecipeIngredients.Items.Add(string.Format("{0}, ({1} {2})", ing.ingredientName, ir.amount, ir.unit)); } } }
private void ClearSearchResults() { currentRecipe = null; pictureBoxRecipePicture.Image = null; Controller.Clear(listBoxRecipeIngredients, textBoxRecipeInstructions, textBoxSearch, listBoxSearch); Controller.ChangeComponentVisibility(false, comboBoxRecipeServings, labelIngredientRecipe, labelInstructionsRecipe, labelSearchServings, pictureBoxClock, buttonAddRecipeToMenu, panelSearchTab, comboBoxMenuDay, labelRecipeName, labelRecipeTime, labelRecipeCategory); Search(); }