⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx

📁 四六级答案在线对答比较,能自行对比答案的正确与错误,做的比较简单
💻 ASPX
字号:
<%@ Import Namespace="System.Xml" %>

<script language="VB" runat="server">

'Relative file path to XML data
Dim strXmlFilePath as String = Server.MapPath("quiz.xml")

Dim xDoc as XmlDocument = New XmlDocument()
Dim intTotalQuestion as Integer
Dim intQuestionNo as Integer = 1
Dim intScore as Integer = 0
Dim arrAnswerHistory as new ArrayList()

Sub Page_Load(src as Object, e as EventArgs)

	'Load xml data
	xDoc.Load(strXmlFilePath)

	'Start a new quiz?
	If Not Page.IsPostBack Then

		'Yes! Count total question
		intTotalQuestion = xDoc.SelectNodes("/quiz/mchoice").Count

		'Record start time
		ViewState("StartTime") = DateTime.Now

		ShowQuestion(intQuestionNo)
	End If
End Sub


Sub btnSubmit_Click(src as Object, e as EventArgs)

	'Retrieve essential variables from state bag
	intTotalQuestion = ViewState("TotalQuestion")
	intQuestionNo = ViewState("QuestionNo")
	intScore = ViewState("Score")
	arrAnswerHistory = ViewState("AnswerHistory")

	'Correct answer?
	If rblAnswer.SelectedItem.Value = ViewState("CorrectAnswer") Then
		intScore += 1
		arrAnswerHistory.Add(0)
	Else
		arrAnswerHistory.Add(rblAnswer.SelectedItem.Value)
	End If

	'End of quiz?
	If intQuestionNo=intTotalQuestion Then

		'Yes! Show the result...
		QuizScreen.Visible = False
		ResultScreen.Visible = True

		'Render result screen
		ShowResult()

	Else

		'Not yet! Show another question...
		QuizScreen.Visible = True
		ResultScreen.Visible = False
		intQuestionNo += 1
	
		'Render next question
		ShowQuestion(intQuestionNo)
	End If
End Sub


Sub ShowQuestion(intQuestionNo as Integer)
	Dim xNodeList as XmlNodeList
	Dim xNodeAttr as Object
	Dim strXPath as String
	Dim i as Integer
	Dim tsTimeSpent as TimeSpan

	strXPath = "/quiz/mchoice[" & intQuestionNo.ToString() & "]"

	'Extract question
	lblQuestion.Text = intQuestionNo.ToString() & ". " & xDoc.SelectSingleNode(strXPath & "/question").InnerXml

	'Extract answers
	xNodeList = xDoc.SelectNodes(strXPath & "/answer")

	'Clear previous listitems
	rblAnswer.Items.Clear
	
	For i = 0 to xNodeList.Count-1

		'Add item to radiobuttonlist
		rblAnswer.Items.Add(new ListItem(xNodeList.Item(i).InnerText, i+1))

		'Extract correct answer
		xNodeAttr = xNodeList.Item(i).Attributes.ItemOf("correct")
		If not xNodeAttr is Nothing Then
			If xNodeAttr.Value = "yes" Then
				ViewState("CorrectAnswer") = i+1
			End If
		End If
	Next

	'Output Total Question
	lblTotalQuestion.Text = intTotalQuestion

	'Output Time Spent
	tsTimeSpent = DateTime.Now.Subtract(ViewState("StartTime"))
	lblTimeSpent.Text = tsTimeSpent.Minutes.ToString() & ":" & tsTimeSpent.Seconds.ToString()

	'Store essential data to viewstate
	ViewState("TotalQuestion") = intTotalQuestion
	ViewState("Score") = intScore
	ViewState("QuestionNo") = intQuestionNo
	ViewState("AnswerHistory") = arrAnswerHistory

End Sub

