private void DeleteUser(string username) { if (username == "admin") { return; } var dt = userHelper.GetUserInfo(username).Tables[0]; if (dt.Rows.Count < 1) { return; } var roleID = dt.Rows[0][0].ToString(); if (roleID == "0")//admin { return; } if (MessageBox.Show($"确认要删除用户【{username}】?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.OK) { return; } int delV = userHelper.DeleteUser(username); if (delV == 1) { SelectAllUser(); MessageBox.Show("删除成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } MessageBox.Show("删除失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); }
private void GetBackPassword() { var username = this.tb_username.Text.Trim(); var password = this.tb_pwd.Text.Trim(); var confirmPwd = this.tb_repwd.Text.Trim(); if (string.IsNullOrEmpty(username)) { MessageBox.Show("用户名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(password)) { MessageBox.Show("密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(confirmPwd)) { MessageBox.Show("确认密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var dt = userHelper.GetUserInfo(username).Tables[0]; if (dt.Rows.Count < 1) { MessageBox.Show("用户名不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (password != confirmPwd) { MessageBox.Show("两次密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } var userID = userHelper.GetUserID(username); var res = userHelper.ModifyUserPassword(username, username, confirmPwd); if (res == 1) { MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } else { MessageBox.Show("修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void CommitUserModify() { var username = this.tb_user.Text.Trim(); var oldPwd = this.tb_oldPwd.Text.Trim(); var newPwd = this.tb_newPwd.Text.Trim(); var confirmPwd = this.tb_confirmPwd.Text.Trim(); if (string.IsNullOrEmpty(username)) { MessageBox.Show("用户名称不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(oldPwd)) { MessageBox.Show("旧密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(newPwd)) { MessageBox.Show("新密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(confirmPwd)) { MessageBox.Show("确认密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var dt = userHelper.GetUserInfo(username).Tables[0]; if (dt.Rows.Count > 0) { //用户已存在 //用户不能是已经存在的其他用户名 if (username != userName) { MessageBox.Show("该用户名已存在,请重新输入用户名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } //验证旧密码 var loginResult = userHelper.Login(userName, oldPwd); if (loginResult == UserHelper.LoginResult.Err_Password) { MessageBox.Show("旧密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (newPwd != confirmPwd) { MessageBox.Show("新密码与确认密码不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var res = userHelper.ModifyUserPassword(userName, username, confirmPwd); if (res == 1) { UserOperateRecord.UpdateOperateRecord($"修改密码"); MessageBox.Show("修改成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); this.DialogResult = DialogResult.OK; } else { MessageBox.Show("修改失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
private void RegisterUser() { var username = this.tb_username.Text.Trim(); var userpwd = this.tb_pwd.Text.Trim(); var userRpwd = this.tb_repwd.Text.Trim(); var userType = this.cb_userType.Text.Trim(); if (string.IsNullOrEmpty(userType.ToString())) { MessageBox.Show("用户类型不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(username)) { MessageBox.Show("用户名不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(userpwd)) { MessageBox.Show("密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (string.IsNullOrEmpty(userRpwd)) { MessageBox.Show("确认密码不能为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DataSet dataSet = userHelper.GetUserInfo(username); if (dataSet.Tables[0].Rows.Count > 0) { MessageBox.Show("用户已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); tb_username.ForeColor = Color.Red; return; } tb_username.ForeColor = Color.Black; if (userpwd != userRpwd) { MessageBox.Show("两次密码不一致?", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //校验密码复杂度 if (!RegexHelper.IsMatchPassword(userpwd)) { //密码复杂度不满足 MessageBox.Show("密码必须包含数字、字母", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } var registerResult = userHelper.Register(username, userpwd, userType); if (registerResult == UserHelper.RegisterResult.Successful) { //注册成功 UserOperateRecord.UpdateOperateRecord($"新增用户-{username}"); MessageBox.Show("注册成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); this.DialogResult = DialogResult.OK; } else if (registerResult == UserHelper.RegisterResult.Err_Exist_user) { MessageBox.Show("用户已存在!", "提示", MessageBoxButtons.OK); } else if (registerResult == UserHelper.RegisterResult.Fail) { MessageBox.Show("注册失败!", "提示", MessageBoxButtons.OK); } }