当前位置:   article > 正文

电影记录管理系统3[密码修改]_idea影视管理系统修改密码界面

idea影视管理系统修改密码界面

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;

namespace 电影记录管理系统
{
    public partial class FrmPwdChange : Form
    {
        public FrmPwdChange()
        {
            InitializeComponent();
        }
        //连接字符串 获取文件里的连接路径
        static string connStr = ConfigurationManager.ConnectionStrings["str"].ConnectionString;
        private void FrmPwdChange_Load(object sender, EventArgs e)
        {
            //获取变量uid
            string currentUser = Form2.Uid;
            //把获取的字符串赋给用户名文本框
            txtUsername.Text = currentUser;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            //连接字符串
            SqlConnection conn = new SqlConnection();
            //获取当前密码
            string sql = "select MUserPwd from MovieAccount where MUserName ='" + txtUsername.Text + "'"; 
            //创建一个cmd对象
            SqlCommand cmd = new SqlCommand(sql,conn);
            //打开conn连接
            conn.Open();
            //读取sql数据,获取读到的数据
            SqlDataReader sdr = cmd.ExecuteReader();
            if (sdr.Read())//如果读到了数据,继续进行
            {
                string oldPwd = sdr.GetString(0).Trim();
                //如果用户输入的密码等于旧密码
                if (oldPwd == txtOldPwd.Text)
                {
                    if (txtNewPwd.Text.Trim() == "" || txtNewPwdConfirm.Text.Trim() == "")
                    {
                        //如果新密码为空,则弹出提示
                        MessageBox.Show("新密码不能为空!");
                        return;
                    }
                    else if (txtNewPwd.Text.Trim() != txtNewPwd.Text.Trim())
                    {
                        //两次新密码不一样,弹出提示
                        MessageBox.Show("你输入的密码两次不一样,请重新输入!");
                        //a清空文本框
                        txtNewPwd.Text = "";

                        txtNewPwdConfirm.Text = "";

                        return;


                    }
                    else
                    {
                        sdr.Close();
                        string sqlUpdate = "update MovieAccount set MUserPwd ='" + txtNewPwdConfirm.Text +
                       "' where MUserName ='" + txtUsername.Text + "'";
                        SqlCommand cmdUp = new SqlCommand();
                        if (cmdUp.ExecuteNonQuery() == 0)
                        {
                            MessageBox.Show("未知错误!");
                            return;
                        }
                        else
                        {
                            MessageBox.Show("恭喜你,密码修改成功!");
                        }
                    }

                }
                else
                {
                    MessageBox.Show("旧密码错误");
                    //清空文本框
                    txtNewPwd.Text = "";
                    txtOldPwd.Text = "";
                    return;
                }

            }
            else
            {
                MessageBox.Show("用户名不存在,请重新输入!");

                txtOldPwd.Text = "";
                txtUsername.Text = "";
                txtNewPwd.Text = "";
                txtNewPwdConfirm.Text = "";
                return;

            }

            //关闭数据库
            conn.Close();
        }

        private void btnBack_Click(object sender, EventArgs e)
        {
            //返回主窗体
            //new一个main窗体
            FrmMain main = new FrmMain();
            //出现密码修改主窗体
            main.Show();
            //隐藏当前的窗口
            this.Hide();
        }
    }
}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/155230
推荐阅读
相关标签
  

闽ICP备14008679号