请帮助我,我找到了一个测验C#Asp.Net项目,但无法添加正确的答案列 [英] Please Help Me I Have Found A Quiz C# Asp.Net Project But Unable To Add Correct Answer Column
问题描述
命名空间测验
{
使用System;
使用System.Data;
使用System.Drawing ;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用System.Web.UI.HtmlControls;
使用System.IO;
使用System.Xml;
使用System。 Xml.XPath;
使用System.Text;
使用System.Collections;
///< summary>
///在线测验
///作者:Ameen Abudbush
/// http://ameen.rr.nu
/// ameen@scientist.com
///在线更新此项目:
/// http://ameen.rr.nu/projects。 htm
///您的问题建议欢迎
///
公共抽象类wucQuiz:System .Web.UI.UserControl
{
protected System.Web.UI.WebControls.Panel quizPanal;
protected System.Web.UI。 WebControls.Panel revisionPanal;
protected System.Web.UI.WebControls.Panel resultPanal;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System。 Web.UI.WebControls.Label qNoLbl;
protected System.Web.UI.WebControls.Label spentTimeLbl;
protected System.Web.UI.WebControls.Label questionLbl;
protected System.Web.UI.WebControls.RadioButtonList answersRBL;
protected HWebProgressBar.WebCustomControl1 progressBar;
protected System.Web.UI.WebControls。 RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.CheckBox bookmarkCKBX;
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.LinkButton markBtn;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls。标签dateLbl;
protected System.Web.UI.WebControls.Label totalQNoREsLbl;
protected System.Web.UI.WebControls.Label totalScoreLbl;
protected System.Web.UI.WebControls.Label scoreLbl;
protected System.Web.UI.WebControls.Label correctAnswersLbl;
protected System.Web.UI.WebControls.Label passingScoreLbl;
protected System.Web.UI.WebControls.Label gradeLbl;
protected System.Web.UI.WebControls.Label timeTakenLbl;
protected System.Web.UI.WebControls.Image headerImage;
protected System.Web.UI.WebControls.LinkButton resultBtn;
XmlDocument doc = new XmlDocument();
XPathNavigator nav;
XPathNodeIterator nodeItrator;
// hold user Answers
ArrayList historyALst = new ArrayList();
// hold Correct Answers
ArrayList correctAnswer = new ArrayList();
// hold bookmarked问题
ArrayList bookmarkLst = new ArrayList();
//曾经用A替换索引1,用B替换2 ....等等
char [] perfix = new char [10] {'A','B','C','D',' F','G','H','J','K','L'};
int currentQNo;
int totalQNumber;
int totalMarkedQuestion;
int currentMarkedQuestion;
int markLoop;
DateTime startTime;
TimeSpan花费时间;
bool isReview;
bool wasChecked = false;
private void Page_Load(object sender,System.EventArgs e)
{
doc.Load(Server.MapPath(quiz.xml)) );
nav = doc.CreateNavigator();
//通过添加新的javascript属性来改变用户
markBtn.Attributes.Add( onclick,评论());
//是新测验吗?
if(!IsPostBack)
{
//是的。
quizPanal.Visible = true; //显示测验屏幕。
revisionPana l.Visible = false; //隐藏评论报告屏幕。
resultPanal.Visible = false; //隐藏分数报告屏幕。
startTime = DateTime.Now;
currentQNo = 1;
totalQNumber = nav.Select(// mc)。Count;
// totalQNumber = doc.SelectNodes(// mc)。Count; // onther way
ViewState [startTime] = startTime;
ViewState [totalQNumber] = totalQNumber;
ViewState [currentQNo ] = currentQNo;
ViewState [得分] = 0;
ShowQuestion(currentQNo);
}
}
///< summary>
///从
/// XML文件中回答问题及其选择并将其渲染到屏幕
///
///< param name =_ qNo/>问题编号
public void ShowQuestion(int _qNo)
{
quizPanal.Visible = true;
revisionPanal.Visible = false;
resultPanal.Visible = false;
answersRBL.Items.Clear( );
isReview = Convert.ToBoolean(ViewState [isReview]);
if(isReview){bookmarkCKBX.Enabled = false; Image1.Visible = true; qNoLbl .ForeColor = Color.Red; RequiredFieldValidator1.Text =回答问题!;}}
startTime =(DateTime)ViewState [startTime];
totalQNumber = Convert.ToInt32(ViewState [totalQNumber]);
spentTime = DateTime.Now.Subtract( startTime);
string xPath =quiz / mc [+ _ qNo.ToString()+];
int counter = 1;
string str;
nodeItrator = nav.Select(xPath +/ question);
nodeItrator.MoveNext();
qNoLbl.Text =Q:+ _qNo.ToString()+/+ totalQNumber.ToString();
questionLbl.Text = _qNo.ToString()+:+ nodeItrator.Current.Value;
// questionLbl.Text = doc.SelectSingleNode(qXPath).InnerText; // onther way
spentTimeLbl.Text = spentTime.Minutes.ToString()+〜+ spentTime.Seconds.ToString();
nodeItrator = nav.Select(xPath +/ answer);
while(nodeItrator.MoveNext())
{
str = counter.ToString();
answersRBL.Items.Add(new ListItem(+ perfix [counter-1] .ToString()+:+ nodeItrator.Current.Value,str));
if(nodeItrator.Current.GetAttribute(correct, )==是)
{
ViewState [correctAnswer] =柜台;
}
counter ++;
}
currentQNo ++;
ViewState [ currentQNo] = currentQNo;
}
/// < summary>
///生成评论报告
///来自historyALst ArrayList的回复用户答案
///来自bookmarkLst ArrayList的书签问题
///并做用户descion
///
public void Review( )
{
quizPanal.Visible = false;
revisionPanal.Visible = true;
resultPanal.Visible = false;
headerImage.ImageUrl =quizImages / hedRev.jpg;
int seqance = 0;
string _is =No;
bookmarkLst =(ArrayList)ViewState [bookmarkLst];
historyALst =(ArrayList)ViewState [historyALst];
wasChecked = Convert.ToBoolean(ViewState [wasChecked]);
if(!wasChecked)
{
markBtn.Enabled = false;
}
totalQNumber = Convert.ToInt32(ViewState [totalQNumber]);
//表格表格
TableCell c = new TableCell();
TableCell cc = new TableCell();
TableCell ccc =新的TableCell();
c.Text =问题编号;
cc.Text =你的回答;
ccc.Text =Bookmark?;
TableRow hr = new TableRow();
hr.Cells.Add(c);
hr.Cells.Add(cc);
hr.Cells.Add(ccc);
hr.ForeColor = Color.White;
hr.BackColor = Color.LightSlateGray;
Table1.Rows.Add(hr);
Table1.Font.Bold = true;
for(int i = 1; i< = totalQNumber; i ++)
{
//否
TableCell c1 = new TableCell();
c1.Text = i.ToString();
//回答
TableCell c2 = new TableCell();
c2.HorizontalAlign = HorizontalAlign.Center;
c2.Text = perfix [Convert.ToInt32 (historyALst [i-1]) - 1] .ToString();
//供审核
TableCell c3 = new TableCell();
for(int n = 0; n< bookmarklst.count; n ++)>
{
if(Convert.ToInt32(bookmarkLst [n] .ToString())== i)
{
_is =是;
}
}
c3.Text = _is;
c3.HorizontalAlign = HorizontalAlign.Center;
_is =否;
//是正确答案
TableRow r = new TableRow();
r。 Cells.Add(c1);
r.Cells.Add(c2);
r.Cells.Add(c3);
r.ForeColor = Color.SlateGray;
if(seqance%2!= 0)
{
r .BackColor = Color.Gainsboro;
}
Table1.Rows.Add(r);
seqance ++;
}
}
///< summary>
/// generate分数报告
///通过一些计算
///
public void ShowResult()
{
quizPanal.Visible = false;
revisionPanal.Visible = false;
resultPanal.Visible = true;
headerImage.ImageUrl =quizImages / hedRep.jpg;
int score = Convert.ToInt32(ViewState [score]);
totalQNumber = Convert.ToInt32(ViewState [totalQNumber]);
startTime =(DateTime)ViewState [startTime];
spentTime = DateTime.Now.Subtract( startTime);
progressBar.Value =得分* 100;
progressBar.Total = totalQNumber * 100;
dateLbl.Text = DateTime.Now.ToUniversalTime()。ToShortDateString();
totalQNoREsLbl.Text = totalQNumber.ToString();
totalScoreLbl.Text =(totalQNumber * 100).ToString();
scoreLbl.Text =(得分* 100).ToString();
correctAnswersLbl.Text =得分.ToString();
传球分数.Lbl.Text =(totalQNumber * 100/2).ToString();
timeTakenLbl.Text = spentTime.Hours.ToString()+ :+ spentTime.Minutes.ToString()+:+ spentTime.Seconds.ToString()+ Hr(s)。;
if((得分* 100 / totalQNumber)< 50)
{
gradeLbl.ForeColor = Color.Red;
gradeLbl.Text =失败;
}
其他
{
gradeLbl.ForeColor = Color.Green;
gradeLbl.Text =成功;
}
}
#region Web Form Designer生成的代码
覆盖protected void OnInit(EventArgs e)
{
//
// CODEGEN:ASP.NET Web窗体设计器需要此调用。
//
InitializeComponent();
base.OnInit(e);
}
// /支持Designer的必需方法 - 不要使用代码编辑器修改
///此方法的内容。
///
private void InitializeComponent()
{
this.ImageButton1.Click + = new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.markBtn.Click + = new System.EventHandler(this.markBtn_Click);
this.resultBtn.Click + = new System.EventHandler(this.resultBtn_Click);
this.Load + = new System.EventHandler(this.Page_Load);
}
#endregion
}
}
< blockquote>然后问你在哪里找到它:不在这里。
他们w不知道他们的软件,我们不知道,而且我不愿意通过代码转储来为你做功课!
namespace Quiz
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Text;
using System.Collections;
/// <summary>
/// online Quiz
/// By: Ameen Abudbush
/// http://ameen.rr.nu
/// ameen@scientist.com
/// the update of this project online:
/// http://ameen.rr.nu/projects.htm
/// your Questions Suggestion are welcomed
///
public abstract class wucQuiz : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Panel quizPanal;
protected System.Web.UI.WebControls.Panel revisionPanal;
protected System.Web.UI.WebControls.Panel resultPanal;
protected System.Web.UI.WebControls.ImageButton ImageButton1;
protected System.Web.UI.WebControls.Label qNoLbl;
protected System.Web.UI.WebControls.Label spentTimeLbl;
protected System.Web.UI.WebControls.Label questionLbl;
protected System.Web.UI.WebControls.RadioButtonList answersRBL;
protected HWebProgressBar.WebCustomControl1 progressBar;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.CheckBox bookmarkCKBX;
protected System.Web.UI.WebControls.Table Table1;
protected System.Web.UI.WebControls.LinkButton markBtn;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.Label dateLbl;
protected System.Web.UI.WebControls.Label totalQNoREsLbl;
protected System.Web.UI.WebControls.Label totalScoreLbl;
protected System.Web.UI.WebControls.Label scoreLbl;
protected System.Web.UI.WebControls.Label correctAnswersLbl;
protected System.Web.UI.WebControls.Label passingScoreLbl;
protected System.Web.UI.WebControls.Label gradeLbl;
protected System.Web.UI.WebControls.Label timeTakenLbl;
protected System.Web.UI.WebControls.Image headerImage;
protected System.Web.UI.WebControls.LinkButton resultBtn;
XmlDocument doc=new XmlDocument();
XPathNavigator nav;
XPathNodeIterator nodeItrator;
//hold user Answers
ArrayList historyALst=new ArrayList();
//hold Correct Answers
ArrayList correctAnswer = new ArrayList();
//hold bookmarked Question(s)
ArrayList bookmarkLst=new ArrayList();
//used to replace index 1 by A and 2 by B ....etc
char[] perfix=new char[10] {'A','B','C','D','F','G','H','J','K','L'};
int currentQNo;
int totalQNumber;
int totalMarkedQuestion;
int currentMarkedQuestion;
int markLoop;
DateTime startTime;
TimeSpan spentTime;
bool isReview;
bool wasChecked=false;
private void Page_Load(object sender, System.EventArgs e)
{
doc.Load(Server.MapPath("quiz.xml"));
nav=doc.CreateNavigator();
//alter user by adding new javascript Attribute
markBtn.Attributes.Add("onclick","Review()");
//Is New Quiz?.
if(!IsPostBack)
{
//Yes.
quizPanal.Visible=true;// show quiz screen.
revisionPanal.Visible=false;//hide review report screen.
resultPanal.Visible=false; // hide score report screen.
startTime=DateTime.Now;
currentQNo=1;
totalQNumber=nav.Select("//mc").Count;
// totalQNumber=doc.SelectNodes("//mc").Count; // onther way
ViewState["startTime"]=startTime;
ViewState["totalQNumber"]=totalQNumber;
ViewState["currentQNo"]=currentQNo;
ViewState["score"]=0;
ShowQuestion(currentQNo);
}
}
/// <summary>
/// Retrive Question and its Choice from
/// XML file and render it to screen
///
/// <param name="_qNo" />Question Number
public void ShowQuestion(int _qNo)
{
quizPanal.Visible=true;
revisionPanal.Visible=false;
resultPanal.Visible=false;
answersRBL.Items.Clear();
isReview=Convert.ToBoolean(ViewState["isReview"]);
if(isReview){bookmarkCKBX.Enabled=false;Image1.Visible=true;qNoLbl.ForeColor=Color.Red;RequiredFieldValidator1.Text="Answer The Question !";}
startTime=(DateTime)ViewState["startTime"];
totalQNumber=Convert.ToInt32(ViewState["totalQNumber"]);
spentTime=DateTime.Now.Subtract(startTime);
string xPath="quiz/mc["+_qNo.ToString()+"]";
int counter=1;
string str;
nodeItrator=nav.Select(xPath+"/question");
nodeItrator.MoveNext();
qNoLbl.Text="Q: "+_qNo.ToString()+" / "+totalQNumber.ToString();
questionLbl.Text=_qNo.ToString()+": "+nodeItrator.Current.Value;
// questionLbl.Text=doc.SelectSingleNode(qXPath).InnerText; // onther way
spentTimeLbl.Text=spentTime.Minutes.ToString()+" ~ "+spentTime.Seconds.ToString();
nodeItrator=nav.Select(xPath+"/answer");
while(nodeItrator.MoveNext())
{
str=counter.ToString();
answersRBL.Items.Add(new ListItem(" "+perfix[counter-1].ToString()+": "+nodeItrator.Current.Value,str));
if(nodeItrator.Current.GetAttribute("correct","")=="Yes")
{
ViewState["correctAnswer"]=counter;
}
counter++;
}
currentQNo++;
ViewState["currentQNo"]=currentQNo;
}
/// <summary>
/// generate Review Report
/// by retrive user answers from historyALst ArrayList
/// and Bookmarked Question(s) from bookmarkLst ArrayList
/// and do user descion
///
public void Review()
{
quizPanal.Visible=false;
revisionPanal.Visible=true;
resultPanal.Visible=false;
headerImage.ImageUrl="quizImages/hedRev.jpg";
int seqance=0;
string _is=" No ";
bookmarkLst=(ArrayList)ViewState["bookmarkLst"];
historyALst=(ArrayList)ViewState["historyALst"];
wasChecked=Convert.ToBoolean(ViewState["wasChecked"]);
if(!wasChecked)
{
markBtn.Enabled=false;
}
totalQNumber=Convert.ToInt32(ViewState["totalQNumber"]);
//table header
TableCell c=new TableCell();
TableCell cc=new TableCell();
TableCell ccc=new TableCell();
c.Text="Question No.";
cc.Text="Your Answer";
ccc.Text="Bookmark ?";
TableRow hr=new TableRow();
hr.Cells.Add(c);
hr.Cells.Add(cc);
hr.Cells.Add(ccc);
hr.ForeColor=Color.White;
hr.BackColor=Color.LightSlateGray;
Table1.Rows.Add(hr);
Table1.Font.Bold=true;
for(int i=1;i<=totalQNumber;i++)
{
//no
TableCell c1=new TableCell();
c1.Text=i.ToString();
//answer
TableCell c2=new TableCell();
c2.HorizontalAlign=HorizontalAlign.Center;
c2.Text=perfix[Convert.ToInt32(historyALst[i-1])-1].ToString();
//is for review
TableCell c3=new TableCell();
for(int n=0;n<bookmarklst.count;n++)>
{
if(Convert.ToInt32(bookmarkLst[n].ToString())==i)
{
_is=" Yes ";
}
}
c3.Text=_is;
c3.HorizontalAlign=HorizontalAlign.Center;
_is=" No ";
//is for correct Answer
TableRow r=new TableRow();
r.Cells.Add(c1);
r.Cells.Add(c2);
r.Cells.Add(c3);
r.ForeColor=Color.SlateGray;
if(seqance % 2 != 0)
{
r.BackColor=Color.Gainsboro;
}
Table1.Rows.Add(r);
seqance++;
}
}
/// <summary>
/// generate Score Report
/// by some calculations
///
public void ShowResult()
{
quizPanal.Visible=false;
revisionPanal.Visible=false;
resultPanal.Visible=true;
headerImage.ImageUrl="quizImages/hedRep.jpg";
int score=Convert.ToInt32(ViewState["score"]);
totalQNumber=Convert.ToInt32(ViewState["totalQNumber"]);
startTime=(DateTime)ViewState["startTime"];
spentTime=DateTime.Now.Subtract(startTime);
progressBar.Value=score*100;
progressBar.Total=totalQNumber*100;
dateLbl.Text=DateTime.Now.ToUniversalTime().ToShortDateString();
totalQNoREsLbl.Text=totalQNumber.ToString();
totalScoreLbl.Text=(totalQNumber*100).ToString();
scoreLbl.Text=(score*100).ToString();
correctAnswersLbl.Text=score.ToString();
passingScoreLbl.Text=(totalQNumber*100/2).ToString();
timeTakenLbl.Text=spentTime.Hours.ToString()+":"+spentTime.Minutes.ToString()+":"+spentTime.Seconds.ToString()+"Hr(s).";
if((score*100/totalQNumber)<50)
{
gradeLbl.ForeColor=Color.Red;
gradeLbl.Text="Failed";
}
else
{
gradeLbl.ForeColor=Color.Green;
gradeLbl.Text="Success";
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.ImageButton1.Click += new System.Web.UI.ImageClickEventHandler(this.ImageButton1_Click);
this.markBtn.Click += new System.EventHandler(this.markBtn_Click);
this.resultBtn.Click += new System.EventHandler(this.resultBtn_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
Then ask where you found it: not here.
They will know their software, we don't, and I for one do not feel inclined to wade through that code dump to do your homework for you!
这篇关于请帮助我,我找到了一个测验C#Asp.Net项目,但无法添加正确的答案列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!