Sub ShowResult()
	Dim strResult as String
	Dim intCompetency as Integer
	Dim i as Integer
	Dim strXPath as String
	Dim tsTimeSpent as TimeSpan
	
	tsTimeSpent = DateTime.Now.Subtract(ViewState("StartTime"))

	strResult  = "<center>"
	strResult += "<h3>结果</h3>"
	strResult += "<br>分数: " & intScore.ToString() & " / " & intTotalQuestion.ToString()
	strResult += "<br>成功率: " & Int(intScore/intTotalQuestion*100).ToString() & "%"
	strResult += "<br>用时: " & tsTimeSpent.Minutes.ToString() & ":" & tsTimeSpent.Seconds.ToString()
	strResult += "</center>"

	strResult += "<h3>结果:</h3>"
	For i = 1 to intTotalQuestion
		strXPath = "/quiz/mchoice[" & i.ToString() & "]"
		strResult += "<b>" & i.ToString() & ". " & xDoc.SelectNodes(strXPath & "/question").Item(0).InnerXml & "</b><br>"
		If arrAnswerHistory.Item(i-1)=0 Then
			strResult += "<font color=""write""><b>正确!</b></font><br><br>"
		Else
			strResult += "<b>您的答案:</b> " & xDoc.SelectNodes(strXPath & "/answer[" & arrAnswerHistory.Item(i-1).ToString() & "]").Item(0).InnerXml & "<br>"
			strResult += "<font color=""red""><b>错误</b></font><br><br>"
		End If
	Next

	lblResult.Text = strResult
End Sub

</script>
<html>
<head>
<title>考试测试系统</title>
</head>

<style>
body {
  font-size: 10pt;
  FONT-FAMILY: Arial;
  color:#000000;
  background-color:#eeeedd;
}

tr.heading {
  background-color:#0033CC;
}

.button {
	border: 1px solid #000000;
	background-color: #ffffff;
}

</style>

<META http-equiv=Content-Type content="text/html; charset=gb2312">
<LINK href="css/index05.css" type=text/css rel=stylesheet>
<BODY background="css/bg.gif">
<span id="QuizScreen" runat="server">
<form runat="server">
<table width="100%" border="0" cellpadding="2" cellspacing="0">
  <tr class="heading">
    <td width="50%"><font color="white"><b>测试系统(英语六级试卷)</b></font></td>
	<td width="50%" align="right"><font color="white">&nbsp;</font></td>
  </tr>
  <tr>
    <td colspan="2" bgColor=#ffffff>
	  <b><asp:label id="lblQuestion" runat="server" /></b><br>
      <asp:radiobuttonlist
	     id="rblAnswer"
		 RepeatDirection="vertical"
		 TextAlign="right"
		 RepeatLayout="table"
		 runat="server" /><br>
	  <asp:requiredfieldvalidator
		 ControlToValidate="rblAnswer"
		 ErrorMessage="请选择答案!"
		 runat="server" /><br>
      <asp:button id="btnSubmit" class="button" text="  下一个问题  " onClick="btnSubmit_Click" runat="server" />
	</td>
  </tr>
  <tr class="heading">
    <td width="50%"><font color="white"><b>总计 <asp:label id="lblTotalQuestion" runat="server" /> 问题</b></font></td>
	<td width="50%" align="right"><font color="white"><b>用时 <asp:label id="lblTimeSpent" runat="server" /></b></font></td>
  </tr>
</table>
</form>
</span>
<span id="ResultScreen" runat="server">
<asp:label id="lblResult" runat="server" />
</span>
		
						<TABLE  width="100%">
						<TR>
							<TD  bgColor=#ffffff><!--DWLayoutEmptyCell-->&nbsp;
							 </TD>
						</TR>
						<TR>
							<TD  bgColor=#ffffff><P>
<table width='100%' border='0' align='center' cellpadding='0' cellspacing='0'>
  <tr> <td colspan='4'> <hr size='1' noshade> </td></tr>
  <tr> 
    <td width='340' colspan='4'><a href=\"javascript:window.external.AddFavorite('http://www.shfu.edu.cn','hello')\" title='请点击这里收藏'  class='txt_blue'>收藏</a> | <a href='http://www.shfu.edu.cn' class='txt_blue'>联系我们</a>  </td>
  </tr>
  <tr> <td colspan='4'> <hr size='1' noshade> </td></tr>
  <tr> 
    <td  colspan='4'></td>
  </tr>
  <tr> 
    <td colspan='4'>电话:021-12345678  传真:021-12345678 地址:</td>
  </tr>
</table>
			</TD>
						</TR>
						</TABLE>
       
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -