📄 startexamfra.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 System.Data.SqlClient;
public partial class QianUser_StartExamfra : System.Web.UI.Page
{
Datacon dataconn = new Datacon();
static int int_row1 = 0;//单选题题号索引
static int int_row2 = 0;//多选题题号索引
static int int_row3 = 0;//判断题题号索引
static int int_row4 = 0;//填空题题号索引
static int int_row5 = 0;//简答题题号索引
static int int_row1Point = 0;//单选题分数
static int int_row2Point = 0;//多选题分数
static int int_row3Point = 0;//判断题分数
static int int_row4Point = 0;//填空题分数
static int int_row5Point = 0;//简答题分数
//============页面加载事件,从数据库中提取题目================
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.getCom(1);
this.getCom(2);
this.getCom(6);
this.getCom(8);
this.getCom(10);
}
}
//=========================提交试卷===========================
protected void btnSubmit_Click(object sender, EventArgs e)
{
this.lblStuID.Text = "学生证号:" + Session["StuName"].ToString();
this.lblSubject.Text = "考试科目:" + Session["SelLession"].ToString();
this.lblQuestion.Text = "考试套题:" + Session["SelTitle"].ToString();
this.getCom(3);
this.getCom(4);
this.getCom(7);
this.getCom(9);
this.getCom(11);
this.lblTotal.Text = "总分:" + (int_row1Point + int_row2Point + int_row3Point + int_row4Point + int_row5Point) + "分";
this.lblSel.Text = "单选题:" + int_row1Point + "分";
this.lblDSel.Text = "多选题:" + int_row2Point + "分";
this.lblPSel.Text = "判断题:" + int_row3Point + "分";
this.lblTSel.Text = "填空题:" + int_row4Point + "分";
this.lblJSel.Text = "简答题:" + int_row5Point + "分";
this.getCom(5);
Response.Write("<script lanuage=javascript>alert('您确定要交卷吗?');localtion='StartExamfra.aspx';</script>");
this.btnSubmit.Enabled = false;
}
//==================执行与数据库的关联操作=====================
protected void getCom(int i)
{
string dd1 = Application["d1"].ToString();
string dd2 = Application["d2"].ToString();
SqlConnection con = dataconn.getcon();
con.Open();
switch (i)
{
//从数据库中选择单选题
case 1:
SqlDataAdapter myadapter1 = new SqlDataAdapter("select * "
+"from tb_Questions where que_type='单选题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds1 = new DataSet();
myadapter1.Fill(myds1);
DataList1.DataSource = myds1;
DataList1.DataBind();
//生成单选题题号
for (int tID1 = 1; tID1 <= DataList1.Items.Count; tID1++)
{
Label lblSelect = (Label)DataList1.Items[tID1 - 1].FindControl("Label2");
lblSelect.Text = tID1.ToString() + "、";
}
break;
//从数据库中选择多选题
case 2:
SqlDataAdapter myadapter2 = new SqlDataAdapter("select * "
+"from tb_Questions where que_type='多选题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds2 = new DataSet();
myadapter2.Fill(myds2);
DataList2.DataSource = myds2;
DataList2.DataBind();
//生成多选题题号
for (int tID2 = 1; tID2 <= DataList2.Items.Count; tID2++)
{
Label lblDSelect = (Label)DataList2.Items[tID2 - 1].FindControl("Label24");
lblDSelect.Text = tID2.ToString() + "、";
}
break;
//从数据库中选择判断题
case 6:
SqlDataAdapter myadapter6 = new SqlDataAdapter("select * "
+ "from tb_Panduan where que_type='判断题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds6 = new DataSet();
myadapter6.Fill(myds6);
DataList6.DataSource = myds6;
DataList6.DataBind();
//生成判断题题号
for (int tID6 = 1; tID6 <= DataList6.Items.Count; tID6++)
{
Label lblDSelect = (Label)DataList6.Items[tID6 - 1].FindControl("Label25");
lblDSelect.Text = tID6.ToString() + "、";
}
break;
//从数据库中选择填空题
case 8:
SqlDataAdapter myadapter8 = new SqlDataAdapter("select * "
+ "from tb_Tiankong where que_type='填空题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds8 = new DataSet();
myadapter8.Fill(myds8);
DataList8.DataSource = myds8;
DataList8.DataBind();
//生成填空题题号
for (int tID8 = 1; tID8 <= DataList8.Items.Count; tID8++)
{
Label lblDSelect = (Label)DataList8.Items[tID8 - 1].FindControl("Label33");
lblDSelect.Text = tID8.ToString() + "、";
}
break;
//从数据库中选择简答题
case 10:
SqlDataAdapter myadapter10 = new SqlDataAdapter("select * "
+ "from tb_Jianda where que_type='简答题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds10 = new DataSet();
myadapter10.Fill(myds10);
DataList10.DataSource = myds10;
DataList10.DataBind();
//生成简答题题号
for (int tID10 = 1; tID10 <= DataList10.Items.Count; tID10++)
{
Label lblDSelect = (Label)DataList10.Items[tID10 - 1].FindControl("Label39");
lblDSelect.Text = tID10.ToString() + "、";
}
break;
//核对单选题答案
case 3:
SqlDataAdapter myadapter3 = new SqlDataAdapter("select id,que_answer"
+ " from tb_Questions where que_type='单选题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds3 = new DataSet();
myadapter3.Fill(myds3);
DataRow[] row1 = myds3.Tables[0].Select();
//计算单选题成绩
foreach (DataRow answer1 in row1)
{
int_row1 += 1;
RadioButtonList rbl = (RadioButtonList)(DataList1.Items[int_row1 - 1].FindControl("RadioButtonList1"));
if (rbl.SelectedValue == "")
{
this.lblSel.Text = "单选题:0分";
}
else
{
if (answer1["que_answer"].ToString().Trim() == rbl.SelectedValue.ToString().Trim())
{
int_row1Point += 20 / DataList1.Items.Count;
this.lblSel.Text = "单选题:" + int_row1Point.ToString() + "分";
}
}
}
break;
//核对多选题答案
case 4:
SqlDataAdapter myadapter4 = new SqlDataAdapter("select id,que_answer"
+ " from tb_Questions where que_type='多选题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds4 = new DataSet();
myadapter4.Fill(myds4);
DataRow[] row2 = myds4.Tables[0].Select();
//计算多选题成绩
foreach (DataRow answer2 in row2)
{
int_row2 += 1;
CheckBoxList cbl = (CheckBoxList)(DataList2.Items[int_row2 - 1].FindControl("CheckBoxList1"));
if (cbl.SelectedValue == "")
{
lblDSel.Text = "多选题:0分";
}
else
{
for (int q = 0; q < cbl.Items.Count; q++)
{
if (cbl.Items[q].Selected == true)
{
this.TextBox1.Text = TextBox1.Text.Trim() + cbl.Items[q].Value + ", ";
}
}
if (answer2["que_answer"].ToString().Trim() + "," == this.TextBox1.Text.Trim())
{
int_row2Point += 30 / DataList2.Items.Count;
this.lblDSel.Text = "多选题:" + int_row2Point.ToString() + "分";
}
}
}
break;
//核对判断题答案
case 7:
SqlDataAdapter myadapter7 = new SqlDataAdapter("select id,que_answer"
+ " from tb_Panduan where que_type='判断题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds7 = new DataSet();
myadapter7.Fill(myds7);
DataRow[] row3 = myds7.Tables[0].Select();
//计算判断题成绩
foreach (DataRow answer3 in row3)
{
int_row3 += 1;
RadioButtonList rb2 = (RadioButtonList)(DataList6.Items[int_row3 - 1].FindControl("RadioButtonList2"));
if (rb2.SelectedValue == "")
{
this.lblPSel.Text = "判断题:0分";
}
else
{
if (answer3["que_answer"].ToString().Trim() == rb2.SelectedValue.ToString().Trim())
{
int_row3Point += 10 / DataList6.Items.Count;
this.lblPSel.Text = "判断题:" + int_row3Point.ToString() + "分";
}
}
}
break;
//核对填空题答案
case 9:
SqlDataAdapter myadapter9 = new SqlDataAdapter("select id,que_answer"
+ " from tb_Tiankong where que_type='填空题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds9 = new DataSet();
myadapter9.Fill(myds9);
DataRow[] row4 = myds9.Tables[0].Select();
//计算填空题成绩
foreach (DataRow answer4 in row4)
{
int_row4 += 1;
TextBox t1 = (TextBox)(DataList8.Items[int_row4 - 1].FindControl("TextBox1"));
if (t1.Text == "")
{
this.lblTSel.Text = "填空题:0分";
}
else
{
if (answer4["que_answer"].ToString().Trim() == t1.Text.ToString().Trim())
{
int_row4Point += 20 / DataList8.Items.Count;
this.lblTSel.Text = "填空题:" + int_row4Point.ToString() + "分";
}
}
}
break;
//核对简答题答案
case 11:
SqlDataAdapter myadapter11 = new SqlDataAdapter("select id,que_answer"
+ " from tb_Jianda where que_type='简答题'and que_lessonid='"
+ dd1 + "'and que_taotiid='" + dd2 + "'order by id desc", con);
DataSet myds11 = new DataSet();
myadapter11.Fill(myds11);
DataRow[] row5 = myds11.Tables[0].Select();
//计算简答题成绩
foreach (DataRow answer5 in row5)
{
int_row5 += 1;
TextBox t2 = (TextBox)(DataList10.Items[int_row5 - 1].FindControl("TextBox2"));
if (t2.Text == "")
{
this.lblJSel.Text = "简答题:0分";
}
else
{
if (answer5["que_answer"].ToString().Trim() == t2.Text.ToString().Trim())
{
int_row5Point += 20 / DataList10.Items.Count;
this.lblJSel.Text = "简答题:" + int_row5Point.ToString() + "分";
}
}
}
break;
//把考试结果插入数据库
case 5:
{
dataconn.eccom("insert into tb_StuResult(stu_id,which_lesson,taotiid,taotiname,res_single,res_more,res_panduan,res_tiankong,res_jianda,res_total) values('" + lblStuID.Text + "','" + lblSubject.Text + "','" + dd2 + "','" + lblQuestion.Text + "','" + int_row1Point + "','" + int_row2Point + "','" + int_row3Point + "','" + int_row4Point + "','" + int_row5Point + "','" + lblTotal.Text + "')");
}
break;
}
con.Close();
}
//========================退出当前系统========================
protected void btnExit_Click(object sender, EventArgs e)
{
Response.Write("<script lanuage=javascript>window.close();location='javascript:history.go(-1)'</script>");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -