void LoadData() { try { dtService = new DataTable(); dtService.Clear(); DataSet ds = dbService.GetService(); dtService = ds.Tables[0]; // Đưa dữ liệu lên DataGridView dgvService.DataSource = dtService; // Thay đổi độ rộng cột dgvService.AutoResizeColumns(); // Xóa trống các đối tượng trong Panel this.txtServiceID.ResetText(); this.txtServiceName.ResetText(); this.txtPrice.ResetText(); this.txtUnit.ResetText(); this.txtServiceID.Enabled = true; this.txtServiceName.Enabled = true; this.txtPrice.Enabled = true; this.txtUnit.Enabled = true; // Không cho thao tác trên các nút Lưu / Hủy this.pbSave.Enabled = false; this.pbCancel.Enabled = false; this.pbSave.Hide(); this.pbCancel.Hide(); // Không cho thao tác trên các ô thông tin this.gbInfor.Enabled = false; this.gbInfor.Text = "Information"; // Cho thao tác trên các nút Thêm / Sửa / Xóa /Thoát this.pbAdd.Enabled = true; this.pbEdit.Enabled = true; this.pbDelete.Enabled = true; this.pbBack.Enabled = true; this.pbAdd.Show(); this.pbEdit.Show(); this.pbDelete.Show(); this.pbBack.Show(); // dgvService_CellClick(null, null); } catch (SqlException) { MessageBox.Show("Cannot get data from table 'Service' !"); } }
void LoadData() { try { dtUseService = new DataTable(); dtUseRoom = new DataTable(); dtService = new DataTable(); dtUseService.Clear(); dtUseRoom.Clear(); dtService.Clear(); DataSet ds = dbUseService.GetUseService(); dtUseService = ds.Tables[0]; DataSet dsUseRoom = dbRoom.GetUseRoomUnpaid(); dtUseRoom = dsUseRoom.Tables[0]; DataSet dsService = dbService.GetService(); dtService = dsService.Tables[0]; // Đưa dữ liệu lên DataGridView dgvUseService.DataSource = dtUseService; (dgvUseService.Columns["ServiceID"] as DataGridViewComboBoxColumn).DataSource = dtService; (dgvUseService.Columns["ServiceID"] as DataGridViewComboBoxColumn).DisplayMember = dtService.Columns[1].ToString(); (dgvUseService.Columns["ServiceID"] as DataGridViewComboBoxColumn).ValueMember = dtService.Columns[0].ToString(); // Thay đổi độ rộng cột dgvUseService.AutoResizeColumns(); // Xóa trống các đối tượng trong Panel this.cmbRoomID.ResetText(); this.cmbServiceID.ResetText(); this.dtpDateIn.ResetText(); this.txtAmount.ResetText(); this.cmbRoomID.Enabled = true; this.cmbServiceID.Enabled = true; this.dtpDateIn.Enabled = true; this.txtAmount.Enabled = true; // Không cho thao tác trên các nút Lưu / Hủy this.pbSave.Enabled = false; this.pbCancel.Enabled = false; this.pbSave.Hide(); this.pbCancel.Hide(); // Không cho thao tác trên các ô thông tin this.gbInfor.Enabled = false; this.gbInfor.Text = "Information"; // Cho thao tác trên các nút Thêm / Sửa / Xóa /Thoát this.pbAdd.Enabled = true; this.pbEdit.Enabled = true; this.pbBack.Enabled = true; this.pbAdd.Show(); this.pbEdit.Show(); this.pbBack.Show(); //đẩy dữ liệu lên cmb RoomID và CMND this.cmbRoomID.DataSource = dtUseRoom; this.cmbRoomID.DisplayMember = dtUseRoom.Columns[0].ToString(); this.cmbRoomID.ValueMember = dtUseRoom.Columns[0].ToString(); this.cmbServiceID.DataSource = dtService; this.cmbServiceID.DisplayMember = dtService.Columns[1].ToString(); this.cmbServiceID.ValueMember = dtService.Columns[0].ToString(); dgvUseService_CellClick(null, null); } catch (SqlException) { MessageBox.Show("Cannot get data from table 'Su Dung Phong' !"); } }