温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:明日网络考试系统源码
当前文件:
NetExam/Default.aspx.cs,打开代码结构图
NetExam/Default.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 Default : System.Web.UI.Page 14
{ 15
Datacon dataconn = new Datacon(); 16
protected void Page_Load(object sender, EventArgs e) 17
{ 18
Session["StuName"] = this.txtUserName.Text; 19
if (!IsPostBack) 20
{ 21
Random rnd = new Random(); 22
//生成验证码 23
this.labValidate.Text = rnd.Next(1000,9999).ToString(); 24
} 25
} 26
//==============================找回密码========================= 27
protected void Button3_Click(object sender, EventArgs e) 28
{ 29
Page.Response.Redirect("InfoPwd.aspx"); 30
} 31
//==============================新学生注册========================= 32
protected void Button2_Click(object sender, EventArgs e) 33
{ 34
Page.Response.Redirect("zhuce.aspx"); 35
} 36
//==============================登录按钮========================= 37
protected void Button1_Click(object sender, EventArgs e) 38
{ 39
if (txtValidate.Text != labValidate.Text) 40
{ 41
Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>"); 42
} 43
else 44
{ 45
if (cblAdminLog.Items[0].Selected == true) 46
{ 47
this.getcom(1); 48
} 49
else 50
{ 51
this.getcom(2); 52
} 53
} 54
} 55
//==============================登录控制============================ 56
private void getcom(int i) 57
{ 58
SqlConnection con = dataconn.getcon(); 59
con.Open(); 60
SqlCommand com=con.CreateCommand(); 61
switch (i) 62
{ 63
case 1: 64
com.CommandText = "select count(*) from tb_Administrator where Name='" + txtUserName.Text + "' and PWD='" + txtPwd.Text + "'"; 65
int count1 = Convert.ToInt32(com.ExecuteScalar());//获取SQL语句的值 强制转换成数值类型 66
if (count1 > 0) 67
{ 68
Application["Name"] = txtUserName.Text;//成功 69
Application["PWD"] = txtPwd.Text;//成功 70
Page.Response.Redirect("HouAdmin/admin.aspx"); 71
} 72
else 73
{ 74
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>"); 75
return; 76
} 77
break; 78
case 2: 79
com.CommandText = "select count(*) from tb_Student where ID='" + txtUserName.Text + "' and PWD='" + txtPwd.Text + "'"; 80
int count2 = Convert.ToInt32(com.ExecuteScalar()); 81
if (count2 > 0) 82
{ 83
Application["ID"] = txtUserName.Text; 84
Application["PWD"] = txtPwd.Text; 85
Page.Response.Redirect("QianUser/zaixian_kaoshi.aspx"); 86
} 87
else 88
{ 89
Response.Write("<script lanuage=javascript>alert('用户名或密码有误!');location='javascript:history.go(-1)'</script>"); 90
return; 91
} 92
break; 93
} 94
con.Close(); 95
} 96
} 97




Datacon dataconn 
}
}