/// <summary> /// 保存 /// </summary> private void Save() { string strPasswred = txtPassword.Text.Trim(); string strConfirmPassword = txtConfirmPassword.Text.Trim(); if (string.IsNullOrWhiteSpace(strPasswred) || strPasswred.Length < 6 || strPasswred.Length > 16) { MessageBox.Show("密码不允许为空,并且长度为6~16个字符", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (strPasswred != strConfirmPassword) { MessageBox.Show("两次填写的密码不一致", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } strConfirmPassword = TripleDES.EncryptPassword(strConfirmPassword);//加密 parentMain.UpdateUser((p) => { bool retVal = false; if (p.Password != strConfirmPassword) { p.Password = strConfirmPassword; retVal = true; } return(retVal); }); MessageBox.Show("密码修改成功", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.Close(); }
/// <summary> /// 新增 /// </summary> private void Add() { User user = new User(); if (parentMain.userList.Count > 0) { maxUserID++; CreateLoginName(); } user.LoginName = loginName; user.ChineseName = "新用户"; user.Guid = Guid.NewGuid().ToString(); user.IsAdmin = 0; user.Sex = 0; user.CreateDate = DateTime.Now; user.CreateUserGuid = parentMain.ThisUser.Guid; user.UpdateDate = DateTime.Now; user.UpdateUserGuid = parentMain.ThisUser.Guid; user.Password = TripleDES.EncryptPassword("888888"); addUserList.Add(user); int rowIndex = AddDgvRow(user);//添加数据行 dgvMain.Rows[rowIndex].Selected = true; AddDataType(user); //初始化用户默认分类数据 AddSetting(user); //初始化用户默认设置数据 }
/// <summary> /// 保存 /// </summary> private void Save() { try { if (parentMain.ContentManager != null) { if (string.IsNullOrWhiteSpace(strContentID)) { return; } Content content = new Content(); content.Code = this.txtCode.Text.Trim(); content.Title = this.txtTitle.Text.Trim(); content.Address = this.txtAddress.Text.Trim(); content.UserName = this.txtUserName.Text.Trim(); string strPassword = this.txtPassword.Text.Trim(); if (!string.IsNullOrWhiteSpace(strPassword)) { content.Password = TripleDES.EncryptPassword(strPassword); } content.Email = this.txtEmail.Text.Trim(); content.Remarks = this.txtRemarks.Text.Trim(); content.UpdateUserGuid = parentMain.ThisUser.Guid; content.UpdateDate = DateTime.Now; content.ContentID = Convert.ToInt32(strContentID); content.DataTypeGuid = this.txtClassify.Tag.ToString(); parentMain.SaveContent(content);//保存更新内容 } } catch (Exception ex) { Logger.Error(ex, MethodBase.GetCurrentMethod(), parentMain.ThisSendBackParameter); } this.Close(); }
private void Login() { this.Invoke(new Action(() => { btnSubmit.Text = "登录中..."; btnSubmit.Enabled = false; })); bool isLogin = false; string strUserName = this.txtUserName.Text.Trim(); string strPassword = this.txtPassword.Text.Trim(); string strError = "登录失败"; if (string.IsNullOrWhiteSpace(strUserName) || string.IsNullOrWhiteSpace(strPassword)) { strError += ":登录名及密码不允许为空。"; Logger.Error(strError, MethodBase.GetCurrentMethod());//记录日志 MessageBox.Show(strError, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } strError = "登录失败"; try { Imanager <User> manager = Tools.DynamicCreateClass <Imanager <User> >("UserManager"); if (manager == null) { strError += ":创建用户管理实例异常。"; Logger.Error(strError, MethodBase.GetCurrentMethod());//记录日志 MessageBox.Show(strError, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } UserList = manager.Load(); if (UserList.Count > 0) { var result = (from u in UserList where u.LoginName == strUserName select u).ToList(); if (result != null && result.Count > 0) { if (TripleDES.EncryptPassword(strPassword) == result[0].Password) { this.ThisUser = result[0]; isLogin = true; } else { strError += ":密码错误。"; } } else { strError += ":系统不存在该用户。"; } } else { strError += ":系统用户表无数据信息。"; } } catch (Exception ex) { strError += string.Format(":{0}。", ex.Message); } if (isLogin) { Logger.Info("用户 " + ThisUser.ChineseName + " 成功登陆系统。", MethodBase.GetCurrentMethod(), this.ThisUser.UserID); this.DialogResult = DialogResult.OK; //返回一个登录成功的对话框状态 //this.Invoke(new Action(() => { this.Close(); })); } else { Logger.Error(strError, MethodBase.GetCurrentMethod());//记录日志 MessageBox.Show(strError, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Invoke(new Action(() => { btnSubmit.Text = "登录"; btnSubmit.Enabled = true; })); } }