Example #1
0
        private void btnIn_Click(object sender, EventArgs e)
        {
            HoaDon              bc      = new HoaDon();
            List <eKhachHang>   listkh  = new List <eKhachHang>();
            ChiTietThuePhongBUS cttpbus = new ChiTietThuePhongBUS();
            PhongBUS            pbus    = new PhongBUS();

            for (int i = 0; i < gridViewLuongKhach.RowCount; i++)
            {
                eKhachHang kh = new eKhachHang();
                kh.SoPhong = gridViewLuongKhach.GetRowCellValue(i, gridViewLuongKhach.Columns[0]).ToString();
                kh.TenKH   = gridViewLuongKhach.GetRowCellValue(i, gridViewLuongKhach.Columns[1]).ToString();
                kh.SoCMND  = gridViewLuongKhach.GetRowCellValue(i, gridViewLuongKhach.Columns[2]).ToString();
                kh.SoDT    = gridViewLuongKhach.GetRowCellValue(i, gridViewLuongKhach.Columns[3]).ToString();
                string tgian = cttpbus.getCTTP_By_MaPhong_TrangThai(pbus.maPhong_byTen(kh.SoPhong), false).GioVao + "  " + cttpbus.getCTTP_By_MaPhong_TrangThai(pbus.maPhong_byTen(kh.SoPhong), false).NgayVao.ToShortDateString();
                kh.ThoiGianNhanPhong = tgian;
                listkh.Add(kh);
            }
            bc.thoiGianInHD = DateTime.Now.ToLongTimeString() + "   " + DateTime.Now.ToShortDateString();
            frmPrint frmInBCDV = new frmPrint();

            frmInBCDV.InBaoCaoInLuongKhachTuReport(bc, listkh.ToList());
            frmInBCDV.ShowDialog();
            this.Close();
        }
        private void btnIn_Click(object sender, EventArgs e)
        {
            HoaDon bc = new HoaDon();
            List <eBC_DoanhThuDV> listbcdv = new List <eBC_DoanhThuDV>();

            for (int i = 0; i < gridViewTienDV.RowCount; i++)
            {
                eBC_DoanhThuDV bcdv = new eBC_DoanhThuDV();
                bcdv.TenPhong = gridViewTienDV.GetRowCellValue(i, gridViewTienDV.Columns[0]).ToString();
                bcdv.TenKH    = gridViewTienDV.GetRowCellValue(i, gridViewTienDV.Columns[1]).ToString();
                bcdv.TienDV   = Convert.ToDouble(gridViewTienDV.GetRowCellValue(i, gridViewTienDV.Columns[2]));
                bcdv.NgayLap  = Convert.ToDateTime(gridViewTienDV.GetRowCellValue(i, gridViewTienDV.Columns[3]));
                listbcdv.Add(bcdv);
            }

            bc.loai         = cboNgayThang.Text;
            bc.thoiGianInHD = DateTime.Now.ToLongTimeString() + "   " + DateTime.Now.ToShortDateString();
            frmPrint frmInBCDV = new frmPrint();

            frmInBCDV.InBaoCaoInDichVuTuReport(bc, listbcdv.ToList());
            frmInBCDV.ShowDialog();
            this.Close();
        }
        private void btnIn_Click(object sender, EventArgs e)
        {
            HoaDon bc = new HoaDon();
            List <eBC_TienPhong> listbctp = new List <eBC_TienPhong>();

            for (int i = 0; i < gridViewTienPhong.RowCount; i++)
            {
                eBC_TienPhong bctp = new eBC_TienPhong();
                bctp.TenKH     = gridViewTienPhong.GetRowCellValue(i, gridViewTienPhong.Columns[0]).ToString();
                bctp.TienPhong = Convert.ToDouble(gridViewTienPhong.GetRowCellValue(i, gridViewTienPhong.Columns[1]));
                bctp.TgianVao  = Convert.ToDateTime(gridViewTienPhong.GetRowCellValue(i, gridViewTienPhong.Columns[2]));
                bctp.TgianRa   = Convert.ToDateTime(gridViewTienPhong.GetRowCellValue(i, gridViewTienPhong.Columns[3]));
                listbctp.Add(bctp);
            }

            bc.loai         = cboNgayThang.Text;
            bc.thoiGianInHD = DateTime.Now.ToLongTimeString() + "   " + DateTime.Now.ToShortDateString();
            bc.tenNV        = cboNhanVien.Text;
            frmPrint frmInBCDV = new frmPrint();

            frmInBCDV.InBaoCaoInTienPhongTuReport(bc, listbctp.ToList());
            frmInBCDV.ShowDialog();
            this.Close();
        }
        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();
            }
        }
        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            ChiTietThuePhongBUS cttpbus    = new ChiTietThuePhongBUS();
            ThuePhongBUS        tpbus      = new ThuePhongBUS();
            DoanBUS             dbus       = new DoanBUS();
            PhongBUS            pbus       = new PhongBUS();
            HoaDonTienPhongBUS  hdtpbus    = new HoaDonTienPhongBUS();
            TimeSpan            gioHienTai = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
            eHoaDonTienPhong    tt_ent     = new eHoaDonTienPhong();

            tt_ent.MaThue    = tpbus.getMaThue_ByMaDoan(dbus.getId_ByTenDoan(txtTenDoan.Text), 0);
            tt_ent.NgayLap   = DateTime.Now;
            tt_ent.GioLap    = gioHienTai;
            tt_ent.ThueVAT   = Convert.ToSingle(txtThueVAT.Text);
            tt_ent.KhuyenMai = Convert.ToSingle(txtKhuyenMai.Text);
            int a = hdtpbus.insertThanhToan(tt_ent);

            if (a == 1)
            {
                foreach (var item in cttpbus.getChiTietThuePhong_By_MaThue(tpbus.getMaThue_ByMaDoan(dbus.getId_ByTenDoan(txtTenDoan.Text), 0)))
                {
                    eChiTietThuePhong ectOld = new eChiTietThuePhong();
                    ectOld.MaThue    = tpbus.getMaThue_ByMaDoan(dbus.getId_ByTenDoan(txtTenDoan.Text), 0);
                    ectOld.MaPhong   = item.MaPhong;
                    ectOld.MaKhach   = item.MaKhach;
                    ectOld.NgayRa    = DateTime.Now.Date;
                    ectOld.GioRa     = gioHienTai;
                    ectOld.TrangThai = true;
                    cttpbus.updateChiTietThuePhong(ectOld);

                    ePhong newp = new ePhong();
                    newp.MaPhong     = item.MaPhong;
                    newp.TinhTrang   = false;
                    newp.SoNgHienTai = 0;
                    pbus.updateTinhTrangPhong(newp);
                }

                eThuePhong tp = new eThuePhong();
                tp.MaThue    = tpbus.getMaThue_ByMaDoan(dbus.getId_ByTenDoan(txtTenDoan.Text), 0);
                tp.TrangThai = true;
                tpbus.updateThuePhong(tp);

                MessageBox.Show("Thanh toán thành công");

                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_TrangThai(tp.MaThue, 1))
                {
                    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();
                    eHoaDonTienPhong hdtp       = new eHoaDonTienPhong();
                    double           tienPhong  = Convert.ToDouble(hdtp.tinhTienPhong(item, lpbus.donGia(pbus.getLoaiPhong_ByID(item.MaPhong)), Convert.ToDateTime(item.GioVao + "   " + item.NgayVao.ToShortDateString()), Convert.ToDateTime(DateTime.Now.ToLongTimeString() + "   " + DateTime.Now.ToShortDateString())));
                    double           tienPhuThu = Convert.ToDouble(hdtp.tinhTienPhuThu(item, lpbus.donGia(pbus.getLoaiPhong_ByID(item.MaPhong))));
                    ctbc.tienPhong = tienPhong + tienPhuThu;
                    listphong.Add(ctbc);
                }

                for (int i = 0; i < listphong.Count; i++)
                {
                    for (int j = 1; j < listphong.Count; j++)
                    {
                        if (i == j)
                        {
                            continue;
                        }
                        if (listphong[i].tenPhong.Equals(listphong[j].tenPhong))
                        {
                            listphong.RemoveAt(i);
                        }
                    }
                }

                foreach (var item in tpbus.getMaThue(tp.MaThue))
                {
                    bc.tenNV        = nvbus.getenNV_ByID(maNVThanhToan);
                    bc.tenKH        = dbus.getTen_ById(item.MaDoan);
                    bc.soHD         = hdtpbus.gemaHD_BymaThue(tp.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();

                ChiTietDichVuBUS ctdvbus = new ChiTietDichVuBUS();
                HoaDonDichVuBUS  hddvbus = new HoaDonDichVuBUS();
                DichVuBUS        dvbus   = new DichVuBUS();
                KhachHangBUS     khbus   = new KhachHangBUS();
                if (ctdvbus.getctdv_byMaThue(tt_ent.MaThue) != null)
                {
                    foreach (var item in ctdvbus.getctdv_byMaThue(tt_ent.MaThue))
                    {
                        if (hddvbus.kiemTraTonTai(item.MaThue, item.MaPhong) == false)
                        {
                            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  = item.MaThue;
                            hddv.MaKH    = item.MaKhach;
                            hddv.MaPhong = item.MaPhong;
                            hddv.NgayLap = DateTime.Now.Date;
                            hddv.GioLap  = gioHienTai;
                            hddvbus.insertThanhToanDV(hddv);
                            List <eCTDV> lsctdv = new List <eCTDV>();
                            foreach (eChiTetDichVu dv in ctdvbus.getctdv_MaThue_MaPhong(item.MaThue, item.MaPhong))
                            {
                                eCTDV ctdv = new eCTDV();
                                ctdv.TenDV   = dvbus.getTenDV_byID(dv.MaDV);
                                ctdv.SoLuong = dv.SoLuong;
                                ctdv.DonGia  = dvbus.getDonGia_byID(dv.MaDV);
                                lsctdv.Add(ctdv);
                            }

                            bc.tenNV        = nvbus.getenNV_ByID(maNVThanhToan);
                            bc.tenKH        = khbus.getenKH_ByID(item.MaKhach);
                            bc.soHD         = hddvbus.gemaHD_BymaThue_maPhong(item.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();
                        }
                    }
                }
            }
        }