📄 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
* 函数: checkUser(ref stirng,ref string) 检查学生的登陆情况
* dsDelay(DateTime):取得一个比系统时间少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();//读取文件内容
HttpContext.Current.Application["strcon"] = strcon;
}
else
{
strcon = HttpContext.Current.Application["strcon"].ToString();
}
}
}
/// <summary>
/// 检查学生的登陆情况
/// 0:学号或密码错误;1:改时段内没有考试;2:登陆考试状态;3:无权限参加这场考试或者已经考过 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);//调用自定义函数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分钟之前都可以进入考试系统考试,迟到min分钟后则不允许考试
/// 取得一个比系统时间少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 + -