protected void btnThem_Click(object sender, EventArgs e) { TaiKhoan1 nv = LayDuLieuTuForm(); TaiKhoanDAO nvDAO = new TaiKhoanDAO(); bool exist = nvDAO.KTMaNV(nv.MaNV); bool exist1 = nvDAO.KTTenDN(nv.TenDangNhap); if (exist || exist1) { lblThongBao.Text = "Nhân Viên đã tồn tại"; } else { bool result = nvDAO.Them(nv); if (result) { lblThongBao.Text = "Thêm nhân viên thành công"; LayNhanVienVaoGV(); } else { lblThongBao.Text = "Có lỗi, vui lòng thử lại!"; } } }
private TaiKhoan1 LayDuLieuTuForm() { string manv = txtMaNV.Text; string tennv = txtTenNV.Text; string ngaysinh = txtNgaySinh.Text; string cmnd = txtCMND.Text; string gioitinh = ddlGioiTinh.SelectedValue; string sdt = txtSDT.Text; string chucvu = ddlChucVu.SelectedValue; string tendangnhap = txtTenDangNhap.Text; string matkhau = txtMatKhau.Text; TaiKhoan1 nv = new TaiKhoan1 { MaNV = manv, TenNV = tennv, NgaySinh = ngaysinh, GioiTinh = gioitinh, CMND = cmnd, SDT = sdt, ChucVu = chucvu, TenDangNhap = tendangnhap, MatKhau = matkhau, }; return(nv); }
public TaiKhoan1 LayNhanVien(string manv) { using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = @"SELECT * FROM NHANVIEN WHERE maNV = @manv"; string sql1 = @"SELECT * FROM TAIKHOAN1 WHERE tenDangNhap = @tendangnhap,maNV = @manv"; SqlCommand cmd = new SqlCommand(sql, connection); SqlCommand cmd1 = new SqlCommand(sql1, connection); cmd.Parameters.AddWithValue("@manv", manv); cmd1.Parameters.AddWithValue("@tendangnhap", manv); connection.Open(); SqlDataReader reader = cmd.ExecuteReader(); SqlDataReader reader1 = cmd1.ExecuteReader(); if (reader.Read()) { TaiKhoan1 nv = new TaiKhoan1 { MaNV = (string)reader["maNV"], TenNV = (string)reader["hoTen"], NgaySinh = reader["ngaySinh"].ToString(), GioiTinh = (string)reader["gioiTinh"], CMND = (string)reader["diaChi"], SDT = (string)reader["sdt"], ChucVu = (string)reader["chucVu"], TenDangNhap = (string)reader1["tenDangNhap"], MatKhau = (string)reader1["matKhau"], }; return(nv); } } return(null); }
public bool ChinhSua(TaiKhoan1 nv) { using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = @"UPDATE NHANVIEN SET hoTen= @ten, ngaySinh= @ngaysinh, gioiTinh = @gioitinh, cmnd = @cmnd, sdt= @sdt, chucVu = @chucvu WHERE maNV = @manv"; string sql1 = @"UPDATE TAIKHOAN1 SET tenDangNhap= @tendangnhap, matKhau= @matkhau WHERE maNV = @manv"; SqlCommand command = new SqlCommand(sql, connection); SqlCommand command1 = new SqlCommand(sql1, connection); command.Parameters.AddWithValue("@manv", nv.MaNV); command.Parameters.AddWithValue("@ten", nv.TenNV); command.Parameters.AddWithValue("@ngaysinh", Convert.ToDateTime(nv.NgaySinh)); command.Parameters.AddWithValue("@gioitinh", nv.GioiTinh); command.Parameters.AddWithValue("@cmnd", nv.CMND); command.Parameters.AddWithValue("@sdt", nv.SDT); command.Parameters.AddWithValue("@chucvu", nv.ChucVu); command1.Parameters.AddWithValue("@tendangnhap", nv.TenDangNhap); command1.Parameters.AddWithValue("@matkhau", nv.MatKhau); command1.Parameters.AddWithValue("@manv", nv.MaNV); connection.Open(); int result = command.ExecuteNonQuery(); if (result >= 1) { return(true); } } return(false); }
public bool Them(TaiKhoan1 nv) { using (SqlConnection connection = new SqlConnection(connectionString)) { string sql = @"INSERT INTO NHANVIEN(maNV,hoTen,ngaySinh,gioiTinh,cmnd,sdt,chucVu) VALUES(@manv, @ten, @ngaysinh, @gioitinh, @diachi, @sdt, @chucvu)"; string sql1 = @"INSERT INTO TAIKHOAN1(tenDangNhap,matKhau,maNV) VALUES(@tendangnhap, @matkhau,@manv)"; { SqlCommand command = new SqlCommand(sql, connection); SqlCommand command1 = new SqlCommand(sql1, connection); command.Parameters.AddWithValue("@manv", nv.MaNV); command.Parameters.AddWithValue("@ten", nv.TenNV); command.Parameters.AddWithValue("@ngaysinh", Convert.ToDateTime(nv.NgaySinh)); command.Parameters.AddWithValue("@gioitinh", nv.GioiTinh); command.Parameters.AddWithValue("@diachi", nv.CMND); command.Parameters.AddWithValue("@sdt", nv.SDT); command.Parameters.AddWithValue("@chucvu", nv.ChucVu); command1.Parameters.AddWithValue("@tendangnhap", nv.TenDangNhap); command1.Parameters.AddWithValue("@matkhau", nv.MatKhau); command1.Parameters.AddWithValue("@manv", nv.MaNV); connection.Open(); int result = command.ExecuteNonQuery(); int result1 = command1.ExecuteNonQuery(); return(result >= 1 || result1 >= 1); } } }
protected void gvKhachHang_SelectedIndexChanged(object sender, EventArgs e) { string manv = gvTK.SelectedRow.Cells[0].Text; TaiKhoanDAO nvDAO = new TaiKhoanDAO(); TaiKhoan1 nv = nvDAO.LayNhanVien(manv); if (nv != null) { DoDuLieuVaoCacTruong(nv); } }
public void DoDuLieuVaoCacTruong(TaiKhoan1 nv) { txtMaNV.Text = nv.MaNV; txtTenNV.Text = nv.TenNV; txtNgaySinh.Text = nv.NgaySinh; txtCMND.Text = nv.CMND; txtSDT.Text = nv.SDT; ddlChucVu.SelectedValue = nv.ChucVu; ddlGioiTinh.SelectedValue = nv.GioiTinh.ToString(); txtTenDangNhap.Text = nv.TenDangNhap; txtMatKhau.Text = nv.MatKhau; }
protected void btnSua_Click(object sender, EventArgs e) { TaiKhoan1 nv = LayDuLieuTuForm(); TaiKhoanDAO nvDAO = new TaiKhoanDAO(); bool result = nvDAO.ChinhSua(nv); if (result) { lblThongBao.Text = "Cập nhật thành công cho nhân viên: " + nv.TenNV; LayNhanVienVaoGV(); } else { lblThongBao.Text = "Cập nhật không thành công, vui lòng kiểm tra lại"; } }