Beispiel #1
0
        private void TaoMaHD(string NhapMaChiNhanhVao, ref string MaHDmoi)
        {
            DTO_HoaDon hoadon = new DTO_HoaDon();

            hoadon.MaHD = NhapMaChiNhanhVao;
            BO_DatPhong MaHD   = new BO_DatPhong();
            DataSet     result = MaHD.KiemTraMaHD(hoadon);

            if (result.Tables.Count > 0 && result.Tables[0].Rows.Count > 0)
            {
                string NgayThangNam;
                string TenChiNhanh;
                int    STTtrongNgay;
                chuoiMaHD = result.Tables[0].Rows[0][0].ToString();
                if (hoadon.MaHD == "HCM")
                {
                    TenChiNhanh  = chuoiMaHD.Substring(0, 3);
                    NgayThangNam = chuoiMaHD.Substring(4, 8);
                    STTtrongNgay = int.Parse(chuoiMaHD.Substring(13, 3));
                }
                else
                {
                    TenChiNhanh  = chuoiMaHD.Substring(0, 2);
                    NgayThangNam = chuoiMaHD.Substring(3, 8);
                    STTtrongNgay = int.Parse(chuoiMaHD.Substring(12, 3));
                }
                if (NgayThangNam == DateTime.Now.ToShortDateString())
                {
                    if (STTtrongNgay < 9)
                    {
                        STTtrongNgay += 1;
                        string STT = "00" + STTtrongNgay.ToString();
                        MaHDmoi = TenChiNhanh + "-" + NgayThangNam + "-" + STT;
                    }
                    else
                    {
                        if (STTtrongNgay < 99)
                        {
                            STTtrongNgay += 1;
                            string STT = "0" + STTtrongNgay.ToString();
                            MaHDmoi = TenChiNhanh + "-" + NgayThangNam + "-" + STT;
                        }
                        else
                        {
                            STTtrongNgay += 1;
                            string STT = STTtrongNgay.ToString();
                            MaHDmoi = TenChiNhanh + "-" + NgayThangNam + "-" + STT;
                        }
                    }
                }
                else
                {
                    NgayThangNam = DateTime.Now.ToShortDateString();
                    string STT = "001";
                    MaHDmoi = TenChiNhanh + "-" + NgayThangNam + "-" + STT;
                }
            }
            else
            {
                string TenChiNhanh  = NhapMaChiNhanhVao;
                string NgayThangNam = DateTime.Now.ToShortDateString();

                string STT = "001";
                MaHDmoi = TenChiNhanh + "-" + NgayThangNam + "-" + STT;
            }
        }
