public void updateTinhTrangPhong(ePhong pupdate) { IQueryable <Phong> p = db.Phongs.Where(x => x.maPhong.Equals(pupdate.MaPhong)); p.First().tinhTrang = Convert.ToBoolean(pupdate.TinhTrang); p.First().soNguoiHienTai = pupdate.SoNgHienTai; db.SubmitChanges(); }
public int updatePhong(ePhong pupdate) { IQueryable <Phong> p = db.Phongs.Where(x => x.maPhong.Equals(pupdate.MaPhong)); p.First().maLoaiPhong = pupdate.MaLoaiPhong; p.First().ghiChu = pupdate.GhiChu; p.First().tang = pupdate.Tang; db.SubmitChanges(); return(1); }
public ePhong gettP_byMa(string ma) { ePhong phong_ent = new ePhong(); Phong phong = (from x in db.Phongs where x.maPhong.Equals(ma) select x).SingleOrDefault(); phong_ent.MaPhong = phong.maPhong; phong_ent.MaLoaiPhong = phong.maLoaiPhong; phong_ent.TenPhong = phong.tenPhong; phong_ent.Tang = Convert.ToInt32(phong.tang); phong_ent.GhiChu = phong.ghiChu; return(phong_ent); }
public ePhong get_tenP(string tenPhong) { Phong item = (from x in db.Phongs where x.tenPhong.Equals(tenPhong) select x).SingleOrDefault(); ePhong p = new ePhong(); p.MaPhong = item.maPhong; p.TenPhong = item.tenPhong; p.Tang = Convert.ToInt32(item.tang); p.GhiChu = item.ghiChu; p.MaLoaiPhong = item.maLoaiPhong; p.TinhTrang = Convert.ToBoolean(item.tinhTrang); return(p); }
public int insertPhong(ePhong pnew) { Phong ptemp = new Phong(); ptemp.maPhong = ""; ptemp.tenPhong = ""; ptemp.ghiChu = pnew.GhiChu; ptemp.maLoaiPhong = pnew.MaLoaiPhong; ptemp.tang = (pnew.Tang); ptemp.tinhTrang = pnew.TinhTrang; db.Phongs.InsertOnSubmit(ptemp); db.SubmitChanges(); return(1); }
public ePhong getEPhong_byID(string ma) { ePhong p = new ePhong(); Phong ph = db.Phongs.Where(n => n.maPhong.Trim().Equals(ma)).SingleOrDefault(); p.MaPhong = ph.maPhong; p.TenPhong = ph.tenPhong; p.Tang = Convert.ToInt32(ph.tang); p.GhiChu = ph.ghiChu; p.MaLoaiPhong = ph.maLoaiPhong; p.TinhTrang = Convert.ToBoolean(ph.tinhTrang); p.SoNgHienTai = Convert.ToInt32(ph.soNguoiHienTai); return(p); }
public List <ePhong> getallphong() { var litsphong = (from x in db.Phongs select x).ToList(); List <ePhong> ls = new List <ePhong>(); foreach (Phong item in litsphong) { ePhong p = new ePhong(); p.MaPhong = item.maPhong; p.TenPhong = item.tenPhong; p.Tang = Convert.ToInt32(item.tang); p.GhiChu = item.ghiChu; p.MaLoaiPhong = item.maLoaiPhong; p.TinhTrang = Convert.ToBoolean(item.tinhTrang); ls.Add(p); } return(ls); }
public List <ePhong> getLoaiPhong_Trong(string maLoaiPhong, bool tinhTrang) { var litsphong = (from x in db.Phongs where x.maLoaiPhong.Equals(maLoaiPhong) && x.tinhTrang == tinhTrang select x).ToList(); List <ePhong> ls = new List <ePhong>(); foreach (Phong item in litsphong) { ePhong p = new ePhong(); p.MaPhong = item.maPhong; p.TenPhong = item.tenPhong; p.Tang = Convert.ToInt32(item.tang); p.GhiChu = item.ghiChu; p.MaLoaiPhong = item.maLoaiPhong; p.TinhTrang = Convert.ToBoolean(item.tinhTrang); ls.Add(p); } return(ls); }
private void frmTextPhong_Load(object sender, EventArgs e) { if (kieuForm == 2) { PhongBUS pbus = new PhongBUS(); ePhong p_ent = new ePhong(); p_ent = pbus.getEPhong_byID(id_Phong); txtTenPhong.Text = p_ent.TenPhong.Trim(); txtGhiChu.Text = null; bteTang.Text = p_ent.Tang.ToString(); LoaiPhongBUS lpbus = new LoaiPhongBUS(); cbxLoaiPhong.Text = lpbus.getTen_Byma(p_ent.MaLoaiPhong); } else { lbTieuDe.Text = lb_TitleName; cbxLoaiPhong.SelectedIndex = 0; } }
private void Luu_Sua() { if (!CheckNull()) { MessageBox.Show("Chưa Nhập Đủ Thông Tin", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } PhongBUS pbus = new PhongBUS(); ePhong p_ent = new ePhong(); LoaiPhongBUS lpbus = new LoaiPhongBUS(); p_ent.MaPhong = id_Phong; p_ent.TenPhong = txtTenPhong.Text.Trim(); p_ent.GhiChu = txtGhiChu.Text.Trim(); p_ent.Tang = Convert.ToInt32(bteTang.Value.ToString()); p_ent.MaLoaiPhong = lpbus.getma_ByTen(cbxLoaiPhong.Text); if (pbus.CapNhatPhong(p_ent) == 1) { DialogResult ds = MessageBox.Show("Lưu Thành Công, Tiếp Tục ?", "THÔNG BÁO", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (ds == DialogResult.Yes) { //Clear_TextBox(); return; } else { this.Close(); } } else { DialogResult ds = MessageBox.Show("Lưu Thất Bại, Thử Lại ?", "Lỗi", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (ds == DialogResult.Yes) { return; } else { this.Close(); } } }
public void updateTinhTrangPhong(ePhong pupdate) { pdal.updateTinhTrangPhong(pupdate); }
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(); } } } } }
private void btnLuu_Click(object sender, EventArgs e) { ThuePhongBUS tpbus = new ThuePhongBUS(); PhongBUS pbus = new PhongBUS(); LoaiPhongBUS lpbus = new LoaiPhongBUS(); eThuePhong tp = new eThuePhong(); NhanVienBUS nvbus = new NhanVienBUS(); DoanBUS dbus = new DoanBUS(); //Tao Doan eDoan doan = new eDoan(); doan.DiaChi = txtDiaChi.Text.Trim(); doan.MaTruongDoan = txtTruongDoan.Text.Trim(); doan.TenDoan = txtTenDoan.Text.Trim(); doan.Sdt = txtSdtDoan.Text.Trim(); if (dbus.getdoan_sdt(txtSdtDoan.Text.Trim()) == null) { int kqTaoDoan = dbus.insertDoan(doan); } tp.MaNV = nvbus.getmaNV_byEmail(emailNV); tp.MaDoan = dbus.getId_ByTenDoan(txtTenDoan.Text.Trim()); //ma doan int soLuongP = 0; for (int i = 0; i < gridViewLoaiPhong.RowCount; i++) { soLuongP += Convert.ToInt32(gridViewLoaiPhong.GetRowCellValue(i, gridViewLoaiPhong.Columns[3])); } tp.SoLuongPhong = soLuongP; tp.TrangThai = false; TimeSpan gioVao = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); TimeSpan gioRa = new TimeSpan(14, 00, 00); int a = tpbus.insertThuePhong(tp); eChiTietThuePhong cttp = new eChiTietThuePhong(); if (a == 1) { ChiTietThuePhongBUS cttpbus = new ChiTietThuePhongBUS(); foreach (eKhachHang item in ls) { cttp.MaThue = tpbus.getMaThueCuoi(); cttp.MaKhach = item.MaKH; cttp.MaPhong = pbus.maPhong_byTen(item.SoPhong); cttp.NgayRa = Convert.ToDateTime(dtmNgayRa.Text).Date; cttp.NgayVao = DateTime.Now.Date; cttp.GioRa = gioRa; cttp.GioVao = gioVao; cttp.TrangThai = false; cttpbus.insertCTTP(cttp); ePhong p = new ePhong(); p.MaPhong = pbus.maPhong_byTen(item.SoPhong); p.TinhTrang = true; int soPhong = 0; foreach (var kh in ls) { if (kh.SoPhong.Equals(item.SoPhong)) { soPhong++; } } p.SoNgHienTai = soPhong; pbus.updateTinhTrangPhong(p); } MessageBox.Show("Đặt phòng thành công"); this.Close(); } else { MessageBox.Show("Không thành công"); return; } }
public int ThemPhong(ePhong ep) { return(pdal.insertPhong(ep)); }
public int CapNhatPhong(ePhong ep) { return(pdal.updatePhong(ep)); }
private void btnLuu_Click(object sender, EventArgs e) { if (kieuForm == 1) { PhongBUS pbus = new PhongBUS(); LoaiPhongBUS lpbus = new LoaiPhongBUS(); eThuePhong tp = new eThuePhong(); NhanVienBUS nvbus = new NhanVienBUS(); tp.MaNV = nvbus.getmaNV_byEmail(emailNV); tp.SoLuongPhong = 1; tp.TrangThai = false; TimeSpan gioVao = new TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); TimeSpan gioRa = new TimeSpan(14, 00, 00); int a = tpbus.insertThuePhong(tp); eChiTietThuePhong cttp = new eChiTietThuePhong(); if (a == 1) { ChiTietThuePhongBUS cttpbus = new ChiTietThuePhongBUS(); cttp.MaThue = tpbus.getMaThueCuoi(); cttp.MaKhach = maKH; cttp.MaPhong = pbus.maPhong_byTen(TenPhong); cttp.NgayRa = Convert.ToDateTime(dtmNgayRa.Text).Date; cttp.NgayVao = DateTime.Now.Date; cttp.GioRa = gioRa; cttp.GioVao = gioVao; cttp.TrangThai = false; cttp.TienKhac = 0; cttpbus.insertCTTP(cttp); ePhong p = new ePhong(); p.MaPhong = pbus.maPhong_byTen(TenPhong); p.TinhTrang = true; pbus.updateTinhTrangPhong(p); MessageBox.Show("Đặt phòng thành công"); this.Close(); } else { MessageBox.Show("Không thành công"); return; } DichVuBUS dvbus = new DichVuBUS(); eDichVu dv = new eDichVu(); ChiTietDichVuBUS ctdvbus = new ChiTietDichVuBUS(); eChiTetDichVu ctdv = new eChiTetDichVu(); //Thêm chi tiết dịch vụ nếu có đặt dịch vụ if (gridViewCTDV.RowCount > 0) { for (int i = 0; i < gridViewCTDV.RowCount; i++) { ctdv.MaThue = cttp.MaThue; ctdv.MaThue = cttp.MaThue; ctdv.MaKhach = cttp.MaKhach; ctdv.MaPhong = cttp.MaPhong; ctdv.MaDV = gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[0]).ToString(); ctdv.SoLuong = Convert.ToInt32(gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[2]).ToString()); int s = ctdvbus.insertCTDV(ctdv); foreach (eDichVu item in mangDichVu) { //Cập nhật lại số lượng trong bảng dịch vụ if (gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[0]).ToString() == item.MaDV) { dv.MaDV = item.MaDV; dv.TenDV = item.TenDV; dv.DonGia = item.DonGia; dv.SoLuong = (item.SoLuong - Convert.ToInt32(gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[2]))); dvbus.SuaDV(dv); } } } } } if (kieuForm == 2) { //Thêm chi tiết dịch vụ nếu có đặt dịch vụ if (gridViewCTDV.RowCount > 0) { for (int i = 0; i < gridViewCTDV.RowCount; i++) { PhongBUS pbus = new PhongBUS(); ChiTietDichVuBUS ctdvbus = new ChiTietDichVuBUS(); eChiTetDichVu ctdv = new eChiTetDichVu(); ctdv.MaThue = maThue.Trim(); ctdv.MaKhach = maKhachHang; ctdv.MaPhong = pbus.maPhong_byTen(TenPhong); ctdv.MaDV = gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[0]).ToString(); //ctdv.SoLuong = Convert.ToInt32(gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[2]).ToString()); /**Kiểm tra xem mã thuê và mã dịch vụ đó có trong csdl hay chưa * Nếu có thì hãy update lại số lượng * Chưa có thì thêm mới chi tiết dịch vụ**/ if (!ctdvbus.maThue_maDV_CoTonTai(ctdv.MaThue, ctdv.MaDV)) { foreach (var item in ctdvbus.getctdv(ctdv.MaThue, ctdv.MaKhach)) { if (item.MaThue == ctdv.MaThue && item.MaDV == ctdv.MaDV) { ctdv.SoLuong = Convert.ToInt32(gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[2]).ToString()) + item.SoLuong; ctdvbus.updateCTDV(ctdv); } if (item.MaDV == null) { ctdv.SoLuong = Convert.ToInt32(gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[2]).ToString()); int s = ctdvbus.insertCTDV(ctdv); } } } else { ctdv.SoLuong = Convert.ToInt32(gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[2]).ToString()); int s = ctdvbus.insertCTDV(ctdv); } DichVuBUS dvbus = new DichVuBUS(); eDichVu dv = new eDichVu(); foreach (eDichVu item in mangDichVu) { //Cập nhật lại số lượng trong bảng dịch vụ if (gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[0]).ToString() == item.MaDV) { dv.MaDV = item.MaDV; dv.TenDV = item.TenDV; dv.DonGia = item.DonGia; dv.SoLuong = (item.SoLuong - Convert.ToInt32(gridViewCTDV.GetRowCellValue(i, gridViewCTDV.Columns[2]))); dvbus.SuaDV(dv); } } } MessageBox.Show("Cập nhật dịch vụ thành công"); this.Close(); } else { MessageBox.Show("Không có dịch vụ cần cập nhật xin nhập lại"); } } }
private void btnLuu_Click(object sender, EventArgs e) { ThuePhongBUS tpbus = new ThuePhongBUS(); ChiTietThuePhongBUS cttpbus = new ChiTietThuePhongBUS(); ChiTietDichVuBUS ctdvbus = new ChiTietDichVuBUS(); PhongBUS pbus = new PhongBUS(); int s = 0; foreach (eThuePhong item in tpbus.getMaThue(maThue)) { eThuePhong etp = new eThuePhong(); etp.MaNV = item.MaNV; etp.MaDoan = item.MaDoan; etp.SoLuongPhong = item.SoLuongPhong; etp.TrangThai = false; s = tpbus.insertThuePhong(etp); } if (s != 1) { return; } if (s == 1) { foreach (eChiTietThuePhong item in cttpbus.getChiTietThuePhong_By_MaThue_MaPhong(maThue, pbus.maPhong_byTen(TenPhong))) { eChiTietThuePhong ect = new eChiTietThuePhong(); ect.GioRa = item.GioRa; ect.GioVao = item.GioVao; ect.MaKhach = item.MaKhach; ect.MaPhong = cboPhongTrong.SelectedValue.ToString(); ect.NgayRa = item.NgayRa; ect.NgayVao = item.NgayVao; ect.TienKhac = tienkhac; ect.MaThue = tpbus.getMaThueCuoi(); ect.TrangThai = false; ect.GhiChu = cttpbus.getCTTP_By_MaPhong_TrangThai(pbus.maPhong_byTen(TenPhong), false).GhiChu + lblTenPhong.Text + " (" + item.GioVao + " " + item.NgayVao.ToShortDateString() + ")" + " đến " + cboPhongTrong.Text + " (" + DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToShortDateString() + ")"; cttpbus.insertCTTP(ect); } foreach (eChiTietThuePhong item in cttpbus.getChiTietThuePhong_By_MaThue_TrangThai(maThue, 0)) { if (!item.MaPhong.Equals(pbus.maPhong_byTen(TenPhong))) { eChiTietThuePhong ect = new eChiTietThuePhong(); ect.GioRa = item.GioRa; ect.GioVao = item.GioVao; ect.MaKhach = item.MaKhach; ect.MaPhong = item.MaPhong; ect.NgayRa = item.NgayRa; ect.NgayVao = item.NgayVao; ect.MaThue = tpbus.getMaThueCuoi(); ect.TrangThai = false; cttpbus.insertCTTP(ect); } } foreach (eChiTietThuePhong item in cttpbus.getChiTietThuePhong_By_MaThue_TrangThai(maThue, 1)) { eChiTietThuePhong ect = new eChiTietThuePhong(); ect.GioRa = item.GioRa; ect.GioVao = item.GioVao; ect.MaKhach = item.MaKhach; ect.MaPhong = item.MaPhong; ect.NgayRa = item.NgayRa; ect.NgayVao = item.NgayVao; ect.MaThue = tpbus.getMaThueCuoi(); ect.TrangThai = true; cttpbus.insertCTTP(ect); } foreach (eChiTetDichVu item in ctdvbus.getctdv_byMaThue(maThue)) { eChiTetDichVu ctdv = new eChiTetDichVu(); ctdv.MaThue = tpbus.getMaThueCuoi(); ctdv.MaPhong = cboPhongTrong.SelectedValue.ToString(); ctdv.MaKhach = item.MaKhach; ctdv.MaDV = item.MaDV; ctdv.SoLuong = item.SoLuong; ctdvbus.insertCTDV(ctdv); } foreach (var item in cttpbus.getChiTietThuePhong_By_MaThue(maThue)) { if (item.MaPhong.Equals(pbus.maPhong_byTen(TenPhong))) { eChiTietThuePhong ectOld = new eChiTietThuePhong(); ectOld.MaThue = maThue; ectOld.MaPhong = item.MaPhong; //ectOld.MaKhach = cttpbus.getMaKhach_By_MaPhong_TrangThai(ectOld.MaPhong, false); ectOld.MaKhach = item.MaKhach; ectOld.TrangThai = true; ectOld.GhiChu = "Đổi phòng"; cttpbus.updateTrangThaiChiTietThuePhong(ectOld); } else { eChiTietThuePhong ectOld = new eChiTietThuePhong(); ectOld.MaThue = maThue; ectOld.MaPhong = item.MaPhong; ectOld.MaKhach = item.MaKhach; ectOld.TrangThai = true; ectOld.GhiChu = null; cttpbus.updateTrangThaiChiTietThuePhong(ectOld); } } eThuePhong tp = new eThuePhong(); tp.MaThue = maThue; tp.TrangThai = true; tpbus.updateThuePhong(tp); ePhong ep = new ePhong(); ep.MaPhong = pbus.maPhong_byTen(TenPhong); ep.TinhTrang = false; pbus.updateTinhTrangPhong(ep); ePhong newp = new ePhong(); newp.MaPhong = cboPhongTrong.SelectedValue.ToString(); newp.TinhTrang = true; newp.SoNgHienTai = pbus.getEPhong_byID(pbus.maPhong_byTen(TenPhong)).SoNgHienTai; pbus.updateTinhTrangPhong(newp); MessageBox.Show("Thành công"); this.Close(); } else { MessageBox.Show("Không thành công"); return; } }