private void btnSuaSach_SuaSach_Click(object sender, EventArgs e) { SachService s = new SachService(); sach.TenSach = txtTenSach_SuaSach.Text.Trim(); sach.TheLoai = txtTheLoai_SuaSach.Text.Trim(); sach.TacGia = txtTacGia_SuaSach.Text.Trim(); sach.NhaXuanBan = txtNXB_SuaSach.Text.Trim(); sach.SoLuong = txtSoLuong_SuaSach.Text.Trim(); try { s.UpdateSach(sach); MessageBox.Show("Sửa thành công!"); this.Close(); } catch (Exception ex) { MessageBox.Show("Sửa thất bại!"); this.Close(); } }
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ê!"); } } } }