📄 imitationcreatetest.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;
public partial class imitationCreateTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["stuId"] == null)
{
Response.Redirect("Default.aspx");
}
else
{
string courseId = Convert.ToString(Session["courseId"]);
string stuId = Convert.ToString(Session["stuId"]);
string stuName = (new projClass()).getUserName(stuId);
string courseName = (new projClass()).getCourseNameAsCourseId(courseId);
lbl_stuId.Text = stuId;
lbl_stuName.Text = stuName;
lbl_courseName.Text = courseName;
if (!Page.IsPostBack)
{
DataBind1();
}
}
}
private void DataBind1()
{
DataSet ds1 = (new projClass()).getTestDanXuanImitation(Session["courseId"].ToString());
GridView1.DataSource = ds1;
GridView1.DataBind();
((Label)GridView1.HeaderRow.FindControl("Label5")).Text = ((Label)GridView1.Rows[0].FindControl("Label31")).Text;
DataSet ds2 = (new projClass()).getTestDuoXuanImitation(Session["courseId"].ToString());
GridView2.DataSource = ds2;
GridView2.DataBind();
((Label)GridView2.HeaderRow.FindControl("Label10")).Text = ((Label)GridView2.Rows[0].FindControl("Label32")).Text;
DataSet ds3 = (new projClass()).getTestIfImitation(Session["courseId"].ToString());
GridView3.DataSource = ds3;
GridView3.DataBind();
((Label)GridView3.HeaderRow.FindControl("Label11")).Text = ((Label)GridView3.Rows[0].FindControl("Label33")).Text;
DataSet ds4 = (new projClass()).getTianKongImitation(Session["courseId"].ToString());
GridView4.DataSource = ds4;
GridView4.DataBind();
((Label)GridView4.HeaderRow.FindControl("Label12")).Text = ((Label)GridView4.Rows[0].FindControl("Label34")).Text;
DataSet ds5 = (new projClass()).imitationGetWenDa(Session["courseId"].ToString());
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)
{
Hashtable htsing = new Hashtable();
Hashtable htMulit = new Hashtable();
Hashtable htjudge = new Hashtable();
Hashtable htfill = new Hashtable();
Hashtable htquestions = 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 = "1";
}
else if (((RadioButton)dr.FindControl("RadioButton2")).Checked)
{
str = "2";
}
else if (((RadioButton)dr.FindControl("RadioButton3")).Checked)
{
str = "3";
}
else if (((RadioButton)dr.FindControl("RadioButton4")).Checked)
{
str = "4";
}
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 += "1";
}
if (((CheckBox)dr.FindControl("CheckBox3")).Checked)
{
str += "2";
}
if (((CheckBox)dr.FindControl("CheckBox2")).Checked)
{
str += "3";
}
if (((CheckBox)dr.FindControl("CheckBox4")).Checked)
{
str += "4";
}
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)//对判断题每题进行判断用户选择答案
{
string j = "";
if (((CheckBox)dr.FindControl("CheckBox5")).Checked)
{
j = "对";
}
if (j == ((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;//保存填空题
////////////////////////////////////////////////////////////////////////////////////////////
int questionsmark = int.Parse(((Label)GridView5.Rows[0].FindControl("Label35")).Text);//取出问答题每题分值
foreach (GridViewRow dr in GridView5.Rows)
{
string str = "";
str = ((TextBox)dr.FindControl("TextBox2")).Text.Trim();
string key=((Label)dr.FindControl("Label26")).Text.Trim();
int marks = Marks(str, key, questionsmark);
score1 = score1 + marks;
size = size + 1;
htquestions.Add(dr.RowIndex, str);
}
///////////////////////////////
Session["htquestions"]=htquestions;//保存问答题
///////////////////////////////
///////////////////////统计分数
//////////////////////////////////////////////////////////////////////////////////////////
double allQuestion = GridView1.Rows.Count + GridView2.Rows.Count + GridView3.Rows.Count + GridView4.Rows.Count+GridView5.Rows.Count;
double rate = (size / allQuestion) * 100;
Session["Mark"] = score1.ToString();
string userid = Convert.ToString(Session["stuId"]);
// Response.Redirect("resultImitation.aspx");
Page.RegisterStartupScript("555", "<script>windowopen();window.opener=null;window.close()</script>");
}
/// <summary>
/// 下面两个方法是用来解决问答题得分,这里是根据关键字和否定词来判断的,
/// 我个人觉得不严密,不过机器判断得分我也只想出这个思路来解决,你要是有什么好的建议也可提出。
/// 我的算法水平不高,只能写这简单的,望大家多多指教。
/// </summary>
static int Marks(string str, string key, int score)
{
string fou = "not,不是,不,错,错误,不好,否,坏,不会,不对";
string[] str1 = key.Split(',');
string[] str2 = fou.Split(',');
string[,] str3 = new string[str2.Length, str1.Length];
string[] str4 = new string[str2.Length * str1.Length];
int count = 0, count1 = 0;
for (int i = 0; i < str1.Length; i++)
{
count += PanDuan(str, str1[i]);
}
try
{
for (int i = 0; i < str2.Length; i++)
{
for (int j = 0; j < str1.Length; j++)
{
str3[i, j] = str2[i] + str1[j];
}
}
}
catch (Exception e)
{
//Console.WriteLine(e.Message);
throw new Exception(e.Message);
}
for (int i = 0; i < str2.Length; i++)
{
for (int j = 0; j < str1.Length; j++)
{
str4[i * str1.Length + j] = str3[i, j];
}
}
for (int i = 0; i < str4.Length; i++)
{
count1 += PanDuan(str, str4[i]);
//Console.WriteLine(str4[i]);
}
return (count - count1) * (score / str1.Length);
}
static int PanDuan(string str, string str1)
{
int count = 0;
if (str.Contains(str1))
{
count++;
}
return count;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -