2.6密碼修改界面功能設(shè)計(jì)

一.密碼修改界面

(1).結(jié)果展示

image.png

二. 登陸界面各控件的參數(shù)設(shè)置

控件A:Lable

屬性
Lable1 用戶名
Lable2 新密碼
Lable3 確認(rèn)密碼

控件B:TextBox

屬性
TextBox1 空白值(可輸入值)
TextBox2 空白值(可輸入值)
TextBox3 空白值(可輸入值)

控件C:Button

屬性
Button1 確定
Button2 取消

三. 界面設(shè)計(jì)

1. 用戶通過點(diǎn)擊主界面上的"修改密碼"菜單,打開修改密碼界面

     private void tsmi_Password_Click(object sender, EventArgs e)
    {
        PwdForm pwdForm = new PwdForm();
        pwdForm.MdiParent = this;
        pwdForm.StartPosition = FormStartPosition.CenterScreen;
        pwdForm.Show();
    }

2. 密碼修改界面上,默認(rèn)顯示出當(dāng)前登錄的用戶名

    private void PwdForm_Load(object sender, EventArgs e)
    {
        this.tb_User.Text = UserInfo.userName;
    }

四. 實(shí)現(xiàn)密碼修改界面的密碼修改功能

  String connStr = "Data Source=.;Initial Catalog=SuperMarketSales;Integrated Security=True";
        SqlConnection sqlConn = new SqlConnection(connStr);
        try
        {
            // 連接數(shù)據(jù)庫(kù)
            sqlConn.Open();

            // 構(gòu)造命令
            String sqlStr = "update EMPLOYEE set PASSWORD=@pwd where ID=@id";
            SqlCommand cmd = new SqlCommand(sqlStr, sqlConn);

            // SQL字符串參數(shù)賦值
            cmd.Parameters.Add(new SqlParameter("@pwd", newPwd));
            cmd.Parameters.Add(new SqlParameter("@id", UserInfo.userId));

            // 將命令發(fā)送給數(shù)據(jù)庫(kù)
            int res = cmd.ExecuteNonQuery();

            // 根據(jù)返回值判斷是否修改成功
            if (res != 0)
            {
                MessageBox.Show("密碼修改成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("密碼修改錯(cuò)誤");
            }
        }
        catch (Exception exp)
        {
            MessageBox.Show("訪問數(shù)據(jù)庫(kù)錯(cuò)誤:" + exp.ToString());
        }
        finally
        {
            sqlConn.Close();
        }
    }

五.修改密碼界面細(xì)節(jié)設(shè)計(jì)代碼

      // 在“新密碼”輸入框中按“回車”,光標(biāo)跳轉(zhuǎn)到“確認(rèn)密碼”輸入框
        private void tb_NewPwd_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.Enter)
        {
            SendKeys.Send("{tab}");
        }
    }

    // 在“確認(rèn)密碼”輸入框中按“回車”,則直接修改密碼
    private void tb_ConfirmPwd_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (e.KeyChar == (char)Keys.Enter)
        {
            this.bt_Ok_Click(sender, e);
        }
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容