private void btnLuu_Click(object sender, EventArgs e) { if (txtTenSach.Text.Trim().Length == 0) { MessageBox.Show("Vui lòng nhập thông tin đầy đủ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SachObj sachObj = new SachObj(); addData(sachObj); if (flagLuu == 0) { if (sachCtr.AddData(sachObj)) { MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Thêm không thành công!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { if (sachCtr.UpdData(sachObj)) { 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!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } frmSach_Load(sender, e); }
private void addData(SachObj s) { s.Ma = txtMaSach.Text.Trim(); s.Ten = txtTenSach.Text.Trim(); s.Matheloai = txtMaTL.Text.Trim(); s.Matacgia = txtMaTG.Text.Trim(); s.Manhaxuatban = txtMaNXB.Text.Trim(); s.Giaban = int.Parse(txtGiaBan.Text.Trim()); s.Soluong = int.Parse(txtSoLuong.Text.Trim()); }
public bool UpdData(SachObj sachObj) { cmd.CommandText = "Update Sach set TenSach = N'" + sachObj.Ten + "', MaTL = '" + sachObj.Matheloai + "', MaTG = '" + sachObj.Matacgia + "', MaNXB = '" + sachObj.Manhaxuatban + "', GiaBan = '" + sachObj.Giaban + "', SoLuong ='" + sachObj.Soluong + "' Where MaSach = '" + sachObj.Ma + "'"; cmd.CommandType = CommandType.Text; cmd.Connection = con.Connection; try { con.OpenConn(); cmd.ExecuteNonQuery(); return(true); } catch (Exception ex) { string mex = ex.Message; cmd.Dispose(); con.CloseConn(); } return(false); }
public bool AddData(SachObj sachObj) { cmd.CommandText = "Insert into Sach values ('" + sachObj.Ma + "',N'" + sachObj.Ten + "',N'" + sachObj.Matheloai + "','" + sachObj.Matacgia + "','" + sachObj.Manhaxuatban + "','" + sachObj.Giaban + "','" + sachObj.Soluong + "')"; cmd.CommandType = CommandType.Text; cmd.Connection = con.Connection; try { con.OpenConn(); cmd.ExecuteNonQuery(); return(true); } catch (Exception ex) { string mex = ex.Message; cmd.Dispose(); con.CloseConn(); } return(false); }
public bool UpdData(SachObj sachObj) { return(sachMod.UpdData(sachObj)); }
public bool AddData(SachObj sachObj) { return(sachMod.AddData(sachObj)); }