protected void btnThem_Click(object sender, EventArgs e) { //lấy các giá trị từ giao diện qlnv nv = LayDuLieuTuForm(); nv NV = new nv(); //Kiểm tra username này đã tồn tại trong CSDL chưa bool exist = NV.KiemtraNV(nv.MaNV); if (exist) { lblThongBao.Text = "Mã nhân viên đã tồn tại"; } else { //thực hiện ghi dữ liệu xuống bool result = NV.ThemNV(nv); if (result) { lblThongBao.Text = "Thêm thành công!"; //hiển thị dữ liệu lên GridView LayDuLieuVaoGridView(); } else { lblThongBao.Text = "Có lỗi.Vui lòng thử lại sau"; } } }
// đổ dữ liệu lên GridView private void LayDuLieuVaoGridView() { nv NV = new nv(); grVQuanLi.DataSource = NV.LayNV(); grVQuanLi.DataSourceID = null; grVQuanLi.DataBind(); }
protected void grVQuanLi_SelectedIndexChanged(object sender, EventArgs e) { string maNV = grVQuanLi.SelectedRow.Cells[0].Text; nv NV = new nv(); qlnv nv = NV.LayMaNV(maNV); if (nv != null) { DoDuLeuVaoCacTruong(nv); } }
protected void btnXoa_Click(object sender, EventArgs e) { nv NV = new nv(); bool kq = NV.XoaNV(txtMaNV.Text); if (kq) { lblThongBao.Text = "Đã xóa thành công"; LayDuLieuVaoGridView(); } else { lblThongBao.Text = "Có lỗi"; } }