private void btnDatPhong_Click(object sender, EventArgs e)
        {
            string[] column_name = { "TenKH", "GioiTinh", "SoCMND", "LoaiKHID", "SoDienThoai", "Email", "DiemThuong" };
            int      maKH        = QLKhachHang.insert("KHACHHANG", column_name, txtKhachHang.Text, (cboGioiTinh.SelectedItem == "Nam" ? 1 : 0), txtSoCMT.Text, (cboLoaiKH.SelectedItem == "Nội Địa" ? 1 : 2), txtSoDT.Text, null, 0);

            txtMaKH.Text = maKH.ToString();
            int maPhieuThue = RentAdd();

            int maHD = AddOrder(maPhieuThue);

            txtSoBill.Text = maHD.ToString();
            if (maHD != -1)
            {
                MessageBox.Show("Hóa Đơn Đã được thêm!");

                DataTable    dttb = DTService.getAll();
                DataColumn[] keys = new DataColumn[1];
                keys[0]                 = dttb.Columns[0];
                dttb.PrimaryKey         = keys;
                gridDSDichVu.DataSource = dttb;

                dtDVSD = DTBillDetail.getAllWhere("CHITIETHOADON", "MAHD = " + txtSoBill.Text + " AND Phong = " + txtSoPhong.Tag.ToString());
                DataColumn[] keysDVSD = new DataColumn[1];
                keysDVSD[0]       = dtDVSD.Columns[0];
                dtDVSD.PrimaryKey = keysDVSD;
                gridControlDVSuDung.DataSource = dtDVSD;

                Phong.update("PHONG", "TinhTrangPhong = 1", "MaPhong = " + txtSoPhong.Tag.ToString());
                loadGalleryPhong();
            }
            else
            {
                MessageBox.Show("Lỗi khi thêm hóa đơn!");
            }
        }
        public static bool delbyid(string id)
        {
            if (String.IsNullOrWhiteSpace(id))
            {
                return(false);
            }

            if (DTBillDetail.deletebyId(int.Parse(id)))
            {
                return(true);
            }
            return(false);
        }
        public static int create(string[] _value)
        {
            for (int i = 0; i < _value.Length; i++)
            {
                if (String.IsNullOrWhiteSpace(_value[i]))
                {
                    return(i);
                }
            }

            DTBillDetail.create(_value);

            return(-1);
        }
        public static int update(string[] _set, string _where)
        {
            string _value = "";

            //"NgayLap", "TongGia", "NhanVien", "Phong", "MaPhieuThue"
            for (int i = 0; i < _set.Length; i++)
            {
                if (String.IsNullOrWhiteSpace(_set[i]))
                {
                    return(i);
                }
            }
            _value += @"MaHD=N'" + _set[0] + "',";
            _value += @"MaDichVu=N'" + _set[1] + "',";
            _value += @"NgaySuDung=N'" + _set[2] + "',";
            _value += @"Phong='" + _set[3] + "'";



            DTBillDetail.update(_value, _where);
            return(-1);
        }
        private void galleryControl1_Gallery_ItemClick(object sender, GalleryItemClickEventArgs e)
        {
            //clear dữ liệu
            txtKhachHang.Text     = "";
            txtSoCMT.Text         = "";
            txtSoDT.Text          = "";
            txtSoNguoi.Text       = "";
            dtNgayTra.Text        = "";
            dtNgayThue.DateTime   = DateTime.Now;
            txtSoBill.Text        = "";
            txtTienThuePhong.Text = "";
            txtTongTien.Text      = "";
            txtPhuThu.Text        = "";
            txtPhiDichVu.Text     = "";
            cboLoaiKH.Text        = "";


            string GhiChu = e.Item.Description;

            maPhongClick    = e.Item.Caption;
            txtSoPhong.Text = e.Item.Caption;

            string maPhong_TrangThai = e.Item.Tag.ToString();

            txtSoPhongBill.Text = e.Item.Caption;

            //cboLoaiPhong.DataSource = LoaiKH.getAll("LOAIKHACHHANG");

            // add maphong vao txtSoPhong.Tag de su dung khi dat phong, ko phai lay lai ma phong
            txtSoPhong.Tag = maPhong_TrangThai.Split('_')[0];
            string trangThaiP = maPhong_TrangThai.Split('_')[1];

            if (trangThaiP == "0" || trangThaiP == "1")
            {
                btnDatPhong.Enabled         = false;
                btnChuyenPhong.Enabled      = true;
                btnThayDoiThongTin.Enabled  = true;
                btnInPhieuThuePhong.Enabled = true;

                btnThemKH.Enabled = true;
                btnXoaKH.Enabled  = true;
                btnSuaKH.Enabled  = true;
                showBill(maPhongClick);

                // load thong tin người trong phòng
                try
                {
                    DataTable dtPhieuThuePhong = DTRent.getAllWhere("PHIEUTHUE", "MaPhong = " + txtSoPhong.Tag.ToString() + " AND TinhTrangPhieuThue = 1");
                    string    maPhieuThue      = dtPhieuThuePhong.Rows[0]["MaPhieuThue"].ToString();
                    txtMaPhieuThue.Text = maPhieuThue;

                    dtKH = KhachHang.getAllWhere("KHACHHANG", "MaKH = " + dtPhieuThuePhong.Rows[0]["MaKH"].ToString());
                    txtKhachHang.Text        = dtKH.Rows[0]["TenKH"].ToString();
                    txtSoCMT.Text            = dtKH.Rows[0]["SoCMND"].ToString();
                    cboGioiTinh.SelectedItem = dtKH.Rows[0]["GioiTinh"].ToString() == "1" ? "Nam" : "Nữ";
                    txtSoDT.Text             = dtKH.Rows[0]["SoDienThoai"].ToString();
                    cboLoaiKH.SelectedItem   = dtKH.Rows[0]["LoaiKHID"].ToString() == "1" ? "Nội Địa" : "Quốc Tế";


                    txtSoNguoi.Text = "1";
                    dtNgayThue.Text = dtPhieuThuePhong.Rows[0]["NgayBatDau"].ToString();
                    dtNgayTra.Text  = dtPhieuThuePhong.Rows[0]["NgayKetThuc"].ToString();

                    //HD
                    loadHoaDon();

                    //dsdv hien co
                    DataTable    dttb = DTService.getAll();
                    DataColumn[] keys = new DataColumn[1];
                    keys[0]                 = dttb.Columns[0];
                    dttb.PrimaryKey         = keys;
                    gridDSDichVu.DataSource = dttb;

                    //ds dich vu da su dung
                    DataTable dtCTHD = DTBillDetail.getAllWhere("CHITIETHOADON", "MAHD = " + txtSoBill.Text + " AND Phong = " + txtSoPhong.Tag.ToString());
                    if (dtCTHD.Rows.Count != 0)
                    {
                        string[] arrayDV = new string[dtCTHD.Rows.Count];
                        for (int i = 0; i < dtCTHD.Rows.Count; i++)
                        {
                            arrayDV[i] = dtCTHD.Rows[i]["MaDichVu"].ToString();
                        }
                        dtDVSD = DTService.getAllWhere("DICHVU", "MaDichVu in (" + String.Join(",", arrayDV) + ")");
                        DataColumn[] keysDVSD = new DataColumn[1];
                        keysDVSD[0]       = dtDVSD.Columns[0];
                        dtDVSD.PrimaryKey = keysDVSD;
                        gridControlDVSuDung.DataSource = dtDVSD;
                    }
                    else
                    {
                        dtDVSD = new DataTable();
                        gridControlDVSuDung.DataSource = dtDVSD;
                    }
                }
                catch (Exception)
                {
                    return;

                    throw;
                }
            }
            else
            {
                btnDatPhong.Enabled         = true;
                btnChuyenPhong.Enabled      = false;
                btnThayDoiThongTin.Enabled  = false;
                btnInPhieuThuePhong.Enabled = false;

                gridKhachHang.DataSource = null;
                btnThemKH.Enabled        = false;
                btnXoaKH.Enabled         = false;
                btnSuaKH.Enabled         = false;
            }
        }
        private void btnThemDV_Click(object sender, EventArgs e)
        {
            string maDV = txtDichVuSelect.Text;

            if (String.IsNullOrEmpty(maDV))
            {
                MessageBox.Show("Bạn phải chọn 1 dịch vụ khi thêm!");
            }
            else
            {
                string[] values = { txtSoBill.Text, maDV, DateTime.Now.ToString("yyyy-MM-dd"), txtSoPhong.Tag.ToString() };
                if (DTBillDetail.create(values))
                {
                    //
                    //DataRow dr = new DataRow(txtSoBill.Text, maDV, DateTime.Now.ToString("yyyy-MM-dd"), txtSoPhong.Tag.ToString());
                    DataTable dtCTHD = DTBillDetail.getAllWhere("CHITIETHOADON", "MAHD = " + txtSoBill.Text + " AND Phong = " + txtSoPhong.Tag.ToString());
                    if (dtCTHD.Rows.Count != 0)
                    {
                        string[] arrayDV = new string[dtCTHD.Rows.Count];
                        for (int i = 0; i < dtCTHD.Rows.Count; i++)
                        {
                            arrayDV[i] = dtCTHD.Rows[i]["MaDichVu"].ToString();
                        }
                        dtDVSD = DTService.getAllWhere("DICHVU", "MaDichVu in (" + String.Join(",", arrayDV) + ")");
                        DataColumn[] keysDVSD = new DataColumn[1];
                        keysDVSD[0]       = dtDVSD.Columns[0];
                        dtDVSD.PrimaryKey = keysDVSD;
                        gridControlDVSuDung.DataSource = dtDVSD;

                        decimal giaDVselected = 0;
                        foreach (DataRow item in dtDVSD.Rows)
                        {
                            if (item["MaDichVu"].ToString() == maDV)
                            {
                                giaDVselected = Decimal.Parse(item["Gia"].ToString());
                            }
                        }

                        DataTable dtHD = DTBill.getAllWhere("HOADON", "MaHoaDon = " + dtCTHD.Rows[0]["MaHD"].ToString());

                        if (DTBill.update("TongGia = " + (Decimal.Parse(dtHD.Rows[0]["TongGia"].ToString()) + giaDVselected), "MaHoaDon = " + dtCTHD.Rows[0]["MaHD"].ToString()))
                        {
                            //HD
                            loadHoaDon();
                        }
                        else
                        {
                            MessageBox.Show("Lỗi Khi cập nhật hóa đơn!");
                        }
                    }
                    else
                    {
                        dtDVSD = new DataTable();
                        gridControlDVSuDung.DataSource = dtDVSD;
                    }
                }
                else
                {
                    MessageBox.Show("Lỗi không thêm được dịch vụ!");
                }
            }
        }