📄 testanswer.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 TestOnLine_TestAnswer : System.Web.UI.Page
{
int paperId;
Paper paper = new Paper();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
User user = (User)Session["user"];
if (user != null)
{
paperId = Convert.ToInt32(Session["PaperID"]);//获取试卷的id号
}
else
{
Response.Redirect("~/Login.aspx");//转向考试界面
}
}
catch
{
paperId = -1;
}
paper = PaperManager.GetPaperById(paperId);
this.Label2.Text = paper.PaperName.ToString();
InitData();
}
}
public void InitData()
{
Hashtable htsingle = (Hashtable)Session["htsing"];
DataSet ds1 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "单选题");
GridView1.DataSource = ds1;
GridView1.DataBind();
CheckSingle(htsingle);//检查单选题
// string str1 = htsingle[0].ToString();
((Label)GridView1.HeaderRow.FindControl("Label5")).Text = ((Label)GridView1.Rows[0].FindControl("Label31")).Text;
Hashtable htMulit = (Hashtable)Session["htMulit"];
DataSet ds2 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "多选题");
GridView2.DataSource = ds2;
GridView2.DataBind();
CheckMulit(htMulit);//检查多选题
((Label)GridView2.HeaderRow.FindControl("Label10")).Text = ((Label)GridView2.Rows[0].FindControl("Label32")).Text;
Hashtable htJudge = (Hashtable)Session["htjudge"];
DataSet ds3 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "判断题");
GridView3.DataSource = ds3;
GridView3.DataBind();
CheckJudge(htJudge);//检查判断题
((Label)GridView3.HeaderRow.FindControl("Label11")).Text = ((Label)GridView3.Rows[0].FindControl("Label33")).Text;
Hashtable htfill = (Hashtable)Session["htfill"];
DataSet ds4 = PaperDetailManager.GetAllPaperDetailByPaperId(paper.PaperId, "填空题");
GridView4.DataSource = ds4;
GridView4.DataBind();
CheckFill(htfill);//检查填空题
((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;
}
//检查单选题
public void CheckSingle(Hashtable htsing)
{
// htsing[0].ToString();
//string Qanswer= ((Label)GridView1.Rows[0].FindControl("Label4")).Text;
foreach (GridViewRow dr in GridView1.Rows)//对单选题每题进行判断用户选择答案
{
string Qanswer = ((Label)GridView1.Rows[dr.RowIndex].FindControl("Label4")).Text;
if (htsing[dr.RowIndex].ToString() != Qanswer)
{
if (htsing[dr.RowIndex].ToString() == "A")
{
((RadioButton)dr.FindControl("RadioButton1")).Checked = true;
}
else if (htsing[dr.RowIndex].ToString() == "B")
{
((RadioButton)dr.FindControl("RadioButton2")).Checked = true;
}
else if (htsing[dr.RowIndex].ToString() == "C")
{
((RadioButton)dr.FindControl("RadioButton3")).Checked = true;
}
else if (htsing[dr.RowIndex].ToString() == "D")
{
((RadioButton)dr.FindControl("RadioButton4")).Checked = true;
}
((Label)GridView1.Rows[dr.RowIndex].FindControl("Label4")).Visible = true;
}
else
{
if (htsing[dr.RowIndex].ToString() == "A")
{
((RadioButton)dr.FindControl("RadioButton1")).Checked = true;
}
else if (htsing[dr.RowIndex].ToString() == "B")
{
((RadioButton)dr.FindControl("RadioButton2")).Checked = true;
}
else if (htsing[dr.RowIndex].ToString() == "C")
{
((RadioButton)dr.FindControl("RadioButton3")).Checked = true;
}
else if (htsing[dr.RowIndex].ToString() == "D")
{
((RadioButton)dr.FindControl("RadioButton4")).Checked = true;
}
}
}
}
//检查多选题
public void CheckMulit(Hashtable htMulit)
{
//string Qanswer = ((Label)GridView2.Rows[0].FindControl("Label16")).Text;
foreach (GridViewRow dr in GridView2.Rows)//对单选题每题进行判断用户选择答案
{
string Qanswer = ((Label)GridView2.Rows[dr.RowIndex].FindControl("Label16")).Text;
if (htMulit[dr.RowIndex].ToString() != Qanswer)
{
if (htMulit[dr.RowIndex].ToString().Contains("A"))
{
((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("B"))
{
((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("B"))
{
((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
((Label)GridView2.Rows[dr.RowIndex].FindControl("Label16")).Visible = true;
}
else if (htMulit[dr.RowIndex].ToString() == Qanswer)
{
if (htMulit[dr.RowIndex].ToString().Contains("A"))
{
((CheckBox)dr.FindControl("CheckBox1")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("B"))
{
((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("B"))
{
((CheckBox)dr.FindControl("CheckBox3")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("C"))
{
((CheckBox)dr.FindControl("CheckBox2")).Checked = true;
if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
else if (htMulit[dr.RowIndex].ToString().Contains("D"))
{
((CheckBox)dr.FindControl("CheckBox4")).Checked = true;
}
}
}
}
//检查判断题
public void CheckJudge(Hashtable htJudge)
{
// string Qanswer = ((Label)GridView3.Rows[0].FindControl("Label23")).Text;
foreach (GridViewRow dr in GridView3.Rows)//对单选题每题进行判断用户选择答案
{
string Qanswer = ((Label)GridView3.Rows[dr.RowIndex].FindControl("Label23")).Text;
if (htJudge[dr.RowIndex].ToString() != Qanswer)
{
((CheckBox)dr.FindControl("CheckBox5")).Checked = (bool)htJudge[dr.RowIndex];
((Label)GridView3.Rows[dr.RowIndex].FindControl("Label23")).Visible = true;
}
else
{
((CheckBox)dr.FindControl("CheckBox5")).Checked = (bool)htJudge[dr.RowIndex];
}
}
}
//检查填空题
public void CheckFill(Hashtable htfill)
{
foreach (GridViewRow dr in GridView4.Rows)
{
string Qanswer = ((Label)GridView4.Rows[dr.RowIndex].FindControl("Label27")).Text;
if (htfill[dr.RowIndex].ToString() != Qanswer)
{
((TextBox)GridView4.Rows[dr.RowIndex].FindControl("TextBox1")).Text = htfill[dr.RowIndex].ToString();
((Label)GridView4.Rows[dr.RowIndex].FindControl("Label27")).Visible = true;
}
else
{
((TextBox)GridView4.Rows[dr.RowIndex].FindControl("TextBox1")).Text = htfill[dr.RowIndex].ToString();
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("~/Login.aspx");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -