DTO.DTOtblUSER LayUser() { DTO.DTOtblUSER _User = new DTO.DTOtblUSER(); _User.USERID = (int)cmbMaNV.SelectedValue; _User.PASSWORDS = Encrypt_Decrypt.Encrypt(txtPass.Text, true); _User.LASTLOGIN = DateTime.Now; _User.LASTCHANGEDPASS = DateTime.Now; return _User; }
private void UpdateUser() { int _UserID = int.Parse(cmbMaNV.Text); var _oldGroup = GetGroupByUserID((int)grdvUser.GetRowCellValue(grdvUser.FocusedRowHandle, colUserID)); var _newGroup = LayGroupUser(); #region Insert - Remove group //var _themGroup = _newGroup.Concat(_oldGroup).GroupBy(a => a.GROUPID,(key, group) =>group.First()); //var _xoaGroup = _newGroup.Concat(_oldGroup).GroupBy(a => a.GROUPID,(key, group) =>group.First()); //foreach (var _s1 in _oldGroup.ToList()) //{ // _themGroup.ToList().RemoveAll(a => a.GROUPID == _s1.GROUPID); // _themGroup.ToList().Remove(_s1); //} //for (int i = 0; i < _oldGroup.ToList().Count; i++) //{ // _themGroup.ToList().Remove(_oldGroup.ToList()[i]); // _themGroup.ToList().RemoveAll(a=>a.GROUPID==_oldGroup[i].GROUPID); //} //foreach (var _s2 in _newGroup) //{ // _xoaGroup.ToList().RemoveAll(a=>a.GROUPID==_s2.GROUPID); //} #endregion if (CheckRetyePass()) { if (Encrypt_Decrypt.Decrypt(busUser.LayTheoMatblUSER(_UserID).ToList()[0].PASSWORDS,true) == txtPass.Text.Trim()) { foreach (var _b in _oldGroup) { busGroupUser = new BUS.BUStblGROUPUSER(); busGroupUser.XoatblGROUPUSER(_UserID, _b.GROUPID); } foreach (var _a in _newGroup) { busGroupUser = new BUS.BUStblGROUPUSER(); var _dtoGroupUser = new DTO.DTOtblGROUPUSER(); _dtoGroupUser.GROUPID = _a.GROUPID; _dtoGroupUser.USERID = _UserID; busGroupUser.ThemtblGROUPUSER(_dtoGroupUser); } } else //Cập nhật password nếu thay đổi { string _strTB = "Mật khẩu không giống với mật khẩu cũ.\nNếu tiếp tục bạn sẽ đổi mật khẩu của người dùng này\n Bạn muốn tiếp tục chứ?"; if (MessageBox.Show(_strTB, "Lưu ý!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK) { foreach (var _b in _oldGroup) { busGroupUser = new BUS.BUStblGROUPUSER(); busGroupUser.XoatblGROUPUSER(_UserID, _b.GROUPID); } foreach (var _a in _newGroup) { busGroupUser = new BUS.BUStblGROUPUSER(); var _dtoGroupUser = new DTO.DTOtblGROUPUSER(); _dtoGroupUser.GROUPID = _a.GROUPID; _dtoGroupUser.USERID = _UserID; busGroupUser.ThemtblGROUPUSER(_dtoGroupUser); } busUser = new BUS.BUStblUSER(); var _dtoUser = new DTO.DTOtblUSER(); _dtoUser.USERID = _UserID; _dtoUser.PASSWORDS = Encrypt_Decrypt.Encrypt(txtPass.Text, true); ; _dtoUser.LASTCHANGEDPASS = DateTime.Now; _dtoUser.LASTLOGIN = busUser.LayTheoMatblUSER(_UserID)[0].LASTLOGIN; busUser.CapnhattblUSER(_dtoUser); } } } else MessageBox.Show("Kiểm tra lại mật khẩu.", "Lỗi!", MessageBoxButtons.OK, MessageBoxIcon.Warning); grdvUser.FocusedRowHandle = grdvUser.RowCount-1; }
private DTO.DTOtblUSER GetUser(int _ID, string _Pass, DateTime _LastLogin, DateTime _LastPassChanged) { var _User = new DTO.DTOtblUSER(); _User.LASTLOGIN = _LastLogin; _User.USERID = _ID; _User.PASSWORDS =_Pass; _User.LASTCHANGEDPASS = _LastPassChanged; return _User; }