コード例 #1
0
 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);
     }
 }
コード例 #2
0
        private void btnChoMuon_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtMaSachTim.Text) && !string.IsNullOrEmpty(txtTenKhachHang.Text))
            {
                SachService sachService = new SachService();
                sach = sachService.GetSachById(Convert.ToInt32(txtMaSachTim.Text));
                if (Convert.ToInt32(sach.SoLuong) > 0)
                {
                    try
                    {
                        ThueSach thuesach = new ThueSach();
                        thuesach.MaSach      = sach.MaSach;
                        thuesach.MaKhachHang = kh.MaKhachHang;
                        thuesach.NgayThue    = DateTime.Now.Date;
                        thuesach.NgayTra     = dtNgayHenTra.Value.Date;
                        thuesach.TinhTrang   = "1";
                        sachService.ChoThueSach(thuesach);

                        sach.SoLuong = (Convert.ToInt32(sach.SoLuong) - 1).ToString();
                        sachService.UpdateSach(sach);
                        lvwDanhSach.Items.Clear();
                        List <ThueSach> lst = sachService.GetThueSachChuaTra();
                        foreach (ThueSach item in lst)
                        {
                            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);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Không thế cho thuê!");
                    }
                }
            }
        }