private void btnConfirm_Click(object sender, EventArgs e) { var userName = this.txtUserName.Text; var oldPassword = this.txtOldPassword.Text; var newPassword = this.txtNewPassword.Text; var confirmPassword = this.txtConfirmPassword.Text; if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(oldPassword) || string.IsNullOrEmpty(newPassword) || string.IsNullOrEmpty(confirmPassword)) { MessageBox.Show("请填写基本信息!", "信息错误!"); return; } if (newPassword != confirmPassword) { MessageBox.Show("两次填写的密码不一致!", "信息错误!"); return; } var webUserInfo = new WebUserInfo() { UserID = int.Parse(this.txtUserInfoID.Text), UserName = userName, ConfirmPassword = confirmPassword, NewPassword = newPassword, OldPassword = oldPassword, }; var result = new UserBLL().UpdateUserInfo(webUserInfo); if (result.Code > 0) { MessageBox.Show(result.Message, SystemInfo.ErrorReminderStr, MessageBoxButtons.OK); } else { MessageBox.Show("修改成功", SystemInfo.SuccessReminderStr, MessageBoxButtons.OK); this.Close(); } }
public CResult<WebUserInfo> GetUserInfoByName(string userName) { if (string.IsNullOrEmpty(userName)) { return new CResult<WebUserInfo>(null, ErrorCode.ParameterError); } var userInfo = new UserInfoDAL().GetUserInfoByName(userName); if (userInfo == null) { return new CResult<WebUserInfo>(null, ErrorCode.UserNotExist); } var webUserInfo = new WebUserInfo() { UserName = userInfo.UserName, UserID = userInfo.UserID }; return new CResult<WebUserInfo>(webUserInfo); }
public CResult<WebUserInfo> GetUserInfoByID(int userID) { if (userID <= 0) { return new CResult<WebUserInfo>(null, ErrorCode.ParameterError); } var userInfo = new UserInfoDAL().GetUserInfoByID(userID); if (userInfo == null) { return new CResult<WebUserInfo>(null, ErrorCode.UserNotExist); } var webUserInfo = new WebUserInfo() { UserName = userInfo.UserName, UserID = userInfo.UserID, OldPassword = userInfo.Password, }; return new CResult<WebUserInfo>(webUserInfo); }
public CResult<bool> UpdateUserInfo(WebUserInfo webUserInfo) { if (webUserInfo == null) { return new CResult<bool>(false, ErrorCode.ParameterError); } if (string.IsNullOrEmpty(webUserInfo.UserName) || string.IsNullOrEmpty(webUserInfo.OldPassword) || string.IsNullOrEmpty(webUserInfo.NewPassword) || string.IsNullOrEmpty(webUserInfo.ConfirmPassword)) { return new CResult<bool>(false, ErrorCode.ParameterError); } if (webUserInfo.NewPassword != webUserInfo.ConfirmPassword) { return new CResult<bool>(false, ErrorCode.ParameterError); } var oldUserInfo = GetUserInfoByID(webUserInfo.UserID).Data; if (oldUserInfo == null) { return new CResult<bool>(false, ErrorCode.UserNotExist); } if (oldUserInfo.OldPassword != webUserInfo.OldPassword) { return new CResult<bool>(false, ErrorCode.UserPasswordError); } if (oldUserInfo.UserName == webUserInfo.UserName && oldUserInfo.OldPassword == webUserInfo.NewPassword) { return new CResult<bool>(true); } var userInfo = new UserInfo() { UserID = webUserInfo.UserID, Password = webUserInfo.NewPassword, UserName = webUserInfo.UserName, }; if (new UserInfoDAL().UpdateUserInfo(userInfo)) { return new CResult<bool>(true); } else { return new CResult<bool>(false, ErrorCode.SaveDataFailed); } }