private void btnUpdateIngre_Click(object sender, EventArgs e) { IngredientDAO dao = new IngredientDAO(); string name = txtIngredient.Text; int id = dao.GetIngredientIDByName(name); string amount = txtIngredientAmount.Text; string note = txtNote.Text; if (id > 0) { if (string.IsNullOrWhiteSpace(amount)) { errProvider.SetError(txtIngredientAmount, "Amount must not be blank."); } else { RecipeIngredient ingredient = new RecipeIngredient(id, amount, note); for (int i = 0; i < recipeIngredients.Count; i++) { if (recipeIngredients[i].Equals(ingredient)) { recipeIngredients[i] = ingredient; break; } } LoadAllIngredients(); //clear ingredient field only } } else { MessageBox.Show("Invalid ingredient"); } }
private void btnDeleteIngre_Click(object sender, EventArgs e) { IngredientDAO dao = new IngredientDAO(); string name = txtIngredient.Text; int id = dao.GetIngredientIDByName(name); if (id > 0) { RecipeIngredient ingredient = new RecipeIngredient(id, null, null); for (int i = 0; i < recipeIngredients.Count; i++) { if (recipeIngredients[i].Equals(ingredient)) { recipeIngredients.RemoveAt(i); break; } } LoadAllIngredients(); //clear ingredient field only } else { MessageBox.Show("Invalid ingredient"); } }
private void btnAddIngre_Click(object sender, EventArgs e) { IngredientDAO dao = new IngredientDAO(); string name = txtIngredient.Text; int id = dao.GetIngredientIDByName(name); string amount = txtIngredientAmount.Text; string note = txtNote.Text; if (id > 0) { if (string.IsNullOrWhiteSpace(amount)) { errProvider.SetError(txtIngredientAmount, "Amount must not be blank."); } else { errProvider.SetError(txtIngredientAmount, ""); RecipeIngredient ingredient = new RecipeIngredient(id, amount, note); if (recipeIngredients.Contains(ingredient)) { //Neu trong list da co ingredient roi thi chi duoc update hoac delete MessageBox.Show(name + " has already existed. You can only update or delete it"); } else { recipeIngredients.Add(ingredient); LoadAllIngredients(); //clear ingredient field only } } } else { MessageBox.Show("Invalid ingredient"); } }