美文网首页
2018-11-29

2018-11-29

作者: 期末一定过 | 来源:发表于2018-11-29 20:46 被阅读0次

    2.6密码修改界面功能设计

    修改新的密码以及确认新密码


    效2.gif 捕获3.PNG
    1.输入新密码以及确认新密码后,新密码录入到数据库中
    2.连接数据库,判断新密码是否修改成功
    3.再次登录,测试新密码是否能够成功登录
    if (newPwd.Equals(""))
                {
                    MessageBox.Show("请输入新密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (confPwd.Equals(""))
                {
                    MessageBox.Show("请输入确认密码", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (newPwd != confPwd)
                {
                    MessageBox.Show("两次密码不一致", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
    
                // 连接字符串,注意与实际环境保持一致
                String connStr = "Data Source=.;Initial Catalog=SuperMarketSales;Integrated Security=True";
                SqlConnection sqlConn = new SqlConnection(connStr);
                try
                {
                    // 连接数据库
                    sqlConn.Open();
    
                    // 构造命令
                    String sqlStr = "update EMPLOYEE set PASSWORD=@pwd where ID=@id";
                    SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);
    
                    // SQL字符串参数赋值
                    cmd.Parameters.Add(new SqlParameter("@pwd", newPwd));
                    cmd.Parameters.Add(new SqlParameter("@id", UserInfo.userId));
    
                    // 将命令发送给数据库
                    int res = cmd.ExecuteNonQuery();
    
                    // 根据返回值判断是否修改成功
                    if (res != 0)
                    {
                        MessageBox.Show("密码修改成功");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("密码修改错误");
                    }
                }
             
                }
            }
    

    相关文章

      网友评论

          本文标题:2018-11-29

          本文链接:https://www.haomeiwen.com/subject/gmqqcqtx.html