private void btnInsert_Click(object sender, EventArgs e) { if (CheckData()) { TB_NhanVien nv = new TB_NhanVien(); nv.MaNV = txtMaNV.Text; nv.HoTen = txtHoTen.Text; nv.Email = txtEmail.Text; nv.Luong = txtLuong.Text; nv.TenDN = txtTenDN.Text; nv.MatKhau = txtMK.Text; if (NvBLL.InsertNhanVien(nv)) { ShowAllNhanVien(); } else { MessageBox.Show("Đã xảy ra lỗi trog quá trình thêm dữ liệu.", "Thông báo lỗi", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } }
public bool UpdateNhanVien(TB_NhanVien nv) { string sql = "update NHANVIEN set hoten=@hoten,email=@email,luong=@luong,tendn=@tendn, matkhau=@matkhau where manv = @manv"; SqlConnection con = dc.getConnect(); try { cmd = new SqlCommand(sql, con); con.Open(); cmd.Parameters.Add("@manv", SqlDbType.VarChar).Value = nv.MaNV; cmd.Parameters.Add("@hoten", SqlDbType.NVarChar).Value = nv.HoTen; cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = nv.Email; cmd.Parameters.Add("@luong", SqlDbType.VarBinary).Value = aes_obj.Encrypt(nv.Luong); cmd.Parameters.Add("@tendn", SqlDbType.NVarChar).Value = nv.TenDN; cmd.Parameters.Add("@matkhau", SqlDbType.VarBinary).Value = sh.ComputeHash(ASCIIEncoding.ASCII.GetBytes(nv.MatKhau)); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception) { return(false); } return(true); }
//------------------------------------------------------------------------------------------------------------- public bool InsertNhanVien(TB_NhanVien nv) { string sql = "EXEC SP_INS_ENCRYPT_NHANVIEN @manv, @hoten, @email, @luong, @tendn, @matkhau"; SqlConnection con = dc.getConnect(); try { cmd = new SqlCommand(sql, con); con.Open(); cmd.Parameters.Add("@manv", SqlDbType.VarChar).Value = nv.MaNV; cmd.Parameters.Add("@hoten", SqlDbType.NVarChar).Value = nv.HoTen; cmd.Parameters.Add("@email", SqlDbType.VarChar).Value = nv.Email; cmd.Parameters.Add("@luong", SqlDbType.VarBinary).Value = aes_obj.Encrypt(nv.Luong); cmd.Parameters.Add("@tendn", SqlDbType.NVarChar).Value = nv.TenDN; cmd.Parameters.Add("@matkhau", SqlDbType.VarBinary).Value = sh.ComputeHash(ASCIIEncoding.ASCII.GetBytes(nv.MatKhau)); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception) { return(false); } return(true); }
public bool UpdateNhanVien(TB_NhanVien nv) { return(nva.UpdateNhanVien(nv)); }
public bool InsertNhanVien(TB_NhanVien nv) { return(nva.InsertNhanVien(nv)); }