?? seeresult.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace TestOnline
{
/// <summary>
/// seeResult 的摘要說明。
/// </summary>
public class seeResult : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label lbl_stuId;
protected System.Web.UI.WebControls.Label lbl_stuName;
protected System.Web.UI.WebControls.Label lbl_courseName;
protected System.Web.UI.WebControls.ImageButton Ibtn_back;
protected System.Web.UI.WebControls.Panel Panel2;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
if(Session["stuId"]==null)
{
Response.Redirect("login.aspx");
}else
{
if(!Page.IsPostBack)
{
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;
Hashtable ht_stuTest=(Hashtable)Session["stuTest"];
Hashtable ht_rightAnswer,ht_stuAnswer;
ht_rightAnswer=(Hashtable)Session["rightAnswer"];
ht_stuAnswer=(Hashtable)Session["stuAnswer"];
if(Session["stuAnswer"]==null||Session["rightAnswer"]==null)
Response.Write("<script>alert(\"session沒有獲取!\");</script>");
string testId="";
DataSet ds;
bool find;
for(int num=1;num<=50;num++)
{
find=false;
IDictionaryEnumerator myEnumerator = ht_stuTest.GetEnumerator();
while(myEnumerator.MoveNext()&&!find)
if(myEnumerator.Key.Equals(num.ToString()))
{
testId=myEnumerator.Value.ToString();
find=true;
ds=(new projClass()).getTestInfoAsId(testId);
DataTable dt=ds.Tables["testInfo"];
DataRow dataRow=dt.Rows[0];
Label ans=new Label();
string rigAns=getABCD(ht_rightAnswer[num.ToString()].ToString());
string stuAns=getABCD(ht_stuAnswer[num.ToString()].ToString());
ans.Text="正確答案是:<font color=red>"+rigAns+"</font>";
ans.Text+="您的答案是:"+stuAns;
if(!rigAns.Equals(stuAns))
ans.Text+="<font color=red>   這道題您做錯了!</font>";
else ans.Text+="<font color=#ff00cc>   這道題回答正確!</font>";
Literal lit_testContent=new Literal();
RadioButtonList rbtnList=new RadioButtonList();
rbtnList.ID="rbtnList"+num.ToString();
lit_testContent.Text="<br>"+num.ToString()+"、"+Server.HtmlEncode(Convert.ToString(dataRow["testContent"]))+"<br>";
rbtnList.Items.Add("A. "+Server.HtmlEncode(Convert.ToString(dataRow["testAns1"])));
rbtnList.Items.Add("B. "+Server.HtmlEncode(Convert.ToString(dataRow["testAns2"])));
rbtnList.Items.Add("C. "+Server.HtmlEncode(Convert.ToString(dataRow["testAns3"])));
rbtnList.Items.Add("D. "+Server.HtmlEncode(Convert.ToString(dataRow["testAns4"])));
//得到題目的正確答案,并添加到哈希表中
//ht_stuTest.Add(num.ToString(),testId.ToString());
int rightAns=(new projClass()).getRightAnsAsTestId(testId);
for(int j=1;j<=4;j++)
{
rbtnList.Items[j-1].Value=j.ToString();
}
if(num<=25)
{
Panel1.Controls.Add(lit_testContent);
Panel1.Controls.Add(rbtnList);
Panel1.Controls.Add(ans);
}
else
{
Panel2.Controls.Add(lit_testContent);
Panel2.Controls.Add(rbtnList);
Panel2.Controls.Add(ans);
}
}
}
}
}
}
#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Ibtn_back.Click += new System.Web.UI.ImageClickEventHandler(this.Ibtn_back_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Ibtn_back_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("userInfo.aspx");
}
public string getABCD(string ans)
{
switch(ans)
{
case "1": return "A";
case "2": return "B";
case "3": return "C";
case "4": return "D";
default: return "<font color=red>   您沒有選擇該題!</font>";
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -