private void btnTraDoan_Click(object sender, EventArgs e)
        {
            this.Close();
            ThuePhongBUS    tpbus = new ThuePhongBUS();
            frmTraKhachDoan frm   = new frmTraKhachDoan(home, tpbus.getMaDoan_ByMaThue(MaThue));

            frm.ShowDialog();
        }
        public DataTable DataTable_DSTP(ArrayList ds)
        {
            KhachHangBUS        khbus   = new KhachHangBUS();
            PhongBUS            pbus    = new PhongBUS();
            ThuePhongBUS        tpbus   = new ThuePhongBUS();
            DoanBUS             dbus    = new DoanBUS();
            LoaiPhongBUS        lpbus   = new LoaiPhongBUS();
            ChiTietThuePhongBUS cttpbus = new ChiTietThuePhongBUS();
            eHoaDonTienPhong    hdtp    = new eHoaDonTienPhong();
            DataTable           dt      = new DataTable();

            dt.Columns.Add("Tên khách hàng", typeof(string));
            dt.Columns.Add("Tiền phòng", typeof(double));
            dt.Columns.Add("Thời gian vào", typeof(string));
            dt.Columns.Add("Thời gian ra", typeof(string));
            foreach (string item in ds)
            {
                double tienPhong = 0;
                foreach (var cttp in cttpbus.getChiTietThuePhong_By_MaThue(item))
                {
                    tienPhong += hdtp.tinhTienPhong(cttp, lpbus.donGia(pbus.getLoaiPhong_ByID(cttp.MaPhong)), Convert.ToDateTime(cttp.GioVao + " " + cttp.NgayVao.ToShortDateString()), Convert.ToDateTime(cttp.GioRa + " " + cttp.NgayRa.ToShortDateString())) + hdtp.tinhTienPhuThu(cttp, lpbus.donGia(pbus.getLoaiPhong_ByID(cttp.MaPhong))) + cttp.TienKhac;
                }
                if (tpbus.getMaDoan_ByMaThue(item) == null)
                {
                    foreach (var cttp in cttpbus.getChiTietThuePhong_By_MaThue(item))
                    {
                        dt.Rows.Add(khbus.getenKH_ByID(cttp.MaKhach), tienPhong, cttp.GioVao + " " + cttp.NgayVao.ToShortDateString(), cttp.GioRa + " " + cttp.NgayRa.ToShortDateString());
                    }
                }
                else
                {
                    foreach (var cttp in cttpbus.getChiTietThuePhong_By_MaThue(item))
                    {
                        dt.Rows.Add(dbus.getTen_ById(tpbus.getMaDoan_ByMaThue(item)), tienPhong, cttp.GioVao + " " + cttp.NgayVao.ToShortDateString(), cttp.GioRa + " " + cttp.NgayRa.ToShortDateString());
                        break;
                    }
                }
            }
            return(dt);
        }
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (Convert.ToInt32(txtGiamTru.Text) > 10 && Convert.ToInt32(txtGiamTru.Text) < 0)
            {
                MessageBox.Show("Mức giảm giá phải nhỏ hơn 10%");
                txtGiamTru.Focus();
                return;
            }
            if (txtKhachThanhToan.Text.Equals(""))
            {
                MessageBox.Show("Xin hãy nhập số tiền khách thanh toán");
                return;
            }

            TimeSpan            gioHienTai = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            HoaDonTienPhongBUS  hdtpbus    = new HoaDonTienPhongBUS();
            ThuePhongBUS        tpbus      = new ThuePhongBUS();
            ChiTietThuePhongBUS cttpbus    = new ChiTietThuePhongBUS();
            HoaDonDichVuBUS     hddvbus    = new HoaDonDichVuBUS();
            PhongBUS            pbus       = new PhongBUS();

            int a = 0;
            int b = 0;

            if (cttpbus.getChiTietThuePhong_By_MaThue(MaThue).Count < 2)
            {
                eHoaDonTienPhong tt_ent = new eHoaDonTienPhong();
                tt_ent.MaThue    = lblMaThue.Text.Trim();
                tt_ent.NgayLap   = DateTime.Now;
                tt_ent.GioLap    = gioHienTai;
                tt_ent.ThueVAT   = Convert.ToSingle(10 / 10);
                tt_ent.KhuyenMai = Convert.ToSingle((Convert.ToSingle(txtGiamTru.Text) * tienphong));
                a = hdtpbus.insertThanhToan(tt_ent);
            }

            if (tpbus.getMaDoan_ByMaThue(MaThue) != null || ctdvbus.getctdv_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)).Count != 0)
            {
                b++;
            }

            /* Với a = 1 thanh toán khách lẻ
             *  Với b = 1 thanh toán khách đoàn */

            //Update lại trạng thái phòng
            ePhong phong = new ePhong();

            phong.MaPhong   = pbus.maPhong_byTen(TenPhong);
            phong.TinhTrang = false;
            pbus.updateTinhTrangPhong(phong);

            //Update lại trạng thái chi tiết thuê phòng
            eChiTietThuePhong cttp = new eChiTietThuePhong();

            foreach (var item in cttpbus.getChiTietThuePhong_By_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)))
            {
                cttp.MaThue    = MaThue;
                cttp.MaKhach   = item.MaKhach;
                cttp.MaPhong   = item.MaPhong;
                cttp.TrangThai = true;
                cttpbus.updateTrangThaiChiTietThuePhong(cttp);
            }

            //update lại thông tin thuê phòng
            eThuePhong tp = new eThuePhong();

            tp.MaThue    = MaThue;
            tp.TrangThai = true;
            tpbus.updateThuePhong(tp);

            if (a == 1)
            {
                MessageBox.Show("Đã thanh toán thành công");

                KhachHangBUS          khbus     = new KhachHangBUS();
                NhanVienBUS           nvbus     = new NhanVienBUS();
                LoaiPhongBUS          lpbus     = new LoaiPhongBUS();
                HoaDon                bc        = new HoaDon();
                List <eChiTietBaoCao> listphong = new List <eChiTietBaoCao>();
                foreach (var item in cttpbus.getChiTietThuePhong_By_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)))
                {
                    eChiTietBaoCao ctbc = new eChiTietBaoCao();
                    ctbc.tenPhong     = pbus.getTenPhong_ByID(item.MaPhong);
                    ctbc.tenLoaiPhong = lpbus.getTen_Byma(pbus.getLoaiPhong_ByID(item.MaPhong));
                    ctbc.thoiGianNhan = item.GioVao + " " + item.NgayVao.Date.ToShortDateString();
                    ctbc.thoiGianTra  = item.GioRa + " " + item.NgayRa.Date.ToShortDateString();
                    ctbc.tienPhong    = tienvat + tienphong + tiendv + Convert.ToDouble(phuthu);
                    listphong.Add(ctbc);
                    break;
                }

                if (cttpbus.getChiTietThuePhong_By_MaThue(MaThue).Count < 2)
                {
                    foreach (var item in cttpbus.getChiTietThuePhong_By_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)))
                    {
                        bc.tenNV        = nvbus.getenNV_ByID(maNVThanhToan);
                        bc.tenKH        = khbus.getenKH_ByID(item.MaKhach);
                        bc.soHD         = hdtpbus.gemaHD_BymaThue(MaThue); //Cần xem xét lại
                        bc.thoiGianInHD = DateTime.Now.ToLongTimeString() + "   " + DateTime.Now.ToShortDateString();
                    }
                }

                this.Close();
                frmPrint frmp = new frmPrint();
                frmp.InHoaDonInTuReport(bc, listphong.ToList());
                frmp.ShowDialog();
            }

            if (b == 1)
            {
                List <eCTDV> lsctdv = new List <eCTDV>();
                DichVuBUS    dvbus  = new DichVuBUS();
                KhachHangBUS khbus  = new KhachHangBUS();
                NhanVienBUS  nvbus  = new NhanVienBUS();
                LoaiPhongBUS lpbus  = new LoaiPhongBUS();
                HoaDon       bc     = new HoaDon();

                if (ctdvbus.getctdv_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)) != null)
                {
                    foreach (var item in ctdvbus.getctdv_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)))
                    {
                        eHoaDonDichVu hddv = new eHoaDonDichVu();
                        hddv.MaHDDV  = (DateTime.Now.Day).ToString() + (DateTime.Now.Month).ToString() + (DateTime.Now.Year).ToString() + item.MaThue + item.MaKhach + item.MaPhong;
                        hddv.MaThue  = MaThue;
                        hddv.NgayLap = DateTime.Now.Date;
                        hddv.GioLap  = gioHienTai;
                        hddv.MaKH    = item.MaKhach;
                        hddv.MaPhong = item.MaPhong;
                        hddvbus.insertThanhToanDV(hddv);
                        break;
                    }
                }

                foreach (var item in ctdvbus.getctdv_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)))
                {
                    eCTDV ctdv = new eCTDV();
                    ctdv.TenDV   = dvbus.getTenDV_byID(item.MaDV);
                    ctdv.SoLuong = item.SoLuong;
                    ctdv.DonGia  = dvbus.getDonGia_byID(item.MaDV);
                    lsctdv.Add(ctdv);
                }

                foreach (var item in cttpbus.getChiTietThuePhong_By_MaThue_MaPhong(MaThue, pbus.maPhong_byTen(TenPhong)))
                {
                    if (item.MaPhong.Equals(pbus.maPhong_byTen(TenPhong)))
                    {
                        bc.tenNV        = nvbus.getenNV_ByID(maNVThanhToan);
                        bc.tenKH        = khbus.getenKH_ByID(item.MaKhach);
                        bc.soHD         = hddvbus.gemaHD_BymaThue_maPhong(MaThue, item.MaPhong);
                        bc.thoiGianInHD = DateTime.Now.ToLongTimeString() + "   " + DateTime.Now.ToShortDateString();
                        bc.tenPhong     = pbus.getTenPhong_ByID(item.MaPhong);
                    }
                }

                frmPrint frmInDV = new frmPrint();
                frmInDV.InHoaDonInDichVuTuReport(bc, lsctdv.ToList());
                frmInDV.ShowDialog();
                this.Close();
            }
        }
        //Load giao diện các phòng trống và phòng có chứa khách hàng
        public void TaoGiaoDienPhong(List <ePhong> soPhong, List <ePhong> phongTrong, List <ePhong> coKhach, string title)
        {
            //Tạo ra một flowLayoutPanel để chứa các panel
            PhongBUS        pbus             = new PhongBUS();
            FlowLayoutPanel flowLayoutPanel3 = new FlowLayoutPanel();

            flowLayoutPanel3.AutoSize     = true;
            flowLayoutPanel3.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            flowLayoutPanel1.Controls.Add(flowLayoutPanel3);
            Label text = new Label();

            text.Size      = new Size(1850, 30);
            text.TextAlign = ContentAlignment.TopCenter;
            text.Text      = title;
            flowLayoutPanel3.Controls.Add(text);
            //Tạo các label để chứa thông tin, màu sắc thể hiện các phòng
            foreach (var item in soPhong)
            {
                DevExpress.XtraEditors.PanelControl P0001 = new DevExpress.XtraEditors.PanelControl();
                Label lbl = new Label();
                flowLayoutPanel3.Controls.Add(P0001);
                P0001.Appearance.Options.UseBackColor = true;
                P0001.BorderStyle = DevExpress.XtraEditors.Controls.BorderStyles.Style3D;
                P0001.Controls.Add(lbl);
                P0001.Location = new Point(3, 3);
                P0001.Name     = item.MaPhong;
                P0001.Size     = new Size(170, 150);
                lbl.Font       = new Font("Tahoma", 9F);
                lbl.Dock       = DockStyle.Fill;
                lbl.Size       = new Size(150, 120);
                lbl.TextAlign  = ContentAlignment.TopCenter;
            }
            //Load thông tin của phòng trống vào từng label
            foreach (var item in phongTrong)
            {
                foreach (var pnl in flowLayoutPanel3.Controls.OfType <DevExpress.XtraEditors.PanelControl>())
                {
                    if (pnl.Name.Equals(item.MaPhong.Trim()))
                    {
                        pnl.BackColor = Color.LawnGreen;
                        foreach (var lbl in pnl.Controls.OfType <Label>())
                        {
                            string ma = item.MaPhong.Substring(3, 5);
                            lbl.BackColor        = Color.LawnGreen;
                            lbl.Text             = "Phòng " + Convert.ToInt32(ma);
                            lbl.MouseDown       += new MouseEventHandler(lbl_ClickTP);
                            lbl.ContextMenuStrip = cmnstrpSanSang;
                        }
                    }
                }
            }
            //Load thông tin của phòng đang có khách vào từng label
            foreach (var item in coKhach)
            {
                foreach (var pnl in flowLayoutPanel3.Controls.OfType <DevExpress.XtraEditors.PanelControl>())
                {
                    if (pnl.Name.Equals(item.MaPhong.Trim()))
                    {
                        pnl.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
                        foreach (var lbl in pnl.Controls.OfType <Label>())
                        {
                            lbl.BackColor = Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(128)))));
                            string ma = item.MaPhong.Substring(3, 5);
                            ChiTietThuePhongBUS cttpbus = new ChiTietThuePhongBUS();
                            DoanBUS             dbus    = new DoanBUS();
                            ThuePhongBUS        tpbus   = new ThuePhongBUS();
                            foreach (var thuePhong in tpbus.getMaThue(cttpbus.getMaThue_By_MaPhong_TrangThai(item.MaPhong, false)))
                            {
                                if (thuePhong.MaDoan == null)
                                {
                                    lbl.Text = "Phòng " + Convert.ToInt32(ma);
                                }
                                else
                                {
                                    string tendoan  = dbus.getTen_ById(tpbus.getMaDoan_ByMaThue(cttpbus.getMaThue_By_MaPhong_TrangThai(item.MaPhong, false)));
                                    string tenPhong = "Phòng " + Convert.ToInt32(ma);
                                    lbl.Text = tenPhong + "\n\n\rĐoàn: " + tendoan;
                                }
                            }
                            lbl.MouseDown       += new MouseEventHandler(lblred_Click);
                            lbl.MouseHover      += new EventHandler(lblred_MouseHover);
                            lbl.ContextMenuStrip = cmnstrpCoKhach;
                        }
                    }
                }
            }
        }