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.Data.SqlClient;

namespace ch11
{
    public partial class EditPassWord : Form
    {
        public EditPassWord()
        {
            InitializeComponent();
        }

        private void EditPassWord_Load(object sender, EventArgs e)
        {
            txtName.Text = dormConn.name;

        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtPass.Text == "" || txtNewpass.Text == "" || txtNewPassAgin.Text == "")
            {
                MessageBox.Show("信息输入不完整！");

            }
            else
            {
                SqlConnection con = new SqlConnection(dormConn.connection);
                SqlCommand cmd = new SqlCommand("", con);
                string sql = "select * from U_userinfor where U_UserName='" + txtName.Text + "' and U_Pwd='" + txtPass.Text + "'";
                cmd.CommandText = sql;
                con.Open();
                if(null!=cmd.ExecuteScalar())//判断原来密码是否正确，验证效果。
                {
                    if (txtNewpass.Text == txtNewPassAgin.Text)
                    {
                        sql = "update U_userinfor set U_Pwd='" + txtNewpass.Text + "' where U_UserName='" + txtName.Text + "'";//修改语句
                        cmd.CommandText = sql;
                        cmd.ExecuteNonQuery();
                        MessageBox.Show("密码修改成功！", "提示");
                    }
                    else
                    {
                        MessageBox.Show("两次输入的密码不一致！","提示！");
                    }
                    con.Close();
                }

            
            }

        }
    }
}
