温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:Asp.net在线考试系统源码及毕业设计论文
当前文件:
ExamOnline/App_Code/login.cs[7K,2009-6-12 11:42:06],打开代码结构图
ExamOnline/App_Code/login.cs[7K,2009-6-12 11:42:06],打开代码结构图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.SqlClient; 11
using System.IO; 12
13
/************************************************************************************************* 14
* 文件名:login.cs 15
* 信息:有关登陆的信息 16
* 作者:mcz 17
* 函数: checkUser(ref stirng,ref string) 检查学生的登陆情况 18
* dsDelay(DateTime):取得一个比系统时间少min分钟的时间 19
**************************************************************************************************/ 20
21
namespace ExamOnline 22
{ 23
24
public class Login 25
{ 26
string strcon = ""; 27
public Login() 28
{ 29
if (strcon == "") 30
{ 31
if (HttpContext.Current.Application["strcon"] == null) 32
{ 33
string path = HttpContext.Current.Request.PhysicalApplicationPath + "DBSet.ini";//获取文件物理路径 34
StreamReader sr = new StreamReader(path, System.Text.Encoding.Default); 35
strcon = sr.ReadLine();//读取文件内容 36
HttpContext.Current.Application["strcon"] = strcon; 37
} 38
else 39
{ 40
strcon = HttpContext.Current.Application["strcon"].ToString(); 41
} 42
} 43
} 44
45
46
/// <summary> 47
/// 检查学生的登陆情况 48
/// 0:学号或密码错误;1:改时段内没有考试;2:登陆考试状态;3:无权限参加这场考试或者已经考过 4:迟到30分钟以上或者考试还未开始 49
/// </summary> 50
/// <param name="userID"></param> 51
/// <param name="userPWD"></param> 52
/// <returns></returns> 53
public int checkUser(ref string userID,ref string userPWD) 54
{ 55
56
SqlConnection con = new SqlConnection(strcon); 57
string strcmd = "select * from students where stu_id = @ID and pwd = @PWD"; 58
SqlCommand cmd = new SqlCommand(strcmd,con); 59
cmd.Parameters.Add("@ID",SqlDbType.VarChar,20).Value = userID; 60
cmd.Parameters.Add("@PWD",SqlDbType.VarChar,20).Value = userPWD; 61
con.Open(); 62
SqlDataReader dr = cmd.ExecuteReader(); 63
64
if (dr.Read()) //学号和密码正确,再判断是登陆考试还是登陆练习 65
{ 66
dr.Close(); 67
string strcmdExam = "select * from testpaper_list where paper_time > @dtNow and test=1 and audit=1 order by paper_time asc "; 68
SqlCommand cmdExam = new SqlCommand(strcmdExam,con); 69
cmdExam.Parameters.Add("@dtNow", SqlDbType.DateTime).Value = dsDelay(30);//调用自定义函数dsDelay() 70
SqlDataReader drExam = cmdExam.ExecuteReader(); 71
72
if (drExam.Read()) 73
{ 74
DateTime dsExam = drExam.GetDateTime(2); //取得试卷的考试时间 75
//int examID = drExam.GetInt32(0); 76
string strcmdpaperID = "select * from paper_students where paper_id=@paperID and stu_id=@userID and stu_state=0"; 77
SqlCommand cmdpaperID = new SqlCommand(strcmdpaperID,con); 78
cmdpaperID.Parameters.Add("@paperID", SqlDbType.Int).Value = drExam.GetInt32(0); 79
cmdpaperID.Parameters.Add("@userID",SqlDbType.VarChar,20).Value = userID; 80
drExam.Close(); 81
SqlDataReader drpaperID = cmdpaperID.ExecuteReader(); 82
83
if (drpaperID.Read()) 84
{ 85
if (dsExam <= dsDelay(-10)) //允许提前10分钟登陆考试 86
{ 87
drpaperID.Close(); 88
con.Close(); 89
90
return 2; 91
} 92
else 93
{ 94
drpaperID.Close(); 95
con.Close(); 96
return 4; 97
} 98
99
} 100
else 101
{ 102
drpaperID.Close(); 103
con.Close(); 104
return 3; 105
} 106
107
} 108
else 109
{ 110
drExam.Close(); 111
con.Close(); 112
return 1; 113
} 114
115
} 116
else 117
{ 118
dr.Close(); 119
con.Close(); 120
return 0; 121
} 122
} 123
124
/// <summary> 125
/// 考生在迟到min分钟之前都可以进入考试系统考试,迟到min分钟后则不允许考试 126
/// 取得一个比系统时间少min分钟的时间 127
/// </summary> 128
/// <param name="min"></param> 129
/// <returns></returns> 130
public DateTime dsDelay(int min) 131
{ 132
TimeSpan ts = new TimeSpan(0,min,0); 133
DateTime ds = DateTime.Now.Subtract(ts); 134
return ds; 135
} 136
/// <summary> 137
/// 学生修改登陆密码的时候检查用户的合法性 138
/// </summary> 139
/// <param name="userID"></param> 140
/// <param name="userPWD"></param> 141
/// <returns></returns> 142
public bool checkPWD(ref string userID, ref string userPWD,ref string newPWD) 143
{ 144
SqlConnection con = new SqlConnection(strcon); 145
string strcmd = "select * from students where stu_id = @ID and pwd = @PWD"; 146
SqlCommand cmd = new SqlCommand(strcmd, con); 147
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 20).Value = userID; 148
cmd.Parameters.Add("@PWD", SqlDbType.VarChar, 20).Value = userPWD; 149
con.Open(); 150
SqlDataReader dr = cmd.ExecuteReader(); 151
if(dr.Read()) 152
{ 153
dr.Close(); 154
string strrepwd = "update students set pwd='" + newPWD + "' where stu_id='" + userID + "'"; 155
try 156
{ 157
(new ExamOnline.Exam()).exec(strrepwd); 158
con.Close(); 159
return true; 160
} 161
catch(Exception ee) 162
{ 163
ExamOnline.Common.ShowMess(ee.Message); 164
} 165
} 166
con.Close(); 167
return false; 168
} 169
170
/// <summary> 171
/// 学生修改登陆密码的时候检查用户的合法性 172
/// </summary> 173
/// <param name="userID"></param> 174
/// <param name="userPWD"></param> 175
/// <returns></returns> 176
public bool checkPWD(ref string userID, ref string userPWD) 177
{ 178
SqlConnection con = new SqlConnection(strcon); 179
string strcmd = "select * from students where stu_id = @ID and pwd = @PWD"; 180
SqlCommand cmd = new SqlCommand(strcmd, con); 181
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 20).Value = userID; 182
cmd.Parameters.Add("@PWD", SqlDbType.VarChar, 20).Value = userPWD; 183
con.Open(); 184
SqlDataReader dr = cmd.ExecuteReader(); 185
if (dr.Read()) 186
{ 187
con.Close(); 188
return true; 189
} 190
con.Close(); 191
return false; 192
} 193
} 194
} 195





* 文件名:login.cs
*************************************************************************************************
}