📄 test.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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 ExamBLL.Auto_Generated_Code;
using ExamDAL.Auto_Generated_Code;
using ExamModel.Auto_Generated_Code;
public partial class Test : System.Web.UI.Page
{
Paper paper = new Paper();
User user;
string time;
int paperId;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
user = (User)Session["user"];
if (user != null)
{
//this.Label3.Attributes.Add("onLoad", this.Label3.Text);
this.Label3.Attributes.Add("onLoad", "32");
paperId = Convert.ToInt32(Session["PaperID"].ToString());
//paperId = 10;
paper = PaperManager.GetPaperById(paperId);
this.Label2.Text = paper.PaperName.ToString();
// this.Label1.Text = Session["UserID"].ToString();
this.Label1.Text = user.UID;
InitData();
}
else
{
Response.Redirect("~/Login.aspx");//转向考试界面
}
}
catch
{
paperId = -1;
}
// paper = PaperManager.GetPaperById(paperId);
// this.Label2.Text = paper.PaperName.ToString();
//// this.Label1.Text = Session["UserID"].ToString();
// user =(User) Session["user"];
// this.Label1.Text = user.UID;
// InitData();
}
}
public void InitData()
{
DataSet ds1 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "单选题");
GridView1.DataSource = ds1;
GridView1.DataBind();
((Label)GridView1.HeaderRow.FindControl("Label5")).Text = ((Label)GridView1.Rows[0].FindControl("Label31")).Text;
DataSet ds2 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "多选题");
GridView2.DataSource = ds2;
GridView2.DataBind();
((Label)GridView2.HeaderRow.FindControl("Label10")).Text = ((Label)GridView2.Rows[0].FindControl("Label32")).Text;
DataSet ds3 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "判断题");
GridView3.DataSource = ds3;
GridView3.DataBind();
((Label)GridView3.HeaderRow.FindControl("Label11")).Text = ((Label)GridView3.Rows[0].FindControl("Label33")).Text;
DataSet ds4 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "填空题");
GridView4.DataSource = ds4;
GridView4.DataBind();
((Label)GridView4.HeaderRow.FindControl("Label12")).Text = ((Label)GridView4.Rows[0].FindControl("Label34")).Text;
DataSet ds5 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "简答题");
GridView5.DataSource = ds5;
GridView5.DataBind();
((Label)GridView5.HeaderRow.FindControl("Label13")).Text = ((Label)GridView5.Rows[0].FindControl("Label35")).Text;
}
protected void Button1_Click(object sender, EventArgs e)
{
//////////////按开始结束算//////////////////////
time = DateTime.Now.ToString();
/////////////////////////////////////////////////
Hashtable htsing = new Hashtable();
Hashtable htMulit=new Hashtable();
Hashtable htjudge = new Hashtable();
Hashtable htfill = new Hashtable();
int score1 = 0;
int size = 0;
int singlemark = int.Parse(((Label)GridView1.Rows[0].FindControl("Label31")).Text);//取出单选题的每题分值
foreach (GridViewRow dr in GridView1.Rows)//对单选题每题进行判断用户选择答案
{
string str = "";
if (((RadioButton)dr.FindControl("RadioButton1")).Checked)
{
str = "A";
}
else if (((RadioButton)dr.FindControl("RadioButton2")).Checked)
{
str = "B";
}
else if (((RadioButton)dr.FindControl("RadioButton3")).Checked)
{
str = "C";
}
else if (((RadioButton)dr.FindControl("RadioButton4")).Checked)
{
str = "D";
}
if (((Label)dr.FindControl("Label4")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score1 = score1 + singlemark;
size = size + 1;
}
htsing.Add(dr.RowIndex, str);
}
///////////////////////////////////////////
Session["htsing"] = htsing;//保存单选题答案
///////////////////////////////////////////
int multimark = int.Parse(((Label)GridView2.Rows[0].FindControl("Label32")).Text);//取出多选题每题分值
foreach (GridViewRow dr in GridView2.Rows)//对多选题每题进行判断用户选择答案
{
string str = "";
if (((CheckBox)dr.FindControl("CheckBox1")).Checked)
{
str += "A";
}
if (((CheckBox)dr.FindControl("CheckBox3")).Checked)
{
str += "B";
}
if (((CheckBox)dr.FindControl("CheckBox2")).Checked)
{
str += "C";
}
if (((CheckBox)dr.FindControl("CheckBox4")).Checked)
{
str += "D";
}
if (((Label)dr.FindControl("Label16")).Text.Trim() == str)//将用户选择结果和答案进行比较
{
score1 = score1 + multimark;
size = size + 1;
}
htMulit.Add(dr.RowIndex, str);
}
///////////////////////////////////////////////
Session["htMulit"] = htMulit;//保存多选题答案
//////////////////////////////////////////////
int judgemark = int.Parse(((Label)GridView3.Rows[0].FindControl("Label33")).Text);//取出判断题每题分值
foreach (GridViewRow dr in GridView3.Rows)//对判断题每题进行判断用户选择答案
{
bool j = false;
if (((CheckBox)dr.FindControl("CheckBox5")).Checked)
{
j = true;
}
if (j == bool.Parse(((Label)dr.FindControl("Label23")).Text.Trim()))
{
score1 = score1 + judgemark;
size = size + 1;
}
htjudge.Add(dr.RowIndex, j);
}
////////////////////////////////////////////
Session["htjudge"] = htjudge;//保存判断题
///////////////////////////////////////////
int fillmark = int.Parse(((Label)GridView4.Rows[0].FindControl("Label34")).Text);//取出填空题每题分值
foreach (GridViewRow dr in GridView4.Rows)
{
string str = "";
str = ((TextBox)dr.FindControl("TextBox1")).Text.Trim();
if (str == ((Label)dr.FindControl("Label27")).Text.Trim())
{
score1 = score1 + fillmark;
size = size + 1;
}
htfill.Add(dr.RowIndex, str);
}
///////////////////////////////////////////////////////////
Session["htfill"] = htfill;//保存真空题
////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////
///////////////////////统计客观题分数
//////////////////////////////////////////////////////////////////////////////////////////
double allQuestion = GridView1.Rows.Count + GridView2.Rows.Count + GridView3.Rows.Count + GridView4.Rows.Count;
double rate = (size / allQuestion) * 100;
Session["rate"] = rate.ToString();
Session["Mark"] = score1.ToString();
Score score = new Score();
paperId =Int32.Parse( Session["PaperID"].ToString());
// int userid = Int32.Parse(Session["UserID"].ToString());
user =(User) Session["user"];
string userid = user.UID.ToString();
score.UID=UserManager.GetUserByuserid(userid);//获取学号
score.PaperID = PaperManager.GetPaperById(paperId);
score.FrontScore = score1;
//score.BackScore = score2;
score.BackScore = 0;
score.TotleScore = score1 + 0;
score.RightRate = rate.ToString() + "%";
score.ExamTime = time;
int i = ScoreService.AddScore(score);
if (i > 0)
{
JianDaAdd(score.UID.UID);
Response.Redirect("TestFinish.aspx");
}
else
{
Response.Write("<script language=javascript>alert('提交失败!请重新提交')</script>");
}
}
protected void JianDaAdd(string uid)
{
//////////////////////////////////////简答题管理///////////////////////////////////////////////////////////
Score score = ScoreManager.GetScoreByuid(uid);
int jiandamark = int.Parse(((Label)GridView5.Rows[0].FindControl("Label35")).Text);//取出填空题每题分值
foreach (GridViewRow dr in GridView5.Rows)
{
int rowindex = dr.RowIndex;
string str = ((TextBox)dr.FindControl("TextBox2")).Text.Trim();
string title = ((Label)GridView5.Rows[rowindex].FindControl("Label29")).Text;
/////////////////////向数据库里添加///////////////////////
user = (User)Session["user"];
String Ui = user.UID.ToString();
paperId = Convert.ToInt32(Session["PaperID"].ToString());
Answer answer = new Answer();
answer.UID = UserManager.GetUserByuserid(Ui);
answer.PaperID = PaperManager.GetPaperById(paperId);
answer.ScoreID = score;
answer.Question = title;
answer.ANswer = str;
answer.Mark = jiandamark;
AnswerManager.AddAnswer(answer);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -