?? modifypwd.aspx.cs
字號:
?using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class ModifyPwd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//if (this.Session["userID"] == null)
//{
// Response.Redirect("Login.aspx");
//}
}
//修改密碼按鈕事件
protected void imgBtnConfirm_Click(object sender, ImageClickEventArgs e)
{
//取參數
string userName = Session["userName"].ToString();
string oldPwd = txtOldPwd.Text.Trim();
string newPwd = txtNewPwd.Text.Trim();
string selectStr="";
string updateStr="";
switch (Session["userRole"].ToString())
{
case "0": //身份為教師時
selectStr = "Select * from Teacher where teaID = ='" + userName + "' and teaPwd='" + oldPwd + "'";
updateStr="update Teacher set teaPwd='" + newPwd + "' where teaID='" + userName + "'";
break;
case "1": //身份為學生時
selectStr = "Select * from Student where stuID = ='" + userName + "' and stuPwd='" + oldPwd + "'";
updateStr="update Student set stuPwd='" + newPwd + "' where stuID='" + userName + "'";
break;
case "2": //身份為管理員時
selectStr = "Select * from Users where adminName = ='" + userName + "' and adminPwd='" + oldPwd + "'";
updateStr="update Users set adminPwd='" + newPwd + "' where adminName='" + userName + "'";
break;
}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand selectCmd = new SqlCommand(selectStr, conn);
try
{
conn.Open();
SqlDataReader sdr = selectCmd.ExecuteReader();
if (sdr.Read()) //如果用戶存在且輸入密碼正確,修改密碼
{
sdr.Close();
SqlCommand updateCmd = new SqlCommand(updateStr, conn);
int i = updateCmd.ExecuteNonQuery();
if (i > 0) //根據修改后返回的結果給出提示
{
Response.Write("成功修改密碼!");
}
else
{
Response.Write("修改密碼失敗!");
}
}
else
{
Response.Write("您輸入的密碼錯誤,檢查后重新輸入!");
}
}
catch (System.Exception ee) //系統出錯,錯誤處理
{
Response.Write("系統出錯,錯誤原因:" + ee.Message.ToString());
}
finally
{
conn.Close();
}
}
protected void imgBtnReset_Click(object sender, ImageClickEventArgs e)
{
txtOldPwd.Text = "";
txtNewPwd.Text = "";
txtConfirmPwd.Text = "";
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -