private void btnThem_Click(object sender, EventArgs e) { DocGia data = new DocGia(); data.MaDocGia = txtMaDocGia.Text; if (data.MaDocGia.Equals("")) { MessageBox.Show("Mã độc giả không được trống!"); return; } data.TenDocGia = txtTenDocGia.Text; if (data.TenDocGia.Equals("")) { MessageBox.Show("Tên độc giả không được trống!"); return; } data.Email = txtEmail.Text; data.DienThoai = txtDienThoai.Text; if (objdg.insertData(data)) { clearText(); binData("", "", ""); MessageBox.Show("Thêm mới thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm mới không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public void sbtnXoaDG_Click(object sender, EventArgs e) { if (str == "1") { PhieuMuon pm = new PhieuMuon(); string str = pm.ma = grvDocGia.GetFocusedRowCellValue("Mã phiếu").ToString(); DialogResult result = new DialogResult(); result = MessageBox.Show("Bạn có thực sự muốn xóa ?" + pm.ma, "Xóa sách", MessageBoxButtons.OKCancel); da.NonQuery("delete PhieuMuon where ma='" + pm.ma + "'"); grcDSDocGia.DataSource = da.Query("DanhSachPhieuMuon"); } else { DocGia docgia = new DocGia(); docgia.ma = grvDocGia.GetFocusedRowCellValue("ma").ToString(); DialogResult result = MessageBox.Show("Bạn có thực sự muốn xóa ?" + docgia.ma, "Xóa độc giả", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { controller.deleteDocGia(docgia.ma); uDSDocGia_Load(sender, e); } else { uDSDocGia_Load(sender, e); } } }
private void btnSua_Click(object sender, EventArgs e) { int r = dgvDocGia.CurrentCell.RowIndex; if (r < 0) { MessageBox.Show("Chọn một bản ghi trước!"); return; } string id = dgvDocGia.CurrentRow.Cells[0].Value.ToString(); DocGia data = new DocGia(); data.TenDocGia = txtTenDocGia.Text; if (data.TenDocGia.Equals("")) { MessageBox.Show("Tên độc giả không được trống!"); return; } data.Email = txtEmail.Text; data.DienThoai = txtDienThoai.Text; data.MaDocGia = id; if (MessageBox.Show("Bạn muốn sửa bản ghi?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (objdg.updateData(data)) { binData("", "", ""); MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sửa không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void sbtnSuaDG_Click(object sender, EventArgs e) { if (str == "1") { PhieuMuon pm = new PhieuMuon(); pm.ma = grvDocGia.GetFocusedRowCellValue("Mã phiếu").ToString(); pm.docgiama = grvDocGia.GetFocusedRowCellValue("Mã độc giả").ToString(); pm.ngaymuon = DateTime.Parse(grvDocGia.GetFocusedRowCellValue("Ngày mượn").ToString()); pm.hantra = DateTime.Parse(grvDocGia.GetFocusedRowCellValue("Hạn trả").ToString()); pm.phathong = 0; pm.phatmat = 0; pm.phatquahan = 0; pm.ngaytra = DateTime.Now; string str1 = pm.ma + "_" + pm.docgiama + "_" + pm.ngaymuon + "_" + pm.ngaytra + "_" + pm.hantra + "_" + pm.phathong + "_" + pm.phatmat + "_" + pm.phatquahan; frmUpdate frm = new frmUpdate(str1); frm.ShowDialog(); grcDSDocGia.DataSource = da.Query("DanhSachPhieuMuon"); } else { DocGia docgia = new DocGia(); docgia.ma = grvDocGia.GetFocusedRowCellValue("ma").ToString(); docgia.ten = grvDocGia.GetFocusedRowCellValue("ten").ToString(); docgia.ngaysinh = DateTime.Parse(grvDocGia.GetFocusedRowCellValue("ngaysinh").ToString()); if (bool.Parse(grvDocGia.GetFocusedRowCellValue("gioitinh").ToString()) == true) { docgia.gioitinh = true; } //sach.tinhtrang = true; else { docgia.gioitinh = false; } docgia.diachi = grvDocGia.GetFocusedRowCellValue("diachi").ToString(); docgia.ngaylamthe = DateTime.Parse(grvDocGia.GetFocusedRowCellValue("ngaylamthe").ToString()); docgia.ngayhethan = DateTime.Parse(grvDocGia.GetFocusedRowCellValue("ngayhethan").ToString()); if (bool.Parse(grvDocGia.GetFocusedRowCellValue("hoatdong").ToString()) == true) { docgia.hoatdong = true; } //sach.tinhtrang = true; else { docgia.hoatdong = false; } EditReader editreader = new EditReader(docgia); editreader.ShowDialog(); listDocGia = controller.getListDocGia(); grcDSDocGia.DataSource = listDocGia; } }