Beispiel #2
0
        private void btn_DatPhong_Click(object sender, EventArgs e)
        {
            if (txtSoDT.Text == "(+84) ")
            {
                lb_LoiSDT.Visible = true;
                lb_LoiSDT.Text    = "Bạn chưa nhập  số điện thoại";
            }
            else
            {
                lb_LoiSDT.Visible = false;
            }
            if (txt_Ten.Text == "")
            {
                lb_LoiTen.Visible = true;
                lb_LoiTen.Text    = "Bạn chưa điền tên";
            }
            else
            {
                lb_LoiTen.Visible = false;
            }
            if (lb_LoiTen.Visible == false && lb_LoiSDT.Visible == false)
            {
                DialogResult answer;
                answer = MessageBox.Show("Bạn có muốn đặt phòng chứ ?", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (answer == DialogResult.Yes)
                {
                    BO_DatPhong datphong = new BO_DatPhong();
                    DTO_HoaDon  phong    = new DTO_HoaDon();
                    TaoMaHD(tenvtchinhanh, ref MaHDMoi);
                    phong.MaHD    = MaHDMoi;
                    phong.MaPhong = maphong;
                    string NgayDat       = dtpNgayDat.Text.Substring(0, 2);
                    string ThangDat      = dtpNgayDat.Text.Substring(3, 2);
                    string NamDat        = dtpNgayDat.Text.Substring(6, 4);
                    string GioDatPhong   = "12";
                    string PhutDatPhong  = "00";
                    string NgayTra       = dtpNgayTra.Text.Substring(0, 2);
                    string ThangTra      = dtpNgayTra.Text.Substring(3, 2);
                    string NamTra        = dtpNgayTra.Text.Substring(6, 4);
                    string GioTraPhong   = "12";
                    string PhutTraPhong  = "00";
                    string NgayDatPhong1 = NamDat + "-" + ThangDat + "-" + NgayDat + " " + GioDatPhong + ":" + PhutDatPhong + ":00";
                    string NgayTraPhong1 = NamTra + "-" + ThangTra + "-" + NgayTra + " " + GioTraPhong + ":" + PhutTraPhong + ":00";
                    phong.NgayDatPhong           = NgayDatPhong1;
                    phong.NgayTraPhong           = NgayTraPhong1;
                    phong.SoDienThoai            = txtSoDT.Text;
                    phong.MaChiNhanh             = machinhanh;
                    phong.MaDV                   = madv;
                    phong.TenDichVu              = tendv;
                    phong.ThanhTien              = giatien;
                    phong.DapUng                 = "Yes";
                    phong.DatCoc                 = "No";
                    phong.ThoiGianThucHienHoaDon = DateTime.Now;
                    TimeSpan ts = new TimeSpan();

                    DateTime NgayDatPhong2 = new DateTime(dtpNgayDat.Value.Year, dtpNgayDat.Value.Month, dtpNgayDat.Value.Day, 12, 00, 00);
                    DateTime NgayTraPhong2 = new DateTime(dtpNgayTra.Value.Year, dtpNgayTra.Value.Month, dtpNgayTra.Value.Day, 12, 00, 00);
                    ts        = NgayTraPhong2 - NgayDatPhong2;
                    phong.STT = 1;
                    double count = ts.TotalDays;
                    phong.SoLuong   = (int)count;
                    phong.ThanhTien = giatien * phong.SoLuong;
                    BO_DatPhong datphongnhanh = new BO_DatPhong();
                    if (datphongnhanh.DatPhong(phong) != -1)
                    {
                        MessageBox.Show("Đặt phòng thành công ", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Hide();

                        BO_DangNhap   kiemtrakh = new BO_DangNhap();
                        DTO_KhachHang khachhang = new DTO_KhachHang();
                        khachhang.SDT = txtSoDT.Text;
                        DataSet result = kiemtrakh.KT_SDT(khachhang, ref tenkh);
                        if (result.Tables.Count > 0 && result.Tables[0].Rows.Count > 0)
                        {
                        }
                        else
                        {
                            //Néu khách hàng đặt lần đầu
                            khachhang.TenKH       = txt_Ten.Text;
                            khachhang.MatKhau     = "";
                            khachhang.TichLuy     = 0;
                            khachhang.CauHoiBiMat = "";
                            khachhang.CMND        = "";
                            khachhang.TraLoi      = "";
                            //lưu thông tin lại
                            BO_DangKi dangki = new BO_DangKi();
                            dangki.DangKi(khachhang);
                        }
                        XacNhan xacnhan = new XacNhan();
                        xacnhan.MAHD             = MaHDMoi;
                        xacnhan.MACHINHANH       = machinhanh;
                        xacnhan.MAPHONG          = maphong;
                        xacnhan.TENPHONG         = tenphong;
                        xacnhan.TENKH            = txt_Ten.Text;
                        xacnhan.DANHXUNG         = cbb_DanhXung.Text;
                        xacnhan.SDT              = txtSoDT.Text;
                        xacnhan.NGAYDAT          = dtpNgayDat.Text;
                        xacnhan.NGAYTRA          = dtpNgayTra.Text;
                        xacnhan.GIATIEN          = phong.ThanhTien;
                        xacnhan.THOIGIANTHUCHIEN = DateTime.Now;
                        xacnhan.ShowDialog();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Đặt phòng không thành công, vui lòng thử lại", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #3
0
        private void pTimKiem_Click(object sender, EventArgs e)
        {
            load();

            if (cbbDiaChi.Text == "")
            {
                MessageBox.Show("Bạn chưa chọn nơi ở", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (cbbDiaChi.Text == "Đà Lạt")
                {
                    MaHD = "DL";
                }
                else
                {
                    if (cbbDiaChi.Text == "Hồ Chí Minh")
                    {
                        MaHD = "HCM";
                    }
                    else
                    {
                        if (cbbDiaChi.Text == "Đà Nẵng")
                        {
                            MaHD = "DN";
                        }
                        else
                        {
                            if (cbbDiaChi.Text == "Nha Trang")
                            {
                                MaHD = "NT";
                            }
                            else
                            {
                                MaHD = "PQ";
                            }
                        }
                    }
                }
                if (dtpNgayDat.Text == dtpNgayTra.Text)
                {
                    MessageBox.Show("Ngày đặt và ngày trả trùng nhau", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    DateTime dtp1 = new DateTime();
                    DateTime dtp2 = new DateTime();
                    catchuoi(dtpNgayTra.Text, ref dtp1);
                    catchuoi(dtpNgayDat.Text, ref dtp2);
                    TimeSpan ts = new TimeSpan();
                    ts = dtp1 - dtp2;
                    if (ts.TotalDays < 0)
                    {
                        MessageBox.Show("Ngày Đặt không thể sau Ngày Trả được", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        if (cbb_SoNguoi.Text != "Tất Cả")
                        {
                            DTO_HoaDon hoadon = new DTO_HoaDon();
                            if (cbb_SoNguoi.Text == "1-2 người (2 giường đơn)")
                            {
                                hoadon.SoNguoi   = 2;
                                hoadon.LoaiPhong = "Giường Đơn";
                            }
                            else
                            {
                                if (cbb_SoNguoi.Text == "2 người (giường đôi)")
                                {
                                    hoadon.SoNguoi   = 2;
                                    hoadon.LoaiPhong = "Giường Đôi";
                                }
                                else
                                {
                                    if (cbb_SoNguoi.Text == "3-4 người (4 giường đơn)")
                                    {
                                        hoadon.SoNguoi   = 4;
                                        hoadon.LoaiPhong = "Giường Đơn";
                                    }
                                    else
                                    {
                                        if (cbb_SoNguoi.Text == "3-4 người (2 giường đôi)")
                                        {
                                            hoadon.SoNguoi   = 4;
                                            hoadon.LoaiPhong = "Giường Đôi";
                                        }
                                        else
                                        {
                                            if (cbb_SoNguoi.Text == "5-6 người (3 giường đôi)")
                                            {
                                                hoadon.SoNguoi   = 6;
                                                hoadon.LoaiPhong = "Giường Đôi";
                                            }
                                        }
                                    }
                                }
                            }
                            hoadon.MaChiNhanh = MaHD;
                            Point       vitribandau = new Point(5, 5);
                            BO_DatPhong kiemtra     = new BO_DatPhong();
                            DataSet     table       = new DataSet();
                            table = kiemtra.ChonPhong(hoadon);
                            if (table.Tables[0].Rows.Count > 0)
                            {
                                for (int i = 0; i < table.Tables[0].Rows.Count; i++)
                                {
                                    DTO_HoaDon thongtinphong = new DTO_HoaDon();
                                    thongtinphong.MaPhong    = table.Tables[0].Rows[i][0].ToString();
                                    thongtinphong.MaChiNhanh = table.Tables[0].Rows[i][1].ToString();
                                    //Kiểm tra trong phòng hiện tại có nằm trong hóa đơn không, nếu không thì phòng chưa từng được đặt
                                    DataSet KTPhongtrong = new DataSet();
                                    KTPhongtrong = kiemtra.kiemtratronghoadon(thongtinphong);
                                    if (KTPhongtrong.Tables[0].Rows.Count == 0)   //Phòng hiện chưa được sử dụng lần nào => phòng trống
                                    {
                                        if (table.Tables[0].Rows[i][3].ToString() == "Giường Đơn" && table.Tables[0].Rows[i][4].ToString() == "2")
                                        {
                                            giuongdon2nguoi hienthi = new giuongdon2nguoi();
                                            hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                            hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                            hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                            hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                            hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                            hienthi.TENVTCHINHANH = MaHD;
                                            pl_phong.Controls.Add(hienthi);
                                            hienthi.Location = vitribandau;
                                            vitribandau.Y   += 295;
                                        }
                                        else
                                        {
                                            if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "2")
                                            {
                                                giuongdoi2nguoi hienthi = new giuongdoi2nguoi();
                                                hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                hienthi.TENVTCHINHANH = MaHD;
                                                pl_phong.Controls.Add(hienthi);
                                                hienthi.Location = vitribandau;
                                                vitribandau.Y   += 295;
                                            }
                                            else
                                            {
                                                if (table.Tables[0].Rows[i][3].ToString() == "Giường Đơn" && table.Tables[0].Rows[i][4].ToString() == "4")
                                                {
                                                    giuongdon4nguoi hienthi = new giuongdon4nguoi();
                                                    hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                    hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                    hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                    hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                    hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                    hienthi.TENVTCHINHANH = MaHD;
                                                    pl_phong.Controls.Add(hienthi);
                                                    hienthi.Location = vitribandau;
                                                    vitribandau.Y   += 295;
                                                }
                                                else
                                                {
                                                    if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "4")
                                                    {
                                                        giuongdoi4nguoi hienthi = new giuongdoi4nguoi();
                                                        hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                        hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                        hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                        hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                        hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                        hienthi.TENVTCHINHANH = MaHD;
                                                        pl_phong.Controls.Add(hienthi);
                                                        hienthi.Location = vitribandau;
                                                        vitribandau.Y   += 295;
                                                    }
                                                    else
                                                    {
                                                        if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "6")
                                                        {
                                                            giuongdoi6nguoi hienthi = new giuongdoi6nguoi();
                                                            hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                            hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                            hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                            hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                            hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                            hienthi.TENVTCHINHANH = MaHD;
                                                            pl_phong.Controls.Add(hienthi);
                                                            hienthi.Location = vitribandau;
                                                            vitribandau.Y   += 295;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        //Nếu có phòng đang đc sử dụng => kiểm tra xem phòng đó có trùng ngày đặt hay không
                                        DateTime ngaydat = new DateTime();
                                        DateTime ngaytra = new DateTime();
                                        catchuoi(dtpNgayDat.Text, ref ngaydat);
                                        catchuoi(dtpNgayTra.Text, ref ngaytra);
                                        TimeSpan thoigiandat = new TimeSpan();
                                        thoigiandat = ngaytra - ngaydat;
                                        for (int k = 0; k < thoigiandat.Days; k++)
                                        {
                                            SoSanhNgayDat.Add(ngaydat);
                                            ngaydat = ngaydat.AddDays(1);
                                        }
                                        int        count = 0;
                                        DTO_HoaDon kt    = new DTO_HoaDon();
                                        kt.MaPhong    = table.Tables[0].Rows[i][0].ToString();
                                        kt.MaChiNhanh = table.Tables[0].Rows[i][1].ToString();
                                        DataSet table1 = new DataSet();
                                        table1 = kiemtra.KiemTraNgayPhongDangDuocSuDung(kt);

                                        if (table1.Tables[0].Rows.Count > 0 && table1.Tables.Count > 0)
                                        {
                                            int demhd = table1.Tables[0].Rows.Count;
                                            for (int j = 0; j < demhd; j++)
                                            {
                                                DateTime Ngay1 = new DateTime(int.Parse(table1.Tables[0].Rows[j][8].ToString().Substring(6, 2)), int.Parse(table1.Tables[0].Rows[j][8].ToString().Substring(3, 2)), int.Parse(table1.Tables[0].Rows[j][8].ToString().Substring(0, 2)));
                                                DateTime Ngay2 = new DateTime(int.Parse(table1.Tables[0].Rows[j][9].ToString().Substring(6, 2)), int.Parse(table1.Tables[0].Rows[j][9].ToString().Substring(3, 2)), int.Parse(table1.Tables[0].Rows[j][9].ToString().Substring(0, 2)));

                                                TimeSpan khoangthoigiandat = new TimeSpan();
                                                khoangthoigiandat = Ngay2 - Ngay1;
                                                for (int t = 0; t < khoangthoigiandat.Days; t++)
                                                {
                                                    NgayDaDat.Add(Ngay1);
                                                    Ngay1 = Ngay1.AddDays(1);
                                                }
                                                foreach (DateTime day in NgayDaDat)
                                                {
                                                    foreach (DateTime day1 in SoSanhNgayDat)
                                                    {
                                                        if (day == day1)
                                                        {
                                                            count++;
                                                        }
                                                    }
                                                }
                                                NgayDaDat.Clear();
                                            }
                                            if (count == 0)   //Nếu không trùng ngày nào thì hiện lên

                                            {
                                                if (hoadon.LoaiPhong == "Giường Đơn" && hoadon.SoNguoi == 2)
                                                {
                                                    giuongdon2nguoi hienthi = new giuongdon2nguoi();
                                                    hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                    hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                    hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                    hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                    hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                    hienthi.TENVTCHINHANH = MaHD;
                                                    pl_phong.Controls.Add(hienthi);
                                                    hienthi.Location = vitribandau;
                                                    vitribandau.Y   += 295;
                                                }
                                                else
                                                {
                                                    if (hoadon.LoaiPhong == "Giường Đôi" && hoadon.SoNguoi == 2)
                                                    {
                                                        giuongdoi2nguoi hienthi = new giuongdoi2nguoi();
                                                        hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                        hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                        hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                        hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                        hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                        hienthi.TENVTCHINHANH = MaHD;
                                                        pl_phong.Controls.Add(hienthi);
                                                        hienthi.Location = vitribandau;
                                                        vitribandau.Y   += 295;
                                                    }
                                                    else
                                                    {
                                                        if (hoadon.LoaiPhong == "Giường Đơn" && hoadon.SoNguoi == 4)
                                                        {
                                                            giuongdon4nguoi hienthi = new giuongdon4nguoi();
                                                            hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                            hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                            hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                            hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                            hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                            hienthi.TENVTCHINHANH = MaHD;
                                                            pl_phong.Controls.Add(hienthi);
                                                            hienthi.Location = vitribandau;
                                                            vitribandau.Y   += 295;
                                                        }
                                                        else
                                                        {
                                                            if (hoadon.LoaiPhong == "Giường Đôi" && hoadon.SoNguoi == 4)
                                                            {
                                                                giuongdoi4nguoi hienthi = new giuongdoi4nguoi();
                                                                hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                                hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                                hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                                hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                                hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                                hienthi.TENVTCHINHANH = MaHD;
                                                                pl_phong.Controls.Add(hienthi);
                                                                hienthi.Location = vitribandau;
                                                                vitribandau.Y   += 295;
                                                            }
                                                            else
                                                            {
                                                                if (hoadon.LoaiPhong == "Giường Đôi" && hoadon.SoNguoi == 6)
                                                                {
                                                                    giuongdoi6nguoi hienthi = new giuongdoi6nguoi();
                                                                    hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                                    hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                                    hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                                    hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                                    hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                                    hienthi.TENVTCHINHANH = MaHD;
                                                                    pl_phong.Controls.Add(hienthi);
                                                                    hienthi.Location = vitribandau;
                                                                    vitribandau.Y   += 295;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            SoSanhNgayDat.Clear();
                        }
                        else
                        {
                            Point      vitribandau = new Point(5, 5);
                            DTO_HoaDon hoadon      = new DTO_HoaDon();
                            hoadon.MaChiNhanh = MaHD;
                            BO_DatPhong kiemtra = new BO_DatPhong();
                            DataSet     table   = kiemtra.showall(hoadon);
                            if (table.Tables[0].Rows.Count > 0)
                            {
                                for (int i = 0; i < table.Tables[0].Rows.Count; i++)
                                {
                                    DTO_HoaDon thongtinphong = new DTO_HoaDon();
                                    thongtinphong.MaPhong    = table.Tables[0].Rows[i][0].ToString();
                                    thongtinphong.MaChiNhanh = table.Tables[0].Rows[i][1].ToString();
                                    //Kiểm tra trong phòng hiện tại có nằm trong hóa đơn không, nếu không thì phòng chưa từng được đặt
                                    DataSet KTPhongtrong = new DataSet();
                                    KTPhongtrong = kiemtra.kiemtratronghoadon(thongtinphong);
                                    if (KTPhongtrong.Tables[0].Rows.Count == 0)
                                    {
                                        if (table.Tables[0].Rows[i][3].ToString() == "Giường Đơn" && table.Tables[0].Rows[i][4].ToString() == "2")
                                        {
                                            giuongdon2nguoi hienthi = new giuongdon2nguoi();
                                            hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                            hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                            hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                            hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                            hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                            hienthi.TENVTCHINHANH = MaHD;
                                            pl_phong.Controls.Add(hienthi);
                                            hienthi.Location = vitribandau;
                                            vitribandau.Y   += 295;
                                        }
                                        else
                                        {
                                            if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "2")
                                            {
                                                giuongdoi2nguoi hienthi = new giuongdoi2nguoi();
                                                hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                hienthi.TENVTCHINHANH = MaHD;
                                                pl_phong.Controls.Add(hienthi);
                                                hienthi.Location = vitribandau;
                                                vitribandau.Y   += 295;
                                            }
                                            else
                                            {
                                                if (table.Tables[0].Rows[i][3].ToString() == "Giường Đơn" && table.Tables[0].Rows[i][4].ToString() == "4")
                                                {
                                                    giuongdon4nguoi hienthi = new giuongdon4nguoi();
                                                    hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                    hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                    hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                    hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                    hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                    hienthi.TENVTCHINHANH = MaHD;
                                                    pl_phong.Controls.Add(hienthi);
                                                    hienthi.Location = vitribandau;
                                                    vitribandau.Y   += 295;
                                                }
                                                else
                                                {
                                                    if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "4")
                                                    {
                                                        giuongdoi4nguoi hienthi = new giuongdoi4nguoi();
                                                        hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                        hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                        hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                        hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                        hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                        hienthi.TENVTCHINHANH = MaHD;
                                                        pl_phong.Controls.Add(hienthi);
                                                        hienthi.Location = vitribandau;
                                                        vitribandau.Y   += 295;
                                                    }
                                                    else
                                                    {
                                                        if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "6")
                                                        {
                                                            giuongdoi6nguoi hienthi = new giuongdoi6nguoi();
                                                            hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                            hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                            hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                            hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                            hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                            hienthi.TENVTCHINHANH = MaHD;
                                                            pl_phong.Controls.Add(hienthi);
                                                            hienthi.Location = vitribandau;
                                                            vitribandau.Y   += 295;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        DateTime ngaydat = new DateTime();
                                        DateTime ngaytra = new DateTime();
                                        catchuoi(dtpNgayDat.Text, ref ngaydat);
                                        catchuoi(dtpNgayTra.Text, ref ngaytra);
                                        TimeSpan thoigiandat = new TimeSpan();
                                        thoigiandat = ngaytra - ngaydat;
                                        for (int k = 0; k < thoigiandat.Days; k++)
                                        {
                                            SoSanhNgayDat.Add(ngaydat);
                                            ngaydat = ngaydat.AddDays(1);
                                        }
                                        int        count = 0;
                                        DTO_HoaDon kt    = new DTO_HoaDon();
                                        kt.MaPhong    = table.Tables[0].Rows[i][0].ToString();
                                        kt.MaChiNhanh = table.Tables[0].Rows[i][1].ToString();
                                        DataSet table1 = new DataSet();
                                        table1 = kiemtra.KiemTraNgayPhongDangDuocSuDung(kt);
                                        if (table1.Tables[0].Rows.Count > 0 && table1.Tables.Count > 0)
                                        {
                                            int demhd = table1.Tables[0].Rows.Count;
                                            for (int j = 0; j < demhd; j++)
                                            {
                                                DateTime Ngay1 = new DateTime(int.Parse(table1.Tables[0].Rows[j][8].ToString().Substring(6, 2)), int.Parse(table1.Tables[0].Rows[j][8].ToString().Substring(3, 2)), int.Parse(table1.Tables[0].Rows[j][8].ToString().Substring(0, 2)));
                                                DateTime Ngay2 = new DateTime(int.Parse(table1.Tables[0].Rows[j][9].ToString().Substring(6, 2)), int.Parse(table1.Tables[0].Rows[j][9].ToString().Substring(3, 2)), int.Parse(table1.Tables[0].Rows[j][9].ToString().Substring(0, 2)));

                                                TimeSpan khoangthoigiandat = new TimeSpan();
                                                khoangthoigiandat = Ngay2 - Ngay1;
                                                for (int t = 0; t < khoangthoigiandat.Days; t++)
                                                {
                                                    NgayDaDat.Add(Ngay1);
                                                    Ngay1 = Ngay1.AddDays(1);
                                                }
                                                foreach (DateTime day in NgayDaDat)
                                                {
                                                    foreach (DateTime day1 in SoSanhNgayDat)
                                                    {
                                                        if (day == day1)
                                                        {
                                                            count++;
                                                        }
                                                    }
                                                }
                                                NgayDaDat.Clear();
                                            }
                                        }
                                        if (count == 0)
                                        {
                                            if (table.Tables[0].Rows[i][3].ToString() == "Giường Đơn" && table.Tables[0].Rows[i][4].ToString() == "2")
                                            {
                                                giuongdon2nguoi hienthi = new giuongdon2nguoi();
                                                hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                hienthi.TENVTCHINHANH = MaHD;
                                                pl_phong.Controls.Add(hienthi);
                                                hienthi.Location = vitribandau;
                                                vitribandau.Y   += 295;
                                            }
                                            else
                                            {
                                                if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "2")
                                                {
                                                    giuongdoi2nguoi hienthi = new giuongdoi2nguoi();
                                                    hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                    hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                    hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                    hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                    hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                    hienthi.TENVTCHINHANH = MaHD;
                                                    pl_phong.Controls.Add(hienthi);
                                                    hienthi.Location = vitribandau;
                                                    vitribandau.Y   += 295;
                                                }
                                                else
                                                {
                                                    if (table.Tables[0].Rows[i][3].ToString() == "Giường Đơn" && table.Tables[0].Rows[i][4].ToString() == "4")
                                                    {
                                                        giuongdon4nguoi hienthi = new giuongdon4nguoi();
                                                        hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                        hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                        hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                        hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                        hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                        hienthi.TENVTCHINHANH = MaHD;
                                                        pl_phong.Controls.Add(hienthi);
                                                        hienthi.Location = vitribandau;
                                                        vitribandau.Y   += 295;
                                                    }
                                                    else
                                                    {
                                                        if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "4")
                                                        {
                                                            giuongdoi4nguoi hienthi = new giuongdoi4nguoi();
                                                            hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                            hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                            hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                            hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                            hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                            hienthi.TENVTCHINHANH = MaHD;
                                                            pl_phong.Controls.Add(hienthi);
                                                            hienthi.Location = vitribandau;
                                                            vitribandau.Y   += 295;
                                                        }
                                                        else
                                                        {
                                                            if (table.Tables[0].Rows[i][3].ToString() == "Giường Đôi" && table.Tables[0].Rows[i][4].ToString() == "6")
                                                            {
                                                                giuongdoi6nguoi hienthi = new giuongdoi6nguoi();
                                                                hienthi.MAPHONG       = table.Tables[0].Rows[i][0].ToString();
                                                                hienthi.MACHINHANH    = table.Tables[0].Rows[i][1].ToString();
                                                                hienthi.TENPHONG      = table.Tables[0].Rows[i][2].ToString();
                                                                hienthi.NGAYDATPHONG  = dtpNgayDat.Text;
                                                                hienthi.NGAYTRAPHONG  = dtpNgayTra.Text;
                                                                hienthi.TENVTCHINHANH = MaHD;
                                                                pl_phong.Controls.Add(hienthi);
                                                                hienthi.Location = vitribandau;
                                                                vitribandau.Y   += 295;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        SoSanhNgayDat.Clear();
                    }
                }
            }
        }