private void btnAddFood_Click(object sender, EventArgs e) { frmEditDiary frm = new frmEditDiary(); frm.DiaryDate = dtpDate.Value; frm.ShowDialog(); }
private void miEditFood_Click(object sender, EventArgs e) { int idFood; int idUnit; int idMealType; decimal amnt; if (dgvDiary.SelectedRows[0].Cells[0].Value == null) return; string sqlQuery = "SELECT " + "tblDiary.id, " + "tblDiary.id_Meal, " + "tblDiary.id_Food, " + "tblDiary.amnt, " + "tblDiary.id_unit, " + "tblMeals.id_mealType " + "FROM tblDiary " + "left join tblMeals on tblmeals.id = tblDiary.id_Meal " + "WHERE tblDiary.id = @idDiary"; SqlCommand cmd = new SqlCommand(sqlQuery, Global.conn1); cmd.Parameters.AddWithValue("@idDiary", (int)dgvDiary.SelectedRows[0].Cells[0].Value); if (Global.conn1.State != ConnectionState.Open) Global.conn1.Open(); SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { reader.Read(); idFood = reader.GetInt32(2); idUnit = reader.GetInt32(4); idMealType = reader.GetInt32(5); amnt = reader.GetDecimal(3); reader.Close(); Global.conn1.Close(); frmEditDiary frm = new frmEditDiary(); frm.DiaryDate = dtpDate.Value.Date; frm.IdFood = idFood; frm.IdUnit = idUnit; frm.IdMealType = idMealType; frm.amnt = amnt; frm.ShowDialog(); } }