public void GetRecepieIngredients() { Height = 23; Ingredients = new List<UcRecepieIngredient>(); _ingredientLocation.Y = 23; string sql = "SELECT idIngredient, SortOrder " + "FROM tblRecepieIngredients " + "WHERE idRecepieHeading=" + IdRecepieHeading + " ORDER BY SortOrder"; DataTable tbl = Functions.GetTable(sql); foreach (DataRow row in tbl.Rows) { UcRecepieIngredient ingredient = new UcRecepieIngredient(); ingredient.IdIngredient = (int)row["idIngredient"]; ingredient.GetIngredient(); ingredient.SortOrder = (int) row["SortOrder"]; ingredient.Location = _ingredientLocation; ingredient.IngredientDeletedEvent += IngredientDeleted; Controls.Add(ingredient); Ingredients.Add(ingredient); _ingredientLocation.Y += 23; Height += 23; } }
private bool AddIngredient() { string sql = "INSERT INTO tblRecepieIngredients (idRecepieHeading, idFood, Amount, idUnit, SortOrder) VALUES(@idRecepieHeading, @idFood, @Amount, @idUnit, @SortOrder) SET @ID = SCOPE_IDENTITY();"; SqlCommand cmd = Global.conn1.CreateCommand(); cmd.CommandText = sql; cmd.Parameters.AddWithValue("@idRecepieHeading", IdRecepieHeading); cmd.Parameters.AddWithValue("@idFood", (int) dgvFood.SelectedRows[0].Cells[3].Value); cmd.Parameters.AddWithValue("@Amount", Convert.ToDecimal(txtAmount.Text)); cmd.Parameters.AddWithValue("@idUnit", cmbUnits.SelectedValue); cmd.Parameters.AddWithValue("@SortOrder", NewSortOrder); cmd.Parameters.Add("@ID", SqlDbType.Int, 4).Direction = ParameterDirection.Output; if (Global.conn1.State != ConnectionState.Open) Global.conn1.Open(); cmd.ExecuteNonQuery(); NewIngredient=new UcRecepieIngredient(); NewIngredient.IdIngredient = (int)cmd.Parameters["@ID"].Value; NewIngredient.GetIngredient(); NewSortOrder += 1; return true; }