Exemple #1
0
        void LoadData()
        {
            try
            {
                dtPurchase = new DataTable();
                dtUseRoom  = new DataTable();
                dtStaff    = new DataTable();

                dtPurchase.Clear();
                dtUseRoom.Clear();
                dtStaff.Clear();

                DataSet dsstaff = dbStaff.GetStaff();
                DataSet ds      = dbPurchase.GetPurchase();
                DataSet dsroom  = dbUseRoom.GetUseRoomUnpaid();
                dtPurchase = ds.Tables[0];
                dtUseRoom  = dsroom.Tables[0];
                dtStaff    = dsstaff.Tables[0];
                // Đưa dữ liệu lên DataGridView
                dgvPurchase.DataSource = dtPurchase;

                for (int i = 0; i < dgvPurchase.Rows.Count; i++)
                {
                    DataSet  roomusing = dbUseRoom.GetUseRoomCheckIn(dgvPurchase.Rows[i].Cells["RoomID"].Value.ToString());
                    string[] NgayVao   = roomusing.Tables[0].Rows[0][0].ToString().Split(' ');
                    dgvPurchase.Rows[i].Cells["CheckIn"].Value = NgayVao[0];
                }

                for (int i = 0; i < this.dgvPurchase.Rows.Count; i++)
                {
                    dgvPurchase.Rows[i].Cells["Receipt"].Value = "receipt";
                }

                //Đưa dữ liệu mã phòng lên combobox
                this.cmbRoomID.DataSource    = dtUseRoom;
                this.cmbRoomID.DisplayMember = dtUseRoom.Columns[0].ToString();
                this.cmbRoomID.ValueMember   = dtUseRoom.Columns[0].ToString();

                //Đưa mã nv lên cmb
                this.cmbStaffID.DataSource    = dtStaff;
                this.cmbStaffID.DisplayMember = dtStaff.Columns[0].ToString();
                this.cmbStaffID.ValueMember   = dtStaff.Columns[0].ToString();

                // Thay đổi độ rộng cột
                dgvPurchase.AutoResizeColumns();
                // Xóa trống các đối tượng trong Panel
                this.txtPurchaseID.ResetText();
                this.cmbRoomID.ResetText();
                this.txtTotal.ResetText();
                this.dtpPurchaseDate.ResetText();
                this.cmbStaffID.ResetText();
                this.dtpDateIn.ResetText();
                this.txtPurchaseID.Enabled   = true;
                this.cmbRoomID.Enabled       = true;
                this.txtTotal.Enabled        = true;
                this.dtpPurchaseDate.Enabled = true;
                this.cmbStaffID.Enabled      = true;
                this.dtpDateIn.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();

                dgvPurchase_CellClick(null, null);
            }
            catch (SqlException)
            {
                MessageBox.Show("Cannot get data from table 'ThanhToan' !");
            }
        }
        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' !");
            }
        }