private void btnLapPhieu_Click(object sender, EventArgs e) { if (STTSach > 1 && txtMaDG.Text != "" && dtgrvPM[1, 0].Value.ToString() != "") { if (TinhTrangDG.CompareTo("TTDG01") == 0) { DateTime ngayMuon = new DateTime(dtNgayMuon.Value.Year, dtNgayMuon.Value.Month, dtNgayMuon.Value.Day); DateTime newTime = ngayMuon.AddDays(MaxNgayMuon); PhieuMuonDTO PhieuMuon = new PhieuMuonDTO(); PhieuMuon.MaPM = txtMaPhieuMuon.Text; PhieuMuon.NgayMuon = dtNgayMuon.Value; PhieuMuon.MaDG = txtMaDG.Text; PhieuMuon.NgayHetHan = newTime; QuanLyPhieuMuonBUS BUS = new QuanLyPhieuMuonBUS(); int nRow = BUS.ThemPhieuMuon(PhieuMuon); CT_PhieuMuonDTO CTPM; for (int i = 0; i < dtgrvPM.RowCount; i++) { if (Convert.ToString(dtgrvPM.Rows[i].Cells[1].Value) != "") { CTPM = new CT_PhieuMuonDTO(); CTPM.MaPM = txtMaPhieuMuon.Text; CTPM.MaSach = Convert.ToString(dtgrvPM.Rows[i].Cells[1].Value); BUS.ThemChiTietPhieuMuon(CTPM); BUS.CapNhatTinhTrangSach(CTPM.MaSach); } } if (nRow > 0) { MessageBox.Show("Lập phiếu mượn thành công", "THÔNG BÁO"); LoadThemThanhCong(); } else { MessageBox.Show("Lập phiếu mượn thất bại", "THÔNG BÁO"); } } else { MessageBox.Show("Không thể mượn sách vì thẻ độc giả đã hết hạn", "THÔNG BÁO"); return; } } else if (txtMaDG.Text == "") { MessageBox.Show("Xin vui lòng nhập mã độc giả", "THÔNG BÁO"); txtMaDG.Focus(); return; } else if (STTSach == 1 || dtgrvPM[1, 0].Value.ToString() == "") { MessageBox.Show("Vui lòng thêm sách vào phiếu mượn", "THÔNG BÁO"); } }
void LoadMaPhieuMuon() { QuanLyPhieuMuonBUS BUS = new QuanLyPhieuMuonBUS(); DataTable dtMaPM = BUS.LayMaPhieuMuon(); string ma = dtMaPM.Rows[dtMaPM.DefaultView.Count - 1]["MaPM"].ToString(); int lastIndex = int.Parse(ma.Substring(2)) + 1; txtMaPhieuMuon.Text = "PM" + lastIndex.ToString("000"); }
private void ManHinhChucNangChoMuonSach_Load(object sender, EventArgs e) { LoadMaPhieuMuon(); QuanLyPhieuMuonBUS BUS = new QuanLyPhieuMuonBUS(); DataTable dtQuyDinh = BUS.LayQuyDinh(); txtMaDG.AutoCompleteSource = AutoCompleteSource.CustomSource; txtMaDG.AutoCompleteMode = AutoCompleteMode.Suggest; AutoCompleteStringCollection collection = new AutoCompleteStringCollection(); DataTable dtDsDG = LoadDsDG(); collection = LoadSuggestTextBox(dtDsDG); txtMaDG.AutoCompleteCustomSource = collection; MaxSach = int.Parse(dtQuyDinh.Rows[0]["SoSachMuonToiDa"].ToString()); MaxNgayMuon = int.Parse(dtQuyDinh.Rows[0]["SoNgayMuonToiDa"].ToString()); }
private void txtMaDG_Leave(object sender, EventArgs e) { if (txtMaDG.Text != "") { QuanLyPhieuMuonBUS BUS = new QuanLyPhieuMuonBUS(); DataTable dtDocGia = BUS.LayDocGia(txtMaDG.Text); if (dtDocGia.Rows.Count > 0) { QuanLyPhieuTraBUS BUSPT = new QuanLyPhieuTraBUS(); DataTable dtKiemTra = BUSPT.KiemTraDocGiaCoPhieuMuon(txtMaDG.Text); if (int.Parse(dtKiemTra.Rows[0]["TonTai"].ToString()) > 0) { txtHoTenDG.Text = dtDocGia.Rows[0]["HoTenDG"].ToString(); txtNgaySinhDG.Text = dtDocGia.Rows[0]["NgaySinh"].ToString().Substring(0, 10); txtLoaiDG.Text = dtDocGia.Rows[0]["TenLoaiDG"].ToString(); txtTienNo.Text = dtDocGia.Rows[0]["TongNo"].ToString(); txtTongNo.Text = txtTienNo.Text; dtgrPhieuTra.Enabled = true; } else { MessageBox.Show("Độc giả này không có phiếu mượn sách xin vui lòng kiểm tra lại", "THÔNG BÁO"); txtMaDG.Text = ""; txtHoTenDG.Text = ""; txtNgaySinhDG.Text = ""; txtLoaiDG.Text = ""; txtTienNo.Text = ""; txtTongNo.Text = ""; txtMaDG.Focus(); dtgrPhieuTra.Enabled = false; } } else { MessageBox.Show("Mã độc giả không tồn tại", "THÔNG BÁO"); txtMaDG.Text = ""; txtHoTenDG.Text = ""; txtNgaySinhDG.Text = ""; txtLoaiDG.Text = ""; txtTienNo.Text = ""; txtTongNo.Text = ""; txtMaDG.Focus(); dtgrPhieuTra.Enabled = false; } } }
private void ManHinhChucNangNhanTraSach_Load(object sender, EventArgs e) { LoadMaPhieuTra(); txtMaDG.Focus(); QuanLyPhieuMuonBUS BUSPM = new QuanLyPhieuMuonBUS(); DataTable dtQuyDinh = BUSPM.LayQuyDinh(); txtMaDG.AutoCompleteSource = AutoCompleteSource.CustomSource; txtMaDG.AutoCompleteMode = AutoCompleteMode.Suggest; AutoCompleteStringCollection collection = new AutoCompleteStringCollection(); DataTable dtDsDG = LoadDsDG(); collection = LoadSuggestTextBox(dtDsDG); txtMaDG.AutoCompleteCustomSource = collection; soNgayMuonQuyDinh = int.Parse(dtQuyDinh.Rows[0]["SoNgayMuonToiDa"].ToString()); SoTienPhatQuyDinh = float.Parse(dtQuyDinh.Rows[0]["TienPhatTraTre"].ToString()); dtgrPhieuTra.Enabled = false; }
private void txtMaDG_Leave(object sender, EventArgs e) { if (txtMaDG.Text != "") { QuanLyPhieuMuonBUS BUS = new QuanLyPhieuMuonBUS(); DataTable dtDocGia = BUS.LayDocGia(txtMaDG.Text); if (dtDocGia.Rows.Count > 0) { txtHoTenDG.Text = dtDocGia.Rows[0]["HoTenDG"].ToString(); txtNgaySinh.Text = dtDocGia.Rows[0]["NgaySinh"].ToString().Substring(0, 10); txtLoaiDocGia.Text = dtDocGia.Rows[0]["TenLoaiDG"].ToString(); TinhTrangDG = dtDocGia.Rows[0]["TTDG"].ToString(); } else { MessageBox.Show("Mã độc giả không tồn tại", "THÔNG BÁO"); txtMaDG.Text = ""; txtHoTenDG.Text = ""; txtNgaySinh.Text = ""; txtLoaiDocGia.Text = ""; txtMaDG.Focus(); } } }
private void dtgrPhieuTra_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (dtgrPhieuTra.Rows[e.RowIndex].Cells[1].Value == null) { BeginInvoke(new MethodInvoker(delegate { if (e.RowIndex != dtgrPhieuTra.RowCount - 1) { if (dtgrPhieuTra[4, e.RowIndex].Value != null) { txtTienPhatKyNay.Text = (float.Parse(txtTienPhatKyNay.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); txtTongNo.Text = (float.Parse(txtTongNo.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); } dtgrPhieuTra.Rows.RemoveAt(e.RowIndex); ListMaSach.Remove(MaBiXoa); ListViTri.Remove(e.RowIndex); STTSach--; } })); return; } string MaSach = dtgrPhieuTra[e.ColumnIndex, e.RowIndex].Value.ToString(); if (MaSach != "") { for (int i = 0; i < ListMaSach.Count; i++) { if (MaSach.ToLower() == ListMaSach[i].ToLower() && e.RowIndex != ListViTri[i]) { MessageBox.Show("Cuốn sách này đã có trong phiếu trả", "THÔNG BÁO"); dtgrPhieuTra[1, e.RowIndex].Value = null; dtgrPhieuTra[2, e.RowIndex].Value = ""; dtgrPhieuTra[3, e.RowIndex].Value = ""; if (dtgrPhieuTra[4, e.RowIndex].Value != null) { txtTienPhatKyNay.Text = (float.Parse(txtTienPhatKyNay.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); txtTongNo.Text = (float.Parse(txtTongNo.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); } dtgrPhieuTra[4, e.RowIndex].Value = null; return; } } for (int i = 0; i < ListMaSach.Count; i++) { if (dtgrPhieuTra[1, e.RowIndex].Value != null) { if (dtgrPhieuTra[1, e.RowIndex].Value.ToString() == ListMaSach[i]) { return; } } } QuanLyPhieuMuonBUS BUS = new QuanLyPhieuMuonBUS(); DataTable dtSach = BUS.LaySachTrongPhieuMuon(MaSach); if (dtSach.Rows.Count > 0) { QuanLyPhieuTraBUS BUSPT = new QuanLyPhieuTraBUS(); DataTable dtKiemTra = BUSPT.KiemTraSachCoTrongPhieuMuon(txtMaDG.Text, MaSach); if (dtKiemTra.Rows.Count > 0 && int.Parse(dtKiemTra.Rows[0]["TonTai"].ToString()) > 0) { dtgrPhieuTra[2, e.RowIndex].Value = dtKiemTra.Rows[0]["NgayMuon"].ToString().Substring(0, 10); MaPM = dtKiemTra.Rows[0]["MaPM"].ToString(); if (KiemTraNgayTraHopLe() == false) { MessageBox.Show("Ngày trả sách không hợp lệ xin vui lòng kiểm tra lại", "THÔNG BÁO"); } DateTime ngaymuon = Convert.ToDateTime(dtKiemTra.Rows[0]["NgayMuon"].ToString().Substring(0, 10)); DateTime ngaytra = Convert.ToDateTime(dtNgayTra.Value.ToString()); TimeSpan Time = ngaytra - ngaymuon; int TongSoNgay = Time.Days + 1; dtgrPhieuTra[3, e.RowIndex].Value = TongSoNgay.ToString(); if (TongSoNgay > soNgayMuonQuyDinh) { float TienPhat = (TongSoNgay - soNgayMuonQuyDinh) * SoTienPhatQuyDinh; dtgrPhieuTra[4, e.RowIndex].Value = TienPhat.ToString(); txtTienPhatKyNay.Text = (float.Parse(txtTienPhatKyNay.Text) + TienPhat).ToString(); txtTongNo.Text = (float.Parse(txtTongNo.Text) + TienPhat).ToString(); SoNgayTraTre = TongSoNgay - soNgayMuonQuyDinh; } else { dtgrPhieuTra[4, e.RowIndex].Value = "0"; } ListMaSach.Add(dtgrPhieuTra[1, e.RowIndex].Value.ToString()); ListViTri.Add(e.RowIndex); } else { MessageBox.Show("Cuốn sách này không có trong phiếu mượn", "THÔNG BÁO"); if (dtgrPhieuTra[4, e.RowIndex].Value != null) { txtTienPhatKyNay.Text = (float.Parse(txtTienPhatKyNay.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); txtTongNo.Text = (float.Parse(txtTongNo.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); } dtgrPhieuTra[1, e.RowIndex].Value = ""; dtgrPhieuTra[1, e.RowIndex].Value = null; dtgrPhieuTra[2, e.RowIndex].Value = ""; dtgrPhieuTra[3, e.RowIndex].Value = ""; dtgrPhieuTra[4, e.RowIndex].Value = null; } } else { MessageBox.Show("Không tìm thấy cuốn sách nào với mã sách: " + MaSach, "THÔNG BÁO"); if (dtgrPhieuTra[4, e.RowIndex].Value != null) { txtTienPhatKyNay.Text = (float.Parse(txtTienPhatKyNay.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); txtTongNo.Text = (float.Parse(txtTongNo.Text) - float.Parse(dtgrPhieuTra[4, e.RowIndex].Value.ToString())).ToString(); } dtgrPhieuTra[1, e.RowIndex].Value = null; dtgrPhieuTra[2, e.RowIndex].Value = ""; dtgrPhieuTra[3, e.RowIndex].Value = ""; dtgrPhieuTra[4, e.RowIndex].Value = null; } } }
private void dtgrvPM_CellEndEdit(object sender, DataGridViewCellEventArgs e) { if (dtgrvPM.Rows[e.RowIndex].Cells[1].Value == null) { BeginInvoke(new MethodInvoker(delegate { if (e.RowIndex != dtgrvPM.RowCount - 1) { dtgrvPM.Rows.RemoveAt(e.RowIndex); ListMaSach.Remove(MaBiXoa); ListViTri.Remove(e.RowIndex); STTSach--; } })); return; } string MaSach = dtgrvPM[e.ColumnIndex, e.RowIndex].Value.ToString(); if (MaSach != "") { for (int i = 0; i < ListMaSach.Count; i++) { if (MaSach == ListMaSach[i] && e.RowIndex != ListViTri[i]) { MessageBox.Show("Cuốn sách này đã có trong phiếu mượn", "THÔNG BÁO"); dtgrvPM[e.ColumnIndex, e.RowIndex].Value = null; dtgrvPM[2, e.RowIndex].Value = ""; dtgrvPM[3, e.RowIndex].Value = ""; dtgrvPM[4, e.RowIndex].Value = ""; return; } } QuanLyPhieuMuonBUS BUS = new QuanLyPhieuMuonBUS(); DataTable dtSach = BUS.LaySachTrongPhieuMuon(MaSach); if (dtSach.Rows.Count > 0) { if (dtSach.Rows[0]["TTS"].ToString() != "TTS02") { MessageBox.Show("Cuốn sách này hiện tại không có sẵn", "THÔNG BÁO"); dtgrvPM[e.ColumnIndex, e.RowIndex].Value = null; dtgrvPM[2, e.RowIndex].Value = ""; dtgrvPM[3, e.RowIndex].Value = ""; dtgrvPM[4, e.RowIndex].Value = ""; return; } dtgrvPM[2, e.RowIndex].Value = dtSach.Rows[0]["TenSach"]; dtgrvPM[3, e.RowIndex].Value = dtSach.Rows[0]["TenTheLoai"]; dtgrvPM[4, e.RowIndex].Value = dtSach.Rows[0]["TenTacGia"]; ListMaSach.Add(dtgrvPM[1, e.RowIndex].Value.ToString()); ListViTri.Add(e.RowIndex); } else { MessageBox.Show("Không tìm thấy cuốn sách nào với mã sách: " + MaSach, "THÔNG BÁO"); dtgrvPM[1, e.RowIndex].Value = ""; dtgrvPM[2, e.RowIndex].Value = ""; dtgrvPM[3, e.RowIndex].Value = ""; dtgrvPM[4, e.RowIndex].Value = ""; } } }