private void btnLuu_Click(object sender, EventArgs e) { if (txtTenNV.Text.Trim().Length == 0) { MessageBox.Show("Vui lòng nhập thông tin đầy đủ", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Nhanvienobj nvObj = new Nhanvienobj(); addData(nvObj); if (flagLuu == 0) { if (nvCtr.AddData(nvObj)) { 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 (nvCtr.UpdData(nvObj)) { 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); } } NhanVien_Load_1(sender, e); }
private void addData(Nhanvienobj nv) { nv.Ma = txtMaNV.Text.Trim(); if (cbbGioiTinh.SelectedIndex == 0) { nv.Gioitinh = "Nam"; } else { nv.Gioitinh = "Nu"; } nv.Email = txtEmail.Text.Trim(); nv.Cmnd = txtCMND.Text.Trim(); nv.Matkhau = txtMatKhau.Text.Trim(); nv.Maqh = txtIDQ.Text.Trim(); nv.Tennv = txtTenNV.Text.Trim(); nv.NgaySinh = dtimeNgaySinh.Text; }
public bool UpdData(Nhanvienobj nvObj) { cmd.CommandText = "Update NhanVien set TenNV = N'" + nvObj.Tennv + "', Email = N'" + nvObj.Email + "', NgaySinh = CONVERT(DATE,'" + nvObj.NgaySinh + "',103), GioiTinh = N'" + nvObj.Gioitinh + "', CMND = " + nvObj.Cmnd + ", MatKhau = '" + nvObj.Matkhau + "', MaQH = '" + nvObj.Maqh + "' Where MaNV = '" + nvObj.Ma + "'"; cmd.CommandType = CommandType.Text; cmd.Connection = con.Connection; try { con.OpenConn(); cmd.ExecuteNonQuery(); con.CloseConn(); return(true); } catch (Exception ex) { string mex = ex.Message; cmd.Dispose(); con.CloseConn(); } return(false); }
public bool AddData(Nhanvienobj nvObj) { cmd.CommandText = "Insert into NhanVien values ('" + nvObj.Ma + "',N'" + nvObj.Tennv + "','" + nvObj.Email + "',CONVERT(DATE,'" + nvObj.NgaySinh + "',103),'" + nvObj.Gioitinh + "','" + nvObj.Cmnd + "','" + nvObj.Matkhau + "','" + nvObj.Maqh + "')"; cmd.CommandType = CommandType.Text; cmd.Connection = con.Connection; try { con.OpenConn(); cmd.ExecuteNonQuery(); con.CloseConn(); return(true); } catch (Exception ex) { string mex = ex.Message; cmd.Dispose(); con.CloseConn(); } return(false); }
public bool UpdData(Nhanvienobj nvObj) { return(nvMod.UpdData(nvObj)); }
public bool AddData(Nhanvienobj nvObj) { return(nvMod.AddData(nvObj)); }