private void QuanLyThueSach_Load(object sender, EventArgs e) { try { SachService sachService = new SachService(); List <ThueSach> lstChuaTra = sachService.GetThueSachChuaTra(); foreach (ThueSach item in lstChuaTra) { ListViewItem listViewItem = new ListViewItem(); listViewItem.SubItems.Add(item.MaKhachHang.ToString()); listViewItem.SubItems.Add(item.MaSach.ToString()); listViewItem.SubItems.Add(item.NgayThue.ToString()); listViewItem.SubItems.Add(item.NgayTra.ToString()); listViewItem.SubItems.Add(item.TinhTrang.Equals("1") ? "Chưa trả" : "Đã trả"); lvwDanhSach.Items.Add(listViewItem); } List <ThueSach> lstDaTra = sachService.GetThueSachDaTra(); foreach (ThueSach thuesach in lstDaTra) { ListViewItem item = new ListViewItem(); item.SubItems.Add(thuesach.MaKhachHang.ToString()); item.SubItems.Add(thuesach.MaSach.ToString()); item.SubItems.Add(thuesach.NgayThue.ToShortDateString()); item.SubItems.Add(thuesach.NgayTra.ToShortDateString()); item.SubItems.Add(thuesach.TinhTrang.Equals("1") ? "Chưa trả" : "Đã trả"); lvwDanhSachTra.Items.Add(item); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void btnTraSach_Click(object sender, EventArgs e) { SachService s = new SachService(); int MaKH = Convert.ToInt32(txtMaKH_TraSach.Text); int MaSach = Convert.ToInt32(txtMaSach_TraSach.Text); try { s.TraSach(MaKH, MaSach); MessageBox.Show("Trả sách thành công"); } catch (Exception ex) { MessageBox.Show("Lỗi trả sách"); } List <ThueSach> lstDaTra = s.GetThueSachDaTra(); lvwDanhSachTra.Items.Clear(); foreach (ThueSach thuesach in lstDaTra) { ListViewItem item = new ListViewItem(); item.SubItems.Add(thuesach.MaKhachHang.ToString()); item.SubItems.Add(thuesach.MaSach.ToString()); item.SubItems.Add(thuesach.NgayThue.ToShortDateString()); item.SubItems.Add(thuesach.NgayTra.ToShortDateString()); item.SubItems.Add(thuesach.TinhTrang.Equals("1") ? "Chưa trả" : "Đã trả"); lvwDanhSachTra.Items.Add(item); } }