private void adminUpdateRecipe_Click(object sender, EventArgs e) { DataRowView drv = (DataRowView)adminRecipeBox1.SelectedItem; // string food = drv["name"].ToString(); string id = drv["recipeid"].ToString(); int index = adminRecipeBox1.SelectedIndex; if (index > -1 && adminRecipeName.Text.Length > 0) { if (adminRecipeName.Text.Length == 0) { MessageBox.Show("Error: Recipe needs a name"); } else if (adminRecipeDesc.Text.Length == 0) { MessageBox.Show("Error: Recipe needs a description"); } else if (adminRecipeIns.Text.Length == 0) { MessageBox.Show("Error: Recipe needs instructions"); } else if (adminRecipeItems.Items.Count == 0) { MessageBox.Show("Error: Recipe needs ingredients"); } else { RecipeMaker p = new RecipeMaker(adminRecipeName.Text, adminRecipeDesc.Text, adminRecipeIns.Text); foreach (string foods in adminRecipeItems.Items) { Food foodInfo = searchLocalDB(foods); p.addIngredient(foodInfo); } d.UpdateRecipe(p.getRecipe(), id); adminRecipeBox1.DataSource = d.getRecipeList(); recipes = d.GetRecipeList(); adminRecipeName.Clear(); adminRecipeDesc.Clear(); adminRecipeIns.Clear(); adminRecipeItems.Items.Clear(); } } }
private void saveNewRecipeButton_Click(object sender, EventArgs e) { if (newRecipeName.Text.Length == 0) { MessageBox.Show("Error: Recipe needs a name"); } else if (newRecipeDesc.Text.Length == 0) { MessageBox.Show("Error: Recipe needs a description"); } else if (newRecipeIns.Text.Length == 0) { MessageBox.Show("Error: Recipe needs instructions"); } else if (newRecipeList.Items.Count == 0) { MessageBox.Show("Error: Recipe needs ingredients"); } else { RecipeMaker p = new RecipeMaker(newRecipeName.Text, newRecipeDesc.Text, newRecipeIns.Text); foreach (string food in newRecipeList.Items) { Food foodInfo = searchLocalDB(food); p.addIngredient(foodInfo); } d.InsertRecipe(username, p.getRecipe().name, p.getRecipe().description, p.getRecipe().instructions, p.getRecipe().ingredients); newRecipeName.Clear(); newRecipeDesc.Clear(); newRecipeIns.Clear(); newRecipeList.Items.Clear(); recipes = d.GetRecipeList(); recipeDropDown.DataSource = d.getRecipeList(); if (Program.debugMode) { MessageBox.Show("Saved " + p.getRecipe().name + " to the database"); } } }