温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:Asp.net简单网络选课系统源码
当前文件路径:MyElectCourse/ModifyPwd.aspx.cs

1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Collections; 5
using System.Web; 6
using System.Web.Security; 7
using System.Web.UI; 8
using System.Web.UI.WebControls; 9
using System.Web.UI.WebControls.WebParts; 10
using System.Web.UI.HtmlControls; 11
using System.Data.SqlClient; 12
13
public partial class ModifyPwd : System.Web.UI.Page 14
{ 15
protected void Page_Load(object sender, EventArgs e) 16
{ 17
//if (this.Session["userID"] == null) 18
//{ 19
// Response.Redirect("Login.aspx"); 20
//} 21
} 22
23
//修改密码按钮事件 24
protected void imgBtnConfirm_Click(object sender, ImageClickEventArgs e) 25
{ 26
//取参数 27
string userName = Session["userName"].ToString(); 28
string oldPwd = txtOldPwd.Text.Trim(); 29
string newPwd = txtNewPwd.Text.Trim(); 30
string selectStr=""; 31
string updateStr=""; 32
switch (Session["userRole"].ToString()) 33
{ 34
case "0": //身份为教师时 35
selectStr = "Select * from Teacher where teaID = ='" + userName + "' and teaPwd='" + oldPwd + "'"; 36
updateStr="update Teacher set teaPwd='" + newPwd + "' where teaID='" + userName + "'"; 37
break; 38
case "1": //身份为学生时 39
selectStr = "Select * from Student where stuID = ='" + userName + "' and stuPwd='" + oldPwd + "'"; 40
updateStr="update Student set stuPwd='" + newPwd + "' where stuID='" + userName + "'"; 41
break; 42
case "2": //身份为管理员时 43
selectStr = "Select * from Users where adminName = ='" + userName + "' and adminPwd='" + oldPwd + "'"; 44
updateStr="update Users set adminPwd='" + newPwd + "' where adminName='" + userName + "'"; 45
break; 46
} 47
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString); 48
SqlCommand selectCmd = new SqlCommand(selectStr, conn); 49
try 50
{ 51
conn.Open(); 52
SqlDataReader sdr = selectCmd.ExecuteReader(); 53
if (sdr.Read()) //如果用户存在且输入密码正确,修改密码 54
{ 55
sdr.Close(); 56
SqlCommand updateCmd = new SqlCommand(updateStr, conn); 57
int i = updateCmd.ExecuteNonQuery(); 58
if (i > 0) //根据修改后返回的结果给出提示 59
{ 60
Response.Write("成功修改密码!"); 61
} 62
else 63
{ 64
Response.Write("修改密码失败!"); 65
} 66
} 67
else 68
{ 69
Response.Write("您输入的密码错误,检查后重新输入!"); 70
} 71
} 72
catch (System.Exception ee) //系统出错,错误处理 73
{ 74
Response.Write("系统出错,错误原因:" + ee.Message.ToString()); 75
} 76
finally 77
{ 78
conn.Close(); 79
} 80
} 81
protected void imgBtnReset_Click(object sender, ImageClickEventArgs e) 82
{ 83
txtOldPwd.Text = ""; 84
txtNewPwd.Text = ""; 85
txtConfirmPwd.Text = ""; 86
} 87
} 88






}