예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
            }
        }