?? login.cs
字號:
?using System;
using System.Data;
using System.Configuration;
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;
using System.IO;
/*************************************************************************************************
* 文件名:login.cs
* 信息:有關登陸的信息
* 作者:mcz
* 函數(shù): checkUser(ref stirng,ref string) 檢查學生的登陸情況
* dsDelay(DateTime):取得一個比系統(tǒng)時間少min分鐘的時間
**************************************************************************************************/
namespace ExamOnline
{
public class Login
{
string strcon = "";
public Login()
{
if (strcon == "")
{
if (HttpContext.Current.Application["strcon"] == null)
{
string path = HttpContext.Current.Request.PhysicalApplicationPath + "DBSet.ini";//獲取文件物理路徑
StreamReader sr = new StreamReader(path, System.Text.Encoding.Default);
strcon = sr.ReadLine();//讀取文件內(nèi)容
HttpContext.Current.Application["strcon"] = strcon;
}
else
{
strcon = HttpContext.Current.Application["strcon"].ToString();
}
}
}
/// <summary>
/// 檢查學生的登陸情況
/// 0:學號或密碼錯誤;1:改時段內(nèi)沒有考試;2:登陸考試狀態(tài);3:無權(quán)限參加這場考試或者已經(jīng)考過 4:遲到30分鐘以上或者考試還未開始
/// </summary>
/// <param name="userID"></param>
/// <param name="userPWD"></param>
/// <returns></returns>
public int checkUser(ref string userID,ref string userPWD)
{
SqlConnection con = new SqlConnection(strcon);
string strcmd = "select * from students where stu_id = @ID and pwd = @PWD";
SqlCommand cmd = new SqlCommand(strcmd,con);
cmd.Parameters.Add("@ID",SqlDbType.VarChar,20).Value = userID;
cmd.Parameters.Add("@PWD",SqlDbType.VarChar,20).Value = userPWD;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read()) //學號和密碼正確,再判斷是登陸考試還是登陸練習
{
dr.Close();
string strcmdExam = "select * from testpaper_list where paper_time > @dtNow and test=1 and audit=1 order by paper_time asc ";
SqlCommand cmdExam = new SqlCommand(strcmdExam,con);
cmdExam.Parameters.Add("@dtNow", SqlDbType.DateTime).Value = dsDelay(30);//調(diào)用自定義函數(shù)dsDelay()
SqlDataReader drExam = cmdExam.ExecuteReader();
if (drExam.Read())
{
DateTime dsExam = drExam.GetDateTime(2); //取得試卷的考試時間
//int examID = drExam.GetInt32(0);
string strcmdpaperID = "select * from paper_students where paper_id=@paperID and stu_id=@userID and stu_state=0";
SqlCommand cmdpaperID = new SqlCommand(strcmdpaperID,con);
cmdpaperID.Parameters.Add("@paperID", SqlDbType.Int).Value = drExam.GetInt32(0);
cmdpaperID.Parameters.Add("@userID",SqlDbType.VarChar,20).Value = userID;
drExam.Close();
SqlDataReader drpaperID = cmdpaperID.ExecuteReader();
if (drpaperID.Read())
{
if (dsExam <= dsDelay(-10)) //允許提前10分鐘登陸考試
{
drpaperID.Close();
con.Close();
return 2;
}
else
{
drpaperID.Close();
con.Close();
return 4;
}
}
else
{
drpaperID.Close();
con.Close();
return 3;
}
}
else
{
drExam.Close();
con.Close();
return 1;
}
}
else
{
dr.Close();
con.Close();
return 0;
}
}
/// <summary>
/// 考生在遲到min分鐘之前都可以進入考試系統(tǒng)考試,遲到min分鐘后則不允許考試
/// 取得一個比系統(tǒng)時間少min分鐘的時間
/// </summary>
/// <param name="min"></param>
/// <returns></returns>
public DateTime dsDelay(int min)
{
TimeSpan ts = new TimeSpan(0,min,0);
DateTime ds = DateTime.Now.Subtract(ts);
return ds;
}
/// <summary>
/// 學生修改登陸密碼的時候檢查用戶的合法性
/// </summary>
/// <param name="userID"></param>
/// <param name="userPWD"></param>
/// <returns></returns>
public bool checkPWD(ref string userID, ref string userPWD,ref string newPWD)
{
SqlConnection con = new SqlConnection(strcon);
string strcmd = "select * from students where stu_id = @ID and pwd = @PWD";
SqlCommand cmd = new SqlCommand(strcmd, con);
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 20).Value = userID;
cmd.Parameters.Add("@PWD", SqlDbType.VarChar, 20).Value = userPWD;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if(dr.Read())
{
dr.Close();
string strrepwd = "update students set pwd='" + newPWD + "' where stu_id='" + userID + "'";
try
{
(new ExamOnline.Exam()).exec(strrepwd);
con.Close();
return true;
}
catch(Exception ee)
{
ExamOnline.Common.ShowMess(ee.Message);
}
}
con.Close();
return false;
}
/// <summary>
/// 學生修改登陸密碼的時候檢查用戶的合法性
/// </summary>
/// <param name="userID"></param>
/// <param name="userPWD"></param>
/// <returns></returns>
public bool checkPWD(ref string userID, ref string userPWD)
{
SqlConnection con = new SqlConnection(strcon);
string strcmd = "select * from students where stu_id = @ID and pwd = @PWD";
SqlCommand cmd = new SqlCommand(strcmd, con);
cmd.Parameters.Add("@ID", SqlDbType.VarChar, 20).Value = userID;
cmd.Parameters.Add("@PWD", SqlDbType.VarChar, 20).Value = userPWD;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
con.Close();
return true;
}
con.Close();
return false;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -