private void btnLuu_Click(object sender, EventArgs e) { if (Them) { if (LoaiNvBUS.KtMaLNV(txtMa.Text) > 0) { MessageBox.Show("Mã nhân viên tồn tai. Nhập Mã nhân viên khác !"); txtMa.ResetText(); txtTenLoai.ResetText(); txtMa.Focus(); } else { LoaiNvBUS.ThemLNV(txtMa.Text, txtTenLoai.Text); LoadData(); // Thông báo MessageBox.Show("Đã thêm xong!"); } } else { int r = dgvLNV.CurrentCell.RowIndex; // MaNV hiện hành string strMaNV = dgvLNV.Rows[r].Cells[0].Value.ToString(); LoaiNvBUS.SuaLNV(txtMa.Text, txtTenLoai.Text); LoadData(); // Thông báo MessageBox.Show("Đã sửa xong!"); } }
// chưa có xác trùng khóa public void LoadData() { loaiNVBindingSource.DataSource = LoaiNvBUS.GetLNV(); txtMa.ResetText(); txtTenLoai.ResetText(); // Không cho thao tác trên các nút Lưu / Hủy btnLuu.Enabled = false; btnHuy.Enabled = false; panel.Enabled = false; // Cho thao tác trên các nút Thêm / Sửa / Xóa / Thoát btnThem.Enabled = true; btnSua.Enabled = true; btnXoa.Enabled = true; }
private void btnDelLNV_Click(object sender, EventArgs e) { try { // Lấy thứ tự record hiện hành int r = dgvLNV.CurrentCell.RowIndex; // Lấy MaKH của record hiện hành string strMaLNV = dgvLNV.Rows[r].Cells[0].Value.ToString(); LoaiNvBUS.XoaLNV(strMaLNV); LoadData(); //dgvNV_CellClick(null, null); MessageBox.Show("Đã xóa xong!"); } catch { MessageBox.Show("Không được phép xóa nhân viên này"); } }
private void dgvNhanVien_CellClick(object sender, DataGridViewCellEventArgs e) { cboCH.DataSource = CuaHangBUS.GetAllCuaHang(); cboCH.DisplayMember = "TenCuaHang"; cboCH.ValueMember = "MaCuaHang"; cboLoaiNV.DataSource = LoaiNvBUS.GetLNV(); cboLoaiNV.DisplayMember = "TenLoaiNV"; cboLoaiNV.ValueMember = "MaLoaiNV"; // Lấy thứ tự record hiện hành int r = dgvNhanVien.CurrentCell.RowIndex; txtMaNV.Text = dgvNhanVien.Rows[r].Cells[0].Value.ToString(); cboCH.SelectedValue = dgvNhanVien.Rows[r].Cells[1].Value.ToString(); cboLoaiNV.SelectedValue = dgvNhanVien.Rows[r].Cells[2].Value.ToString(); txtTenNV.Text = dgvNhanVien.Rows[r].Cells[3].Value.ToString(); cboSex.Text = dgvNhanVien.Rows[r].Cells[4].Value.ToString(); try { txtDiaChi.Text = dgvNhanVien.Rows[r].Cells[5].Value.ToString(); } catch { txtDiaChi.Text = " "; } try { txtSDT.Text = dgvNhanVien.Rows[r].Cells[6].Value.ToString(); } catch { txtSDT.Text = " "; } try { txtLuong.Text = dgvNhanVien.Rows[r].Cells[7].Value.ToString(); } catch { txtLuong.Text = " "; } }