private void lblUpdateServingTime_Click(object sender, EventArgs e) { if (!(sender is Button && (Button)sender == btnSetServingTime)) { using (var form = new UpdateServingTime(scheduleID)) { form.ShowDialog(); if (scheduleID != form.scheduleID) { scheduleID = form.scheduleID; } }; } if (scheduleID == null) { return; } dgvScheduleMealSet.ColumnCount = 2; dgvScheduleMealSet.Columns[0].Name = "Mã suất"; dgvScheduleMealSet.Columns[1].Name = "Tên suất"; dgvScheduleMealSet.Columns[0].Width = 100; dgvScheduleMealSet.Columns[1].Width = 260; int labelChar = 65; try { MealSetInScheduleDetailTableAdapter mealSetInScheduleDetailTA = new MealSetInScheduleDetailTableAdapter(); DataTable mealSetInScheduleDetailDT = mealSetInScheduleDetailTA.GetDataByScheduleID(scheduleID.Value); DataTable scheduleDT = new ScheduleTableAdapter().GetDataByID(scheduleID.Value); if (scheduleDT.Rows.Count != 0) { lblDate.Text = scheduleDT.Rows[0].Field<DateTime>("Date").ToString("dd/MM/yyyy"); string servingTimeString = new ServingTimeTableAdapter().GetStringByID(scheduleDT.Rows[0].Field<int>("ServingTimeID")); lblServingTime.Text = servingTimeString; } dgvScheduleMealSet.Rows.Clear(); usingMealSetList = new List<KeyValuePair<int, string>>(); if (mealSetInScheduleDetailDT.Rows.Count != 0) { usingMealSetList.Add(new KeyValuePair<int, string>(0, "<<Không có>>")); foreach (DataRow row in mealSetInScheduleDetailDT.Rows) { string name = row.Field<string>("Name"); int scheduleMealSetDetailID = row.Field<int>("ScheduleMealSetDetailID"); bool canEatMore = row.Field<bool>("CanEatMore"); string displayName = ((char)labelChar).ToString() + ": " + name + " " + (canEatMore ? "(Có ăn thêm)" : ""); string[] rowValue = new string[] { ((char)labelChar).ToString(), name }; dgvScheduleMealSet.Rows.Add(rowValue); usingMealSetList.Add(new KeyValuePair<int, string>(scheduleMealSetDetailID, displayName)); labelChar++; } } RefreshDropDownList(); } catch (Exception ex) { MessageBox.Show("Có lỗi khi lấy dữ liệu."); Log.ErrorLog(ex.Message); } }
private void btnCheckScheduleMealSet_Click(object sender, EventArgs e) { dataGridView.Rows.Clear(); int servingTimeID; if (!int.TryParse(cbxServingTime.SelectedValue.ToString(), out servingTimeID)) { MessageBox.Show("Không thể lấy dữ liệu bữa ăn."); return; } DataTable schedule = new ScheduleTableAdapter().GetDataByDateAndServingTime(now.Date, servingTimeID); if (schedule.Rows.Count != 1) { this._scheduleID = null; MessageBox.Show("Không tìm thấy lịch ăn cho bữa ăn này."); btnOk.Enabled = false; return; } else if (!schedule.Rows[0].Field<bool>("IsDayOn")) { this._scheduleID = null; MessageBox.Show("Bữa ăn này đang được đặt là nghỉ."); btnOk.Enabled = false; return; } //this._scheduleID = scheduleID; this._scheduleID = schedule.Rows[0].Field<int>("ScheduleID"); dataGridView.ColumnCount = 2; dataGridView.Columns[0].Name = "Mã suất"; dataGridView.Columns[1].Name = "Tên suất"; int labelChar = 65; try { MealSetInScheduleDetailTableAdapter mealSetInScheduleDetailTA = new MealSetInScheduleDetailTableAdapter(); DataTable dt = mealSetInScheduleDetailTA.GetDataByScheduleID(this._scheduleID.Value); if (dt.Rows.Count == 0) { MessageBox.Show("Chưa có suất ăn nào đươc đặt trong bữa này."); } else { foreach (DataRow row in dt.Rows) { string[] rowValue = new string[] { ((char)labelChar).ToString(), row.Field<string>("Name") }; dataGridView.Rows.Add(rowValue); labelChar++; } } } catch (Exception ex) { MessageBox.Show("Có lỗi khi lấy dữ liệu."); Log.ErrorLog(ex.Message); btnOk.Enabled = false; } btnOk.Enabled = true; }