/// <summary> /// Method wich works when the user press on add ingredient button /// </summary> private void btnAddIngredientsToDish_Click(object sender, EventArgs e) { if (cbIngredientName.SelectedItem == null)//check if user choose ingredint { MessageBox.Show("לא נבחר מרכיב להוספה !!"); } else { if (IsIngredientAllreadyInList(ingredients[cbIngredientName.SelectedIndex].ID)) { MessageBox.Show("מרכיב זה כבר נמצא במנה !"); } else { //the user choose ingredient and the ingredient not shows then add the ingredient dgvIngredientsList.Rows.Add(ingredients[cbIngredientName.SelectedIndex].ID, ingredients[cbIngredientName.SelectedIndex].Name, cbAmount.Text); dgvIngredientsList.CurrentCell.Selected = false; if (updateFlag) { IngredientsInDish ingredientInDish = new IngredientsInDish(); ingredientInDish.DishID = newDish.ID; ingredientInDish.IngredientID = ingredients[cbIngredientName.SelectedIndex].ID; ingredientInDish.Quantity = double.Parse(cbAmount.Text); IngredientsToAddToDish.Add(ingredientInDish); } cbIngredientName.Text = string.Empty; cbAmount.Text = "1"; } } }
/// <summary> /// Method to fill the IngredientsToAddToDish array list with all the new dish ingredients /// </summary> private void FillIngredientArrayList() { if (IngredientsToAddToDish == null) { IngredientsToAddToDish = new List <IngredientsInDish>(); } for (int i = 0; i < dgvIngredientsList.Rows.Count; i++) { IngredientsInDish tmpIngredientToAdd = new IngredientsInDish(); tmpIngredientToAdd.DishID = newDish.ID; tmpIngredientToAdd.IngredientID = int.Parse(dgvIngredientsList.Rows[i].Cells[0].Value.ToString()); tmpIngredientToAdd.Quantity = double.Parse(dgvIngredientsList.Rows[i].Cells[2].Value.ToString()); IngredientsToAddToDish.Add(tmpIngredientToAdd); } }