private void btthem_Click_1(object sender, EventArgs e) { SqlDataReader sdr = dataMuon.getTaiLieu(txtmaTL.Text); if (sdr.HasRows) { sdr.Read(); SqlDataReader sdr2 = dataMuon.getPhieuMuonChiTietTheoMa(muonSach_GUI.pm.MaPM, txtmaTL.Text); if (!sdr2.HasRows) { int sl = sdr.GetInt32(3); if (rgsl.IsMatch(txtsl.Text)) { if (Int32.Parse(txtsl.Text) > sl) { MessageBox.Show("Không đủ sách!!! Chúng tôi chỉ còn " + sl + " cuốn"); } else { dataMuon.updateSoLuongTLAdd(new phieuMuonChiTiet(muonSach_GUI.pm.MaPM, txtmaTL.Text, Int32.Parse(txtsl.Text))); dataMuon.addPhieuMuonChiTiet(new phieuMuonChiTiet(muonSach_GUI.pm.MaPM, txtmaTL.Text, Int32.Parse(txtsl.Text))); MessageBox.Show("Thêm thành công!!!"); load(); } } else { MessageBox.Show("Điền Vào textbox Số Lượng Là Một Số lớn hơn 0 !!!"); } } else { MessageBox.Show("Đã có tài liệu này trong phiếu mượn, Sửa nếu có thay đổi!!!"); } } else { MessageBox.Show("Không Có Tài Liệu Này!!! hoặc textBox đang trống"); } }
private void btxoa_Click_1(object sender, EventArgs e) { Boolean checkpm = true; if (txtmapm.Text.Equals("")) { MessageBox.Show("Chưa nhập mã phiếu mượn!!!"); } else { SqlDataReader sdrpm = dataMuon.getPhieuMuon(); while (sdrpm.Read()) { if (sdrpm.GetString(0).Equals(txtmapm.Text)) { checkpm = checkpm || true; break; } else { checkpm = checkpm && false; } } if (!checkpm) { MessageBox.Show("Không có phiếu mượn này !!!"); } else { Boolean checktl = true; //Check tài liệu chưa trả SqlDataReader sdr = dataMuon.getPhieuMuonChiTietTheoMa(txtmapm.Text); while (sdr.Read()) { if (sdr.IsDBNull(3)) { checktl = checktl && false; break; } } if (!checktl) { DialogResult dlr = MessageBox.Show("Có tài liệu mượn chưa trả! Bạn có chắc muốn xóa phiếu mượn này và những thứ liên quan!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlr == DialogResult.No) { } else { SqlDataReader sdr2 = dataMuon.getPhieuMuonChiTietTheoMa(txtmapm.Text); while (sdr2.Read()) { if (sdr2.IsDBNull(3)) { dataMuon.updateSoLuongTLdelete(new phieuMuonChiTiet(sdr2.GetString(0), sdr2.GetString(1), sdr2.GetInt32(2))); } } dataMuon.deletephieuMuonChiTiet(txtmapm.Text); dataMuon.deletePhieuMuon(txtmapm.Text); MessageBox.Show("Xóa thành công!!!"); loaddata(); } } else { DialogResult dlr = MessageBox.Show("Bạn muốn xóa phiếu mượn này à!", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dlr == DialogResult.Yes) { dataMuon.deletephieuMuonChiTiet(txtmapm.Text); dataMuon.deletePhieuMuon(txtmapm.Text); MessageBox.Show("Xóa thành công!!!"); loaddata(); } else { } } viewphieumuon.DataSource = dataMuon.getphieuMuonlq(); // viewtlmuon.DataSource = dataMuon.gettlMuonlq(); } } }