Ejemplo n.º 1
0
 void LoadData()
 {
     try
     {
         dtClient = new DataTable();
         dtClient.Clear();
         DataSet ds = dbClient.GetClient();
         dtClient = ds.Tables[0];
         // Đưa dữ liệu lên DataGridView
         dgvClient.DataSource = dtClient;
         // Thay đổi độ rộng cột
         dgvClient.AutoResizeColumns();
         // Xóa trống các đối tượng trong Panel
         this.txtID.ResetText();
         this.txtName.ResetText();
         this.txtAddress.ResetText();
         this.txtPhoneNumber.ResetText();
         this.dtpBirthDate.ResetText();
         this.txtID.Enabled          = true;
         this.txtName.Enabled        = true;
         this.txtAddress.Enabled     = true;
         this.txtPhoneNumber.Enabled = true;
         this.dtpBirthDate.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.pbDelete.Enabled = true;
         this.pbAdd.Show();
         this.pbEdit.Show();
         this.pbBack.Show();
         this.pbDelete.Show();
         //
         dgvClient_CellClick(null, null);
     }
     catch (SqlException)
     {
         MessageBox.Show("Cannot get data from table 'KhachHang' !");
     }
 }
Ejemplo n.º 2
0
        void LoadData()
        {
            try
            {
                dtUseRoom = new DataTable();
                dtRoom    = new DataTable();
                dtClient  = new DataTable();
                dtStaff   = new DataTable();

                dtUseRoom.Clear();
                dtRoom.Clear();
                dtClient.Clear();
                dtStaff.Clear();

                DataSet dsstaff = dbStaff.GetStaff();
                dtStaff = dsstaff.Tables[0];

                DataSet ds = dbUseRoom.GetUseRoom();
                dtUseRoom = ds.Tables[0];

                DataSet dsRoom = dbRoom.GetRoom();
                dtRoom = dsRoom.Tables[0];

                DataSet dsClient = dbCLient.GetClient();
                dtClient = dsClient.Tables[0];
                // Đưa dữ liệu lên DataGridView
                dgvRoom.DataSource = dtUseRoom;
                // Thay đổi độ rộng cột
                dgvRoom.AutoResizeColumns();
                // Xóa trống các đối tượng trong Panel
                this.cmbRoomID.ResetText();
                this.cmbCMND.ResetText();
                this.dtpDateIn.ResetText();
                this.txtDeposit.ResetText();
                this.cmbRoomID.Enabled  = true;
                this.cmbCMND.Enabled    = true;
                this.dtpDateIn.Enabled  = true;
                this.txtDeposit.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    = dtRoom;
                this.cmbRoomID.DisplayMember = dtRoom.Columns[0].ToString();
                this.cmbRoomID.ValueMember   = dtRoom.Columns[0].ToString();

                this.cmbCMND.DataSource    = dtClient;
                this.cmbCMND.DisplayMember = dtClient.Columns[0].ToString();
                this.cmbCMND.ValueMember   = dtClient.Columns[0].ToString();

                dgvRoom_CellClick(null, null);
            }
            catch (SqlException)
            {
                MessageBox.Show("Cannot get data from table 'Su Dung Phong' !");
            }
        }