private void btnLuu_Click(object sender, EventArgs e) { if (KiemTraKyTuToiDa() == false) { return; } string Gioitinh; if (radNam.Checked == true) { Gioitinh = "Nam"; } else { Gioitinh = "Nữ"; } blNV = new BLNhanVien(); if (txtMaNV.Text.Trim().Length == 0 || txtTenNV.Text.Trim().Length == 0 || txtDiaChi.Text.Trim().Length == 0 || txtCMND.Text.Trim().Length == 0 || txtSDT.Text.Trim().Length == 0 || txtTaiKhoan.Text.Trim().Length == 0 || txtMatKhau.Text.Trim().Length == 0) { MessageBox.Show("Bạn phải nhập đủ các thông tin cần thiết"); return; } // kiểm tra Trùng CMND blNV = new BLNhanVien(); if (blNV.CheckCMND(txtMaNV.Text.Trim(), txtCMND.Text.Trim(), ref err) == false) { MessageBox.Show("CMND bị trùng vui lòng kiểm tra lại"); return; } float luong = 0; try { luong = float.Parse(txtLuong.Text); } catch { MessageBox.Show("Lương phải là giá trị số và lớn hơn hoặc bằng 0!"); return; } DateTime now = DateTime.Today; if (now.Year - dateTimePickerNgay.Value.Year < 18) { MessageBox.Show("Chỉ nhận người đủ 18 tuổi"); return; } if (Them == true) { try { if (blNV.CheckStaffId(txtMaNV.Text).Tables[0].Rows.Count != 0) { MessageBox.Show("Mã nhân viên bị trùng, vui lòng nhập mã khác!"); } else if (blNV.CheckAcount(txtTaiKhoan.Text, txtMaNV.Text).Tables[0].Rows.Count != 0) { MessageBox.Show("Tài khoản đã có người sử dụng, vui lòng đổi tài khoản!"); } else { blNV = new BLNhanVien(); if (blNV.AddStaff(txtMaNV.Text, txtTenNV.Text, dateTimePickerNgay.Value, Gioitinh, txtCMND.Text, txtSDT.Text, txtDiaChi.Text, txtTaiKhoan.Text, txtMatKhau.Text, luong, ref err)) { MessageBox.Show("Thêm thành công"); } else { MessageBox.Show("Thêm thất bại!!"); } btnThem.Enabled = true; LoadThongTin(); pnlQuanLyNV.Enabled = false; } } catch { MessageBox.Show("Không thể thêm được"); } } else { blNV = new BLNhanVien(); if (blNV.CheckAcount(txtTaiKhoan.Text, txtMaNV.Text).Tables[0].Rows.Count != 0) { MessageBox.Show("Tài khoản đã có người sử dụng, vui lòng đổi tài khoản!"); return; } blNV = new BLNhanVien(); int r = dgvQLNV.CurrentCell.RowIndex; string MaNV = dgvQLNV.Rows[r].Cells[0].Value.ToString(); if (blNV.UpdateStaff(MaNV, txtTenNV.Text, dateTimePickerNgay.Value, Gioitinh, txtCMND.Text, txtSDT.Text, txtDiaChi.Text, txtTaiKhoan.Text, txtMatKhau.Text, luong, ref err) == true) { MessageBox.Show("Sửa thành công!"); LoadThongTin(); } else { MessageBox.Show("Sửa thất bại"); } } }