private void cmbMaPhong_SelectedIndexChanged(object sender, EventArgs e) { BillDTO infor = new BillDTO(); infor.MaPhong = int.Parse(cmbMaPhong.Text); List <BillDTO> lst = new List <BillDTO>(); lst = BillBUS.LayThongTinPhongThue(infor); //txtDonGiaPhong.Text = lst[0].DonGia.ToString(); txtDonGia.Text = string.Format("{0:0,0}", lst[0].DonGia); txtTenKhachHang.Text = lst[0].TenKhachHang.ToString(); txtDiaChi.Text = lst[0].DiaChi.ToString(); int maphieuthue = lst[0].MaPhieuThue.Value; infor.NgayBatDauThue = Convert.ToDateTime(lst[0].NgayBatDauThue.ToString()); BillBUS.TinhSoNgayDaThue(infor); lst = BillBUS.LaySoNgayDaThue(); txtSoNgayThue.Text = lst[0].SoNgayDaThue.ToString(); if (Convert.ToInt32(txtSoNgayThue.Text) < 0) { btnThanhToan.Enabled = false; MessageBox.Show("Chưa thể thanh toán khách hàng này", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (txtSoNgayThue.Text == "0") { txtSoNgayThue.Text = "1"; } int num = BillBUS.LaySoLuongKhach(maphieuthue); lst = BillBUS.LayKhachNuocNgoai(); int kpt = lst[0].KhachPTThu.Value; int kng = lst[0].SLKhachNG.Value; if (num >= kpt) { lst = BillBUS.TinhPhuThu(num); txtPhuThu.Text = lst[0].PhuThu.ToString(); } else { txtPhuThu.Text = "0"; } int nc = BillBUS.DemSoLuongKhachNuocNgoai(infor); if (nc >= kng) { lst = BillBUS.TinhHeSo(); txtHeSo.Text = lst[0].HeSo.ToString(); } else { txtHeSo.Text = "0"; } decimal phidichvu = 0; int numdv = OderDichVuBUS.LaySoLuongDichVuDK(infor.MaPhong); if (numdv == 0) { txtPhiDichVu.Text = "0"; } else { for (int i = 0; i < numdv; i++) { List <OderServiceDTO> lst2 = new List <OderServiceDTO>(); OderServiceDTO infor2 = new OderServiceDTO(); lst2 = OderDichVuBUS.DanhSachDichVuDK(infor.MaPhong); infor2.MaDichVu = lst2[i].MaDichVu; infor2.SoLuong = lst2[i].SoLuong; List <ServiceDTO> lst3 = new List <ServiceDTO>(); lst3 = ServiceBUS.LayDonGia(infor2.MaDichVu); ServiceDTO dongiadv = new ServiceDTO(); dongiadv.DonGia = lst3[0].DonGia; decimal tiendv = dongiadv.DonGia; phidichvu += infor2.SoLuong * tiendv; } txtPhiDichVu.Text = string.Format("{0:0,0 }", phidichvu); } bool flag = true; for (int i = 0; i < dgvHoaDon.RowCount; i++) { if (dgvHoaDon.Rows[i].Cells["colMaPhong"].Value.ToString() != null) { if (dgvHoaDon.Rows[i].Cells["colMaPhong"].Value.ToString() == cmbMaPhong.Text) { btnThemHoaDon.Enabled = false; flag = false; break; } } } if (flag == true) { btnThemHoaDon.Enabled = true; } }