public void ThemHopDong(DTOHopDong dtoHD) { using (PhongTroDBDataContext pt = new PhongTroDBDataContext()) { pt.HopDong_Them(dtoHD.ngaythue, dtoHD.ngaytra, dtoHD.ngaylamhopdong, dtoHD.tiencoc, dtoHD.giathue, dtoHD.chisodien, dtoHD.chisonuoc, dtoHD.ghichu); pt.SubmitChanges(); } BAL_ThuePhong balTP = new BAL_ThuePhong(); BAL_Khach balK = new BAL_Khach(); foreach (Int64 makhach in balTP.DanhSachMaKhachTheoMaHopDong(dtoHD.mahopdong)) { balK.CapNhatStatusTungKhach(makhach); } }
public DTOHopDong HopDongHienTai(int MaPhong) { BAL_ThuePhong balTP = new BAL_ThuePhong(); DTOHopDong dtoHDHT = new DTOHopDong(); foreach (Int64 MaHopDong in balTP.DanhSachMaHopDongTheoMaPhong(MaPhong)) { DTOHopDong dtoHD = DetailHopDong(MaHopDong); if (dtoHD.status == true) { dtoHDHT = dtoHD; } } return(dtoHDHT); }
public List <DTOHopDong> HopDongTrongTuongLai(int MaPhong) { BAL_ThuePhong balTP = new BAL_ThuePhong(); List <DTOHopDong> liDtoHDTL = new List <DTOHopDong>(); foreach (Int64 MaHopDong in balTP.DanhSachMaHopDongTheoMaPhong(MaPhong)) { DTOHopDong dtoHD = DetailHopDong(MaHopDong); if (dtoHD.ngaythue.Date > DateTime.Now.Date) { liDtoHDTL.Add(dtoHD); } } return(liDtoHDTL); }
/// <summary> /// True:Hợp lệ, không trùng hợp đồng khác. False:Không hợp lệ, có trùng ngày với hợp đồng khác /// </summary> /// <param name="hdCheck"></param> /// <param name="lihd">Bao gồm hd hiện tại và tương lai của phòng.</param> /// <returns></returns> public bool KiemTraHopLeHopDong(DTOHopDong dtoHDCheck, List <DTOHopDong> liDtoHD) { bool result = false; foreach (DTOHopDong dtoHD in liDtoHD) { if (dtoHDCheck.ngaythue.Date < dtoHD.ngaythue.Date && dtoHDCheck.ngaytra != null && Convert.ToDateTime(dtoHDCheck.ngaytra).Date < dtoHD.ngaythue.Date) { result = true; } if (dtoHDCheck.ngaythue.Date > dtoHD.ngaythue.Date && dtoHD.ngaytra != null && dtoHDCheck.ngaythue.Date > Convert.ToDateTime(dtoHD.ngaytra).Date) { result = true; } } return(result); }
private void FormChuyenPhong_Load(object sender, EventArgs e) { lblPhong.Text = "[ " + balP.DetailPhong(MaPhong).tenphong + " ]"; //Tải hợp đồng hiện tại và tương lai của phòng dgvHopDong.Rows.Clear(); foreach (Int64 MaHopDong in balTP.DanhSachMaHopDongTheoMaPhong(MaPhong)) { DTOHopDong hd = balHD.DetailHopDong(MaHopDong); string GiaTri = "Đã hết hạn"; if (balHD.GiaTriHopDongVoiNgayHienTai(MaHopDong) == 0) { GiaTri = "Đang sử dụng"; } if (balHD.GiaTriHopDongVoiNgayHienTai(MaHopDong) == 1) { GiaTri = "Chưa đến ngày dùng"; } dgvHopDong.Rows.Add("Xem", "Sửa", GiaTri, MaHopDong, hd.ngaylamhopdong, hd.ngaythue, hd.ngaytra, balK.DetailKhach(balTP.MaChuPhong(MaPhong, MaHopDong)).tenkhach); } }
/// <summary> /// -1:Hết hạn 0:Còn hạn 1:Tương lai /// </summary> /// <param name="mahopdong"></param> /// <returns></returns> public int GiaTriHopDongVoiNgayHienTai(Int64 MaHopDong) { int GiaTri = -1; DTOHopDong dtoHD = GetAll().Where(h => h.mahopdong == MaHopDong).SingleOrDefault(); if (dtoHD.ngaythue.Date > DateTime.Now.Date) { GiaTri = 1; } else { if (dtoHD.ngaytra == null || Convert.ToDateTime(dtoHD.ngaytra).Date >= DateTime.Now.Date) { GiaTri = 0; } else if (Convert.ToDateTime(dtoHD.ngaytra).Date < DateTime.Now.Date) { GiaTri = -1; } } return(GiaTri); }
public List <DTOHopDong> GetAll() { using (PhongTroDBDataContext pt = new PhongTroDBDataContext()) { List <DTOHopDong> liDtoHD = new List <DTOHopDong>(); foreach (HopDong hd in pt.HopDongs) { DTOHopDong dtoHD = new DTOHopDong(); dtoHD.mahopdong = hd.MaHopDong; dtoHD.ngaythue = hd.NgayThue; dtoHD.ngaytra = hd.NgayTra; dtoHD.ngaylamhopdong = hd.NgayLamHopDong; dtoHD.tiencoc = hd.TienCoc; dtoHD.giathue = hd.GiaThue; dtoHD.chisodien = hd.ChiSoDien; dtoHD.chisonuoc = hd.ChiSoNuoc; dtoHD.ghichu = hd.GhiChu; dtoHD.status = hd.Status; liDtoHD.Add(dtoHD); } return(liDtoHD); } }
private void LoadThongTin() { dgvKhach.Rows.Clear(); dgvCuocPhi.Rows.Clear(); //Thêm if (state == 0) { //Trường hợp chọn Thêm Hợp đồng từ FormChinh if (maphong == -1) { cboPhong.Enabled = true; } //Trường hợp Thêm Hợp đồng từ UCHopDong else { cboPhong.Text = balP.DetailPhong(maphong).tenphong; cboPhong.SelectedValue = maphong; cboPhong.Enabled = false; } chbNgayLamHD.Enabled = chbNgayTra.Enabled = true; dtpNgayLap.Enabled = dtpNgayThue.Enabled = dtpNgayTra.Enabled = true; nmrGiaThue.Enabled = nmrTienCoc.Enabled = nmrSoDien.Enabled = nmrSoNuoc.Enabled = true; txtGhiChu.ReadOnly = false; cboKhachThue.Enabled = true; btnThemKhach.Visible = btnThemCuocPhi.Visible = true; btnClear.Visible = btnLuuHD.Visible = true; DTOPhong p = balP.DetailPhong(Convert.ToInt32(cboPhong.SelectedValue)); nmrGiaThue.Value = balLP.DetailLoaiPhong(p.maloaiphong).giathue; nmrSoDien.Value = Convert.ToInt64(balCST.ChiSoMoiNhat(p.maphong).chisodien); nmrSoNuoc.Value = Convert.ToInt64(balCST.ChiSoMoiNhat(p.maphong).chisonuoc); } //Sửa - Xem else { DTOHopDong hd = balHD.DetailHopDong(mahopdong); if (hd.ngaylamhopdong == null) { chbNgayLamHD.Checked = true; } else { dtpNgayLap.Value = hd.ngaylamhopdong.GetValueOrDefault(); } dtpNgayThue.Value = hd.ngaythue; if (hd.ngaytra == null) { chbNgayTra.Checked = true; } else { dtpNgayTra.Value = hd.ngaytra.GetValueOrDefault(); } nmrTienCoc.Value = Convert.ToInt64(hd.tiencoc); nmrGiaThue.Value = Convert.ToInt64(hd.giathue); nmrSoDien.Value = Convert.ToInt64(hd.chisodien); nmrSoNuoc.Value = Convert.ToInt64(hd.chisonuoc); txtGhiChu.Text = hd.ghichu; cboPhong.SelectedValue = maphong; DataTable dtK = new DataTable(); dtK.Columns.Add("makhach", typeof(Int64)); dtK.Columns.Add("tenkhach", typeof(string)); foreach (Int64 makhach in balTP.DanhSachMaKhachTheoMaHopDong(hd.mahopdong)) { //Taỉ ảnh if (balK.DetailKhach(makhach).hinh != null) { Bitmap img = new Bitmap(Image.FromFile(balK.DetailKhach(makhach).hinh), new Size(60, 70)); dgvKhach.Rows.Add(img, balK.DetailKhach(makhach).tenkhach, "Xem", "Xóa", makhach); } else { dgvKhach.Rows.Add(null, balK.DetailKhach(makhach).tenkhach, "Xem", "Xóa", makhach); } //Tải dữ liệu cho combobox Khách đại diện DataRow dr = dtK.NewRow(); dr["makhach"] = makhach; dr["tenkhach"] = balK.DetailKhach(makhach).tenkhach; dtK.Rows.Add(dr); } cboKhachThue.DisplayMember = "tenkhach"; cboKhachThue.ValueMember = "makhach"; cboKhachThue.DataSource = dtK; cboKhachThue.SelectedValue = balTP.MaChuPhong(maphong, mahopdong); foreach (DTOChiuCuocPhi ccp in balCCP.ChiuCuocPhiTuMaHopDong(hd.mahopdong)) { dgvCuocPhi.Rows.Add(balCuoc.DetailCuocPhi(ccp.macuocphi).tencuocphi, ccp.soluong, balCuoc.DetailCuocPhi(ccp.macuocphi).giacuocphi, "Xem", "Xóa"); } //Sửa if (state == -1) { cboPhong.Enabled = false; chbNgayLamHD.Enabled = chbNgayTra.Enabled = true; dtpNgayLap.Enabled = dtpNgayThue.Enabled = dtpNgayTra.Enabled = true; nmrGiaThue.Enabled = nmrTienCoc.Enabled = nmrSoDien.Enabled = nmrSoNuoc.Enabled = true; txtGhiChu.ReadOnly = false; cboKhachThue.Enabled = true; btnThemKhach.Visible = btnThemCuocPhi.Visible = true; btnClear.Visible = btnLuuHD.Visible = true; } //Xem else { cboPhong.Enabled = false; chbNgayLamHD.Enabled = chbNgayTra.Enabled = false; dtpNgayLap.Enabled = dtpNgayThue.Enabled = dtpNgayTra.Enabled = false; nmrGiaThue.Enabled = nmrTienCoc.Enabled = nmrSoDien.Enabled = nmrSoNuoc.Enabled = false; txtGhiChu.ReadOnly = true; cboKhachThue.Enabled = false; btnThemKhach.Visible = btnThemCuocPhi.Visible = false; btnClear.Visible = btnLuuHD.Visible = false; } } }
private void btnLuuHD_Click(object sender, EventArgs e) { DTOHopDong hd = new DTOHopDong(); hd.ngaythue = dtpNgayThue.Value; if (chbNgayTra.Checked) { hd.ngaytra = null; } else { hd.ngaytra = dtpNgayTra.Value; } if (chbNgayLamHD.Checked) { hd.ngaylamhopdong = null; } else { hd.ngaylamhopdong = dtpNgayLap.Value; } hd.tiencoc = Convert.ToInt64(nmrTienCoc.Value); hd.giathue = Convert.ToInt64(nmrGiaThue.Value); hd.chisodien = Convert.ToInt64(nmrSoDien.Value); hd.chisonuoc = Convert.ToInt64(nmrSoNuoc.Value); if (txtGhiChu.Text.Trim() == string.Empty) { hd.ghichu = null; } else { hd.ghichu = txtGhiChu.Text.Trim(); } try { //Thêm Hợp đồng. if (state == 0) { if (balHD.KiemTraHopLeHopDong(hd, balHD.HopDongHienTaiVaTuongLai(Convert.ToInt32(cboPhong.SelectedValue))) == false) { MessageBox.Show("Với Ngày Thuê như trên thì Phòng không trống.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); } else { balHD.ThemHopDong(hd); #region Chỉ số tháng của phòng ngay ngày thuê hợp đồng. DTOChiSoThang cst = new DTOChiSoThang() { maphong = Convert.ToInt32(cboPhong.SelectedValue), ngaycapnhat = hd.ngaythue, chisodien = Convert.ToInt64(nmrSoDien.Value), chisonuoc = Convert.ToInt64(nmrSoNuoc.Value) }; //Có rồi thì cập nhật. if (balCST.CheckCST(cst.maphong, cst.ngaycapnhat)) { balCST.SuaChiSoThang(cst); } //Chưa có thì thêm mới. else { balCST.ThemChiSoThang(cst); } #endregion //Lấy mã hợp đồng. hd.mahopdong = balHD.MaHopDongSearchByAll(hd); #region Thêm Chịu cước phí. foreach (DataGridViewRow dgr in dgvCuocPhi.Rows) { DTOChiuCuocPhi ccp = new DTOChiuCuocPhi() { mahopdong = hd.mahopdong, macuocphi = Convert.ToInt32(dgr.Cells["macuocphi"].Value), soluong = Convert.ToInt32(dgr.Cells["soluong"].Value) }; balCCP.ThemChiuCuocPhi(ccp); } #endregion #region Thêm Thuê Phòng. foreach (DataGridViewRow dgr in dgvKhach.Rows) { DTOThuePhong dtoTP = new DTOThuePhong() { maphong = Convert.ToInt32(cboPhong.SelectedValue.ToString()), makhach = Convert.ToInt64(dgr.Cells["makhach"].Value), mahopdong = hd.mahopdong }; if (Convert.ToInt64(cboKhachThue.SelectedValue.ToString()) == dtoTP.makhach) { dtoTP.chuphong = true; } else { dtoTP.chuphong = false; } balTP.ThemThuePhong(dtoTP); } #endregion MessageBox.Show("Tạo Hợp đồng mới thành công.", "Thông báo"); } } //Sửa Hợp đồng. else if (state == -1) { hd.mahopdong = mahopdong; balHD.SuaHopDong(hd); #region Chỉ số tháng của phòng ngay ngày thuê hợp đồng. DTOChiSoThang cst = new DTOChiSoThang() { maphong = Convert.ToInt32(cboPhong.SelectedValue), ngaycapnhat = hd.ngaythue, chisodien = Convert.ToInt64(nmrSoDien.Value), chisonuoc = Convert.ToInt64(nmrSoNuoc.Value) }; //Có rồi thì cập nhật. if (balCST.CheckCST(cst.maphong, cst.ngaycapnhat)) { balCST.SuaChiSoThang(cst); } //Chưa có thì thêm mới. else { balCST.ThemChiSoThang(cst); } #endregion #region Sửa Chịu cước phí. List <DTOChiuCuocPhi> liCCP_Moi = new List <DTOChiuCuocPhi>(); foreach (DataGridViewRow dgr in dgvCuocPhi.Rows) { DTOChiuCuocPhi ccp = new DTOChiuCuocPhi() { mahopdong = hd.mahopdong, macuocphi = Convert.ToInt32(dgr.Cells["macuocphi"].Value), soluong = Convert.ToInt32(dgr.Cells["soluong"].Value) }; liCCP_Moi.Add(ccp); } //Lấy danh sách chịu cước phí cũ. List <DTOChiuCuocPhi> liCCP_Cu = balCCP.ChiuCuocPhiTuMaHopDong(hd.mahopdong); //So sánh list mới và cũ. [Chưa có thì thêm mới-Có thì cập nhật] foreach (DTOChiuCuocPhi ccp_moi in liCCP_Moi) { bool tontai = false; foreach (DTOChiuCuocPhi ccp_cu in liCCP_Cu) { if (ccp_moi.macuocphi == ccp_cu.macuocphi) { tontai = true; break; } } if (tontai == true) { balCCP.SuaChiuCuocPhi(ccp_moi); } else { balCCP.ThemChiuCuocPhi(ccp_moi); } } //So sánh list cũ và mới. Nếu mới không có thì xóa của cũ. foreach (DTOChiuCuocPhi ccp_cu in liCCP_Cu) { bool tontai = false; foreach (DTOChiuCuocPhi ccp_moi in liCCP_Moi) { if (ccp_cu.macuocphi == ccp_moi.macuocphi) { tontai = true; break; } } if (tontai == false) { balCCP.XoaChiuCuocPhi(ccp_cu); } } #endregion #region Sửa Thuê Phòng. List <DTOThuePhong> liTP_Moi = new List <DTOThuePhong>(); foreach (DataGridViewRow dgr in dgvKhach.Rows) { DTOThuePhong dtoTP = new DTOThuePhong() { maphong = Convert.ToInt32(cboPhong.SelectedValue.ToString()), makhach = Convert.ToInt64(dgr.Cells["makhach"].Value), mahopdong = hd.mahopdong }; if (Convert.ToInt64(cboKhachThue.SelectedValue.ToString()) == dtoTP.makhach) { dtoTP.chuphong = true; } else { dtoTP.chuphong = false; } liTP_Moi.Add(dtoTP); } //Thực hiện giống Chịu Cước Phí List <DTOThuePhong> liTP_Cu = balTP.ThuePhongTuMaHopDong(hd.mahopdong); foreach (DTOThuePhong tp_moi in liTP_Moi) { bool tontai = false; foreach (DTOThuePhong tp_cu in liTP_Cu) { if (tp_moi.mahopdong == tp_cu.mahopdong && tp_moi.maphong == tp_cu.maphong && tp_moi.makhach == tp_cu.makhach) { tontai = true; break; } } if (tontai == true) { balTP.SuaThuePhong(tp_moi); } else { balTP.ThemThuePhong(tp_moi); } } foreach (DTOThuePhong tp_cu in liTP_Cu) { bool tontai = false; foreach (DTOThuePhong tp_moi in liTP_Moi) { if (tp_moi.mahopdong == tp_cu.mahopdong && tp_moi.maphong == tp_cu.maphong && tp_moi.makhach == tp_cu.makhach) { tontai = true; break; } } if (tontai == false) { balTP.XoaThuePhong(tp_cu); } } #endregion MessageBox.Show("Cập nhật thông tin Hợp đồng thành công!", "Thông báo"); } } catch (Exception ex) { MessageBox.Show("Thao tác thất bại.\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
public Int64 MaHopDongSearchByAll(DTOHopDong dtoHD) { if (dtoHD.ngaylamhopdong == null) { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& Convert.ToDateTime(h.ngaytra).Date == Convert.ToDateTime(dtoHD.ngaytra).Date&& h.ngaylamhopdong == null && h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == dtoHD.ghichu).Select(h => h.mahopdong).FirstOrDefault()); } else if (dtoHD.ngaytra == null) { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& h.ngaytra == null && Convert.ToDateTime(h.ngaylamhopdong).Date == Convert.ToDateTime(dtoHD.ngaylamhopdong).Date&& h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == dtoHD.ghichu).Select(h => h.mahopdong).FirstOrDefault()); } else if (dtoHD.ghichu == null) { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& Convert.ToDateTime(h.ngaytra).Date == Convert.ToDateTime(dtoHD.ngaytra).Date&& Convert.ToDateTime(h.ngaylamhopdong).Date == Convert.ToDateTime(dtoHD.ngaylamhopdong).Date&& h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == null).Select(h => h.mahopdong).FirstOrDefault()); } else if (dtoHD.ngaytra == null && dtoHD.ngaylamhopdong == null) { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& h.ngaytra == null && h.ngaylamhopdong == null && h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == dtoHD.ghichu).Select(h => h.mahopdong).FirstOrDefault()); } else if (dtoHD.ngaytra == null && dtoHD.ghichu == null) { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& h.ngaytra == null && Convert.ToDateTime(h.ngaylamhopdong).Date == Convert.ToDateTime(dtoHD.ngaylamhopdong).Date&& h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == null).Select(h => h.mahopdong).FirstOrDefault()); } else if (dtoHD.ngaylamhopdong == null && dtoHD.ghichu == null) { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& Convert.ToDateTime(h.ngaytra).Date == Convert.ToDateTime(dtoHD.ngaytra).Date&& h.ngaylamhopdong == null && h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == null).Select(h => h.mahopdong).FirstOrDefault()); } else if (dtoHD.ngaytra == null && dtoHD.ngaylamhopdong == null && dtoHD.ghichu == null) { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& h.ngaytra == null && h.ngaylamhopdong == null && h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == null).Select(h => h.mahopdong).FirstOrDefault()); } else { return(GetAll().Where(h => Convert.ToDateTime(h.ngaythue).Date == Convert.ToDateTime(dtoHD.ngaythue).Date&& Convert.ToDateTime(h.ngaytra).Date == Convert.ToDateTime(dtoHD.ngaytra).Date&& Convert.ToDateTime(h.ngaylamhopdong).Date == Convert.ToDateTime(dtoHD.ngaylamhopdong).Date&& h.tiencoc == dtoHD.tiencoc && h.giathue == dtoHD.giathue && h.chisodien == h.chisodien && h.chisonuoc == dtoHD.chisonuoc && h.ghichu == dtoHD.ghichu).Select(h => h.mahopdong).FirstOrDefault()); } }
private void dgvHopDong_SelectionChanged(object sender, EventArgs e) { if (dgvHopDong.Rows.Count > 0) { DataGridViewRow dgr = dgvHopDong.CurrentRow; DTOPhong p = balP.DetailPhong(Convert.ToInt32(dgr.Cells["maphong"].Value)); DTOHopDong hd = balHD.DetailHopDong(Convert.ToInt64(dgr.Cells["mahopdong"].Value)); Int64 machuthuephong = balTP.MaChuPhong(Convert.ToInt32(dgr.Cells["maphong"].Value), hd.mahopdong); rtbHopDong.Clear(); rtbHopDong.Text = "THÔNG TIN HỢP ĐỒNG THUÊ PHÒNG: " + p.tenphong + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; if (balHD.GiaTriHopDongVoiNgayHienTai(hd.mahopdong) == -1) { rtbHopDong.Text += "HỢP ĐỒNG ĐÃ HẾT HẠN" + Environment.NewLine; } else if (balHD.GiaTriHopDongVoiNgayHienTai(hd.mahopdong) == 0) { rtbHopDong.Text += "HỢP ĐỒNG VẪN CÒN HẠN" + Environment.NewLine; } else { rtbHopDong.Text += "HỢP ĐỒNG VẪN CHƯA ĐẾN NGÀY DÙNG" + Environment.NewLine; } if (hd.ngaylamhopdong == null) { rtbHopDong.Text += Environment.NewLine + "Ngày làm Hợp đồng thuê: (Không có.)" + Environment.NewLine; } else { rtbHopDong.Text += Environment.NewLine + "Ngày làm Hợp đồng thuê: " + Convert.ToDateTime(hd.ngaylamhopdong).ToShortDateString() + Environment.NewLine; } if (hd.ngaytra == null) { rtbHopDong.Text += "Ngày thuê phòng từ: " + hd.ngaythue.ToShortDateString() + " đến ngày (Không có.)" + Environment.NewLine; } else { rtbHopDong.Text += "Ngày thuê phòng từ: " + hd.ngaythue.ToShortDateString() + " đến ngày " + Convert.ToDateTime(hd.ngaytra).ToShortDateString() + Environment.NewLine; } rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Người thuê phòng: " + balK.DetailKhach(machuthuephong).tenkhach + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Tiền cọc khi thuê phòng: " + string.Format("{0:#,##0.##}", hd.tiencoc) + Environment.NewLine; rtbHopDong.Text += "Giá thuê phòng: " + string.Format("{0:#,##0.##}", hd.giathue) + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Chỉ số điện của phòng lúc làm hợp đồng thuê: " + string.Format("{0:#,##0.##}", hd.chisodien) + Environment.NewLine; rtbHopDong.Text += "Chỉ số nước của phòng lúc làm hợp đồng thuê: " + string.Format("{0:#,##0.##}", hd.chisonuoc) + Environment.NewLine; rtbHopDong.Text += "Ghi chú của hợp đồng: " + hd.ghichu + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; dgvCuocPhi.Rows.Clear(); foreach (DTOChiuCuocPhi dtoCCP in balCCP.ChiuCuocPhiTuMaHopDong(hd.mahopdong)) { dgvCuocPhi.Rows.Add(dtoCCP.macuocphi, balCuoc.DetailCuocPhi(dtoCCP.macuocphi).tencuocphi, dtoCCP.soluong, "Xem"); } dgvKhach.Rows.Clear(); foreach (Int64 makhach in balTP.DanhSachMaKhachTheoMaHopDong(hd.mahopdong)) { //Hiện ảnh if (balK.DetailKhach(makhach).hinh != null) { Bitmap img = new Bitmap(Image.FromFile(balK.DetailKhach(makhach).hinh), new Size(60, 70)); dgvKhach.Rows.Add(img, makhach, balK.DetailKhach(makhach).tenkhach, "Xem"); } else { dgvKhach.Rows.Add(null, makhach, balK.DetailKhach(makhach).tenkhach, "Xem"); } } } }
private void TaiThongTinHopDong() { int maphong = Convert.ToInt32(dgvPhong.CurrentRow.Cells["maphong"].Value); DTOPhong p = balP.DetailPhong(maphong); DTOHopDong hd = balHD.HopDongHienTai(maphong); Int64 machuthuephong = balTP.MaChuPhong(maphong, hd.mahopdong); #region Tải thông tin hợp đồng rtbHopDong.Clear(); rtbHopDong.Text = "THÔNG TIN HỢP ĐỒNG THUÊ PHÒNG: " + p.tenphong + Environment.NewLine; if (hd.ngaylamhopdong == null) { rtbHopDong.Text += Environment.NewLine + "Ngày làm Hợp đồng thuê: (Không có.)" + Environment.NewLine; } else { rtbHopDong.Text += Environment.NewLine + "Ngày làm Hợp đồng thuê: " + Convert.ToDateTime(hd.ngaylamhopdong).ToShortDateString() + Environment.NewLine; } if (hd.ngaytra == null) { rtbHopDong.Text += "Ngày thuê phòng từ: " + hd.ngaythue.ToShortDateString() + " đến ngày (Không có.)" + Environment.NewLine; } else { rtbHopDong.Text += "Ngày thuê phòng từ: " + hd.ngaythue.ToShortDateString() + " đến ngày " + Convert.ToDateTime(hd.ngaytra).ToShortDateString() + Environment.NewLine; } rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Người thuê phòng: " + balK.DetailKhach(machuthuephong).tenkhach + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Tiền cọc khi thuê phòng: " + string.Format("{0:#,##0.##}", hd.tiencoc) + Environment.NewLine; rtbHopDong.Text += "Giá thuê phòng: " + string.Format("{0:#,##0.##}", hd.giathue) + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Chỉ số điện của phòng lúc làm hợp đồng thuê: " + string.Format("{0:#,##0.##}", hd.chisodien) + Environment.NewLine; rtbHopDong.Text += "Chỉ số nước của phòng lúc làm hợp đồng thuê: " + string.Format("{0:#,##0.##}", hd.chisonuoc) + Environment.NewLine; rtbHopDong.Text += "Ghi chú của hợp đồng: " + hd.ghichu + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Danh sách các loại cước phí mà khách thuê phải trả: (" + balCCP.ChiuCuocPhiTuMaHopDong(hd.mahopdong).Count.ToString() + " loại)" + Environment.NewLine; rtbHopDong.Text += "============================================" + Environment.NewLine; int socuoc = 1; rtbHopDong.Text += "STT" + "\t" + "Tên cước phí" + "\t" + "\t" + "\t" + "Số lượng" + "\t" + "Giá cước" + Environment.NewLine; rtbHopDong.Text += "============================================" + Environment.NewLine; foreach (DTOChiuCuocPhi ccp in balCCP.ChiuCuocPhiTuMaHopDong(hd.mahopdong)) { DTOCuocPhi cp = balCuoc.DetailCuocPhi(ccp.macuocphi); rtbHopDong.Text += socuoc.ToString() + "\t" + cp.tencuocphi.ToUpper(); if (cp.tencuocphi.ToUpper().Length > 12) { rtbHopDong.Text += "\t" + "\t"; } else { rtbHopDong.Text += "\t" + "\t" + "\t"; } rtbHopDong.Text += ccp.soluong.ToString(); rtbHopDong.Text += "\t" + "\t" + string.Format("{0:#,##0.##}", cp.giacuocphi) + Environment.NewLine; socuoc += 1; } rtbHopDong.Text += "-------------------------------------------------------------------------------" + Environment.NewLine; rtbHopDong.Text += Environment.NewLine; rtbHopDong.Text += "Danh sách Khách đang thuê phòng: (" + balTP.DanhSachMaKhachTheoMaHopDong(hd.mahopdong).Count.ToString() + " người)" + Environment.NewLine; rtbHopDong.Text += "==========================================================" + Environment.NewLine; int sokhach = 1; rtbHopDong.Text += "STT" + "\t" + "Tên khách" + "\t" + "\t" + "\t" + "\t" + "Giới Tính" + "\t" + "Số định danh" + Environment.NewLine; rtbHopDong.Text += "==========================================================" + Environment.NewLine; foreach (Int64 makhach in balTP.DanhSachMaKhachTheoMaHopDong(hd.mahopdong)) { DTOKhach k = balK.DetailKhach(makhach); rtbHopDong.Text += sokhach.ToString() + "\t" + k.tenkhach.ToUpper(); if (k.tenkhach.ToUpper().Length > 17) { rtbHopDong.Text += "\t"; } else if (k.tenkhach.ToUpper().Length > 17) { rtbHopDong.Text += "\t" + "\t"; } else if (k.tenkhach.ToUpper().Length > 12) { rtbHopDong.Text += "\t" + "\t" + "\t"; } else { rtbHopDong.Text += "\t" + "\t" + "\t" + "\t"; } if (k.gioitinh) { rtbHopDong.Text += "Nam"; } else { rtbHopDong.Text += "Nữ"; } rtbHopDong.Text += "\t" + "\t" + k.sodinhdanh.ToString() + Environment.NewLine; sokhach += 1; } rtbHopDong.Text += "---------------------------------------------------------------------------------------------------------" + Environment.NewLine; #endregion }
private void dgvPhong_SelectionChanged(object sender, EventArgs e) { //Tải các thông tin liên quan đến Phòng: Thông tin Phòng + DS Hợp Đồng cũ + Tải HĐ còn hiệu lực. if (dgvPhong.CurrentRow.Index > -1) { int maphong = Convert.ToInt32(dgvPhong.CurrentRow.Cells["maphong"].Value); DTOPhong p = balP.DetailPhong(maphong); int maloaiphong = balP.DetailPhong(maphong).maloaiphong; DTOLoaiPhong lp = balLP.DetailLoaiPhong(maloaiphong); int machuphong = balLP.DetailLoaiPhong(maloaiphong).machuphong; DTOChuPhong cp = balCP.DetailChuPhong(machuphong); #region Thông tin phòng trên Textbox lblTieuDe.Text = @"PHÒNG: [ " + p.tenphong + @" ]"; lblLSHopDong.Text = @"Các hợp đồng thuê trước đây của phòng: [ " + p.tenphong + @" ]"; string thongtin = string.Empty; thongtin += "Tên chủ phòng: " + cp.tenchuphong + Environment.NewLine; thongtin += "Tên loại phòng: " + lp.tenloaiphong + Environment.NewLine; thongtin += "Tên phòng: " + p.tenphong + Environment.NewLine; thongtin += Environment.NewLine; if (p.status) { thongtin += "Trạng thái phòng: ĐANG CHO THUÊ" + Environment.NewLine; } else { thongtin += "Trạng thái phòng: CÒN TRỐNG" + Environment.NewLine; } thongtin += Environment.NewLine; thongtin += "Giá thuê: " + string.Format("{0:#,##0.##}", lp.giathue) + Environment.NewLine; thongtin += "Số khách ở tối đa: " + lp.sokhach + Environment.NewLine; thongtin += "Thông tin: " + lp.thongtin + Environment.NewLine; thongtin += "Địa chỉ: " + lp.diachi + Environment.NewLine; thongtin += "Tình trạng phòng: " + p.tinhtrangphong; txtThongTinPhong.Text = thongtin; #endregion //Tải thông tin hợp đồng đang còn hiệu lực. if (p.status) { TaiThongTinHopDong(); } else { rtbHopDong.Clear(); rtbHopDong.Text = "HIỆN TẠI PHÒNG CÒN TRỐNG."; } //Load danh sách lịch sử hợp đồng. dgvHopDong.Rows.Clear(); foreach (Int64 mahopdong in balTP.DanhSachMaHopDongTheoMaPhong(p.maphong)) { DTOHopDong hd = balHD.DetailHopDong(mahopdong); string giatriHD = "Đã hết hạn"; if (balHD.GiaTriHopDongVoiNgayHienTai(hd.mahopdong) == 0) { giatriHD = "Còn hạn dùng"; } if (balHD.GiaTriHopDongVoiNgayHienTai(hd.mahopdong) == 1) { giatriHD = "Chưa đến ngày dùng"; } dgvHopDong.Rows.Add("Xem", hd.mahopdong, hd.ngaylamhopdong, hd.ngaythue, hd.ngaytra, hd.tiencoc, hd.giathue, giatriHD, "Chuyển", "Sửa", "Xóa"); } dgvHopDong.Sort(dgvHopDong.Columns["ngaythue"], ListSortDirection.Descending); } if (dgvPhong.SelectedRows.Count == 0) { txtThongTinPhong.Text = string.Empty; } }