温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:在线考试系统源码及论文
当前文件:
OnlineTestSystem/Default.aspx.cs,打开代码结构图
OnlineTestSystem/Default.aspx.cs,打开代码结构图1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
using System.Data.OleDb; 11
12
public partial class _Default : System.Web.UI.Page 13
{ 14
protected void Page_Load(object sender, EventArgs e) 15
{ 16
17
} 18
19
protected void testlogbtn_Click(object sender, EventArgs e) 20
{ 21
string username = usernametxt.Text.Trim(); 22
string password = pawtxt.Text.Trim(); 23
string connecionstring =(string)Application["connectstring"]; 24
OleDbConnection conn = new OleDbConnection(connecionstring); 25
try 26
{ 27
bool flag=false; 28
conn.Open(); 29
string commandtext = "select distinct * from student where studentname='" + username + "' and paw='" + password + "'"; 30
OleDbCommand checkcommand = new OleDbCommand(commandtext, conn); 31
OleDbDataReader dr = checkcommand.ExecuteReader(); 32
flag = dr.HasRows; 33
if (flag) 34
{ 35
Session.Add("username", username); 36
Session.Add("logintime", System.DateTime.Now.ToLongTimeString()); 37
conn.Close(); 38
Response.Redirect("test.aspx"); 39
} 40
else 41
{ 42
lblmessage.Text = "用户名或密码错误,请重新登陆!"; 43
usernametxt.Text = ""; 44
pawtxt.Text = ""; 45
} 46
47
} 48
catch (Exception err) 49
{ 50
Response.Write(err.Message); 51
//Response.Redirect("error.aspx"); 52
} 53
finally 54
{ 55
if (conn.State == ConnectionState.Open) 56
conn.Close(); 57
} 58
59
} 60
61
protected void adminlogbtn_Click(object sender, EventArgs e) 62
{ 63
string username = usernametxt.Text.Trim(); 64
string password = pawtxt.Text.Trim(); 65
string connecionstring = (string)Application["connectstring"]; 66
OleDbConnection conn = new OleDbConnection(connecionstring); 67
try 68
{ 69
bool flag = false; 70
conn.Open(); 71
string commandtext = "select distinct * from admin where name='" + username + "' and password='" + password + "'"; 72
OleDbCommand checkcommand = new OleDbCommand(commandtext, conn); 73
OleDbDataReader dr = checkcommand.ExecuteReader(); 74
flag = dr.HasRows; 75
if (flag) 76
{ 77
Session.Add("username", username); 78
Session.Add("logintime", System.DateTime.Now.ToLongTimeString()); 79
Session.Add("role", "adminstrator"); 80
conn.Close(); 81
Response.Redirect("guanli.aspx"); 82
} 83
else 84
{ 85
lblmessage.Text = "用户名或密码错误,请重新登陆!"; 86
usernametxt.Text = ""; 87
pawtxt.Text = ""; 88
} 89
90
} 91
catch (Exception err) 92
{ 93
Response.Write(err.Message); 94
//Response.Redirect("error.aspx"); 95
} 96
finally 97
{ 98
if (conn.State == ConnectionState.Open) 99
conn.Close(); 100
} 101
} 102
103
} 104





}
}