private void btnLuu_Click(object sender, EventArgs e) { if (txtMaSach.Text == "" || txtTenSach.Text == "" || txtTacGia.Text == "" || txtNhaXuatBan.Text == "" || cbMaLinhVuc.Text == "" || txtNamXuatBan.Text == "" || txtSoTrang.Text == "" || txtSoLuong.Text == "") { MessageBox.Show("Mời nhập đầy đủ thông tin"); } else { sachMod.MaSach = CommonService.ValidateStringForID(txtMaSach.Text); sachMod.TenSach = CommonService.ValidateStringForName(txtTenSach.Text); sachMod.TacGia = CommonService.ValidateStringForName(txtTacGia.Text); sachMod.NhaXuatBan = CommonService.ValidateStringForName(txtNhaXuatBan.Text); sachMod.MaLinhVuc = cbMaLinhVuc.Text; sachMod.NamXuatBan = txtNamXuatBan.Text; sachMod.SoTrang = Convert.ToInt32(txtSoTrang.Text); sachMod.SoLuong = Convert.ToInt32(txtSoLuong.Text); sachMod.SoSachHong = Convert.ToInt32(txtSoSachHong.Text); sachMod.NgayNhap = dtpNgayNhap.Text; sachMod.GhiChu = rtbGhiChu.Text; if (action == "add") { Object obj = sachSer.getModel(txtMaSach.Text); if (obj != null) { MessageBox.Show("Mã bị trùng"); return; } else { sachSer.createModel(sachMod); } } else { sachSer.updateModel(sachMod); } MessageBox.Show("Lưu thành công"); sachSer.getAll(dgvSach); clearText(); txtMaSach.Enabled = false; txtTenSach.Enabled = false; txtTacGia.Enabled = false; txtNhaXuatBan.Enabled = false; cbMaLinhVuc.Enabled = false; txtNamXuatBan.Enabled = false; txtSoTrang.Enabled = false; txtSoLuong.Enabled = false; txtSoSachHong.Enabled = false; dtpNgayNhap.Enabled = false; rtbGhiChu.Enabled = false; btnThem.Enabled = true; btnSua.Enabled = false; btnXoa.Enabled = false; btnLuu.Enabled = false; } }