?? usertest.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 MyOnLineExam.DataAccessLayer;
using System.Data.SqlClient;
using MyOnLineExam.BusinessLogicLayer;
public partial class Web_UserTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lblPaperName.Text = Session["PaperName"].ToString();
InitData();
}
}
//初始化試卷,從數據庫中將試題取出
protected void InitData()
{
SqlParameter[] Params1 = new SqlParameter[2];
DataBase DB = new DataBase();
int paperID = int.Parse(Session["PaperID"].ToString());
Params1[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID); //試卷編號
Params1[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "單選題"); //題目類型
DataSet ds1 = DB.GetDataSet("Proc_PaperDetail",Params1);
GridView1.DataSource = ds1;
GridView1.DataBind();
((Label)GridView1.HeaderRow.FindControl("Label27")).Text = ((Label)GridView1.Rows[0].FindControl("Label4")).Text;
SqlParameter[] Params2 = new SqlParameter[2];
Params2[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID); //試卷編號
Params2[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "多選題"); //題目類型
DataSet ds2 = DB.GetDataSet("Proc_PaperDetail", Params2);
GridView2.DataSource = ds2;
GridView2.DataBind();
((Label)GridView2.HeaderRow.FindControl("Label28")).Text = ((Label)GridView2.Rows[0].FindControl("Label8")).Text;
SqlParameter[] Params3 = new SqlParameter[2];
Params3[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID); //試卷編號
Params3[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "判斷題"); //題目類型
DataSet ds3 = DB.GetDataSet("Proc_PaperDetail", Params3);
GridView3.DataSource = ds3;
GridView3.DataBind();
((Label)GridView3.HeaderRow.FindControl("Label29")).Text = ((Label)GridView3.Rows[0].FindControl("Label12")).Text;
SqlParameter[] Params4 = new SqlParameter[2];
Params4[0] = DB.MakeInParam("@PaperID", SqlDbType.Int, 4, paperID); //試卷編號
Params4[1] = DB.MakeInParam("@Type", SqlDbType.VarChar, 10, "填空題"); //題目類型
DataSet ds4 = DB.GetDataSet("Proc_PaperDetail", Params4);
GridView4.DataSource = ds4;
GridView4.DataBind();
((Label)GridView4.HeaderRow.FindControl("Label30")).Text = ((Label)GridView4.Rows[0].FindControl("Label17")).Text;
}
//提交試卷,生成成績
protected void imgBtnSubmit_Click(object sender, ImageClickEventArgs e)
{
int score = 0;
int singlemark = int.Parse(((Label)GridView1.Rows[0].FindControl("Label4")).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("Label3")).Text.Trim() == str)//將用戶選擇結果和答案進行比較
{
score = score + singlemark;
}
}
int multimark = int.Parse(((Label)GridView2.Rows[0].FindControl("Label8")).Text);//取出多選題每題分值
foreach (GridViewRow dr in GridView2.Rows)//對多選題每題進行判斷用戶選擇答案
{
string str = "";
if (((CheckBox)dr.FindControl("CheckBox1")).Checked)
{
str += "A";
}
if (((CheckBox)dr.FindControl("CheckBox2")).Checked)
{
str += "B";
}
if (((CheckBox)dr.FindControl("CheckBox3")).Checked)
{
str += "C";
}
if (((CheckBox)dr.FindControl("CheckBox4")).Checked)
{
str += "D";
}
if (((Label)dr.FindControl("Label7")).Text.Trim() == str)//將用戶選擇結果和答案進行比較
{
score = score + multimark;
}
}
int judgemark = int.Parse(((Label)GridView3.Rows[0].FindControl("Label12")).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("Label11")).Text.Trim()))
{
score = score + judgemark;
}
}
int fillmark = int.Parse(((Label)GridView4.Rows[0].FindControl("Label17")).Text);//取出填空題每題分值
foreach (GridViewRow dr in GridView4.Rows)
{
string str = "";
str = ((TextBox)dr.FindControl("TextBox1")).Text.Trim();
if (str == ((Label)dr.FindControl("Label16")).Text.Trim())
{
score = score + fillmark;
}
}
Scores insertScore = new Scores(); //創建Scores類對象
insertScore.UserID = Session["userID"].ToString();//設置Scores對象的屬性
insertScore.PaperID=int.Parse(Session["PaperID"].ToString());
insertScore.Score = score;
if (insertScore.InsertByProc())//調用InsertByProc方法向數據庫中插入成績
{
if (score >= 80)//根據成績給出相應提示
{
Response.Write("<script language=javascript>alert('您太棒了!您的成績為:"+score+"分!')</script>");
}
else if (score >= 60)
{
Response.Write("<script language=javascript>alert('合格!您的成績為:"+score+"分!')</script>");
}
else
{
Response.Write("<script language=javascript>alert('需要努力了!您的成績為:"+score+"分!')</script>");
}
Panel1.Visible = true;
}
}
protected void imgBtnAnswer_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("TestAnswer.aspx");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -