To design an online examination system, the paper timing is a problem that must be solved, because the examination has a time limit for answering questions, and the time is one to reach. For those who have not yet handed in the exam, the system should have the function of forcibly collecting volumes. Of course, the most important thing for an online examination system is its answer saving function. We will not discuss it here, but only analyze the problem of rolling timing, finally, a timer control that runs on the client and can call the server method after timeout is designed. -- Cncxz (wormhole) 2005-12-3
Problem Analysis
(1) The examinee opens the question loading page, marking the start of the examination. Therefore, the timing should start from this moment.
(2) The server can only provide data when there is a client request, rather than actively post information to the browser, so the timing must be implemented on the client.
(3) force submit is essentially to save the answer and exit the answer interface, and data needs to be sent back, so this operation should be a server method.
(4) There should be a friendly interface, prompting the examinee how much time is left.
(5) In order to prevent some candidates from cheating by capturing pictures on the examination page, saving the picture, exiting the system, and making a question based on the figure, and then entering the answer, the examination time is determined at the same time.
(6) candidates who accidentally quit the Q & A interface during the examination due to uncertainties such as network disconnection and crashes cannot accurately determine the difference between them and those who are deliberately cheating, I can't find a proper solution, but it's just that they're unlucky and waste the waiting time. You have a way to discuss it.
Proposal
For the above analysis, we can propose a rough solution.
In terms of databases, the exam information table should contain the examinee's ID (string, which can be used with the exam number), start time (DateTime), answer End Time (DateTime), and handed in (bool) four fields (of course, there are other required fields, which are not described in detail here. After all, all I want to talk about is the rolling surface timing problem ).
On the client side, a javascript function is called during onload on the Q & A page to start timing. This function is executed cyclically to save the used time at any time. Here, the cycle is set to 1 minute, in the function body, you must first determine whether the time limit has been reached. If yes, you must hand in the paper. If not, the friendly interface timing information will be displayed and wait for the next call. The relevant js Code is as follows:
<Script language = "JavaScript">
Var myTimeOut = 30; // available time, in minutes
Var myPassTime = 0; // used time, in minutes
Window. attachEvent ("onload", myTimer); // bind to the onload event
Function myTimer (){
If (myPassTime <myTimeOut) {// whether the used time is earlier than the available time
MyPassTime + = 1; // save the time used by the client
// Display the timer information on the friendly interface.
} Else {
// Execute force submit
// You can simulate clicking a linkbutton,
// On the server side, the code for forcibly handing in the paper can be put in the Click of the linkbutton first.
}
Window. setTimeout ("myTimer ()", 60000); // one-minute cycle
}
</Script>
In terms of server code, the Page_Load event initializes the exam information:
If (retrieve the exam information of the current candidate according to the identity ){
If (submitted ){
Feedback of submitted documents
} Else {
If (current time <answer End Time ){
Set the used time so that the examinee can continue to answer questions.
} Else {
Force submit
}
}
} Else {
Add exam information
Set the start time (set to the current time), End Time (the current time plus the total available time), and volume (false)
Normal entrance to test room
}
Put a linkbutton on the examination page, and write the mandatory submit code in the Click of the control for js to execute when it simulates the Click.
Design controls
To facilitate future use, the timing-related functions are encapsulated into a custom control.
Control name: clientTimer, inherited from PlaceHolder, namespace is myControl.
Public attributes:
Attribute name: TimeOutUnits
Class: TimeOutUnitsType
Description: The unit of time. It can be seconds, minutes, or hours. The default value is minutes.
Attribute name: TimeOutLength
Class: int
Description: time-out time (unit: Consistent with the TimeOutUnits attribute ).
Property name: PassTimeLength
Class: int
Description: used time (unit: Consistent with the TimeOutUnits attribute ).
Property name: TimerEnabled
Type: bool
Introduction: whether to enable the timer.
Attribute name: CountDown
Type: bool
Introduction: whether to display the friendly interface in Countdown mode. It shows the remaining time; otherwise, it shows the time used.
Public events:
Event name: onTimeOut
Introduction: When execution times out, you can put the code for forcible submission in it for execution.
Control source code:
Http://cncxz.cnblogs.com/archive/2005/12/03/289991.html
Control Test
1. Save and compile the control source code into a dll file and add it to the control panel of.
2. Create a WebApplication Project (WebApplication1)
3. Add a clientTime control (clientTime1) and a Label control (Label1) to the default WebForm1.aspx.
4. Select clientTime1 and set it in the property panel:
The clientTime1.TimerEnabled attribute is true.
The ClientTimer1.TimeOutUnits attribute is Second. // The effect is easy to observe.
The ClientTimer1.TimeOutLength attribute is 30.
ClientTimer1.PassTimeLength attribute is 5
ClientTimer1.CountDown attribute is true // countdown
5. Double-click in the blank space of WebForm1.aspx, switch to the codebehind view, and add the following code:
Private void Page_Load (object sender, System. EventArgs e)
{
// Place user code here to initialize the page
This. ClientTimer_Test.onTimeOut + = new myControl. onTimeOutEventHandler (this. ClientTimer1_onTimeOut );
}
Private void ClientTimer1_onTimeOut (){
This. ClientTimer_Test.TimerEnabled = false;
Label1.Text = DateTime. Now. ToString () + "by Time ";
}
6. Press F5 to compile and run the program. On the WebForm1.aspx page, you can see a countdown for reading seconds. After, the current time and time are displayed in Label1.
Control usage
1. Save and compile the control source code into a dll file and add it to the control panel of.
2. Drag a widget to the exam page (assuming its id is clientTime1)
3. register the onTimeOut event of clientTime1 in the Page_Load event. Of course, you must have the code to initialize the exam information.
Private void Page_Load (object sender, System. EventArgs e)
{
This. ClientTimer_Test.onTimeOut + = new myControl. onTimeOutEventHandler (this. ClientTimer1_onTimeOut );
// If (the exam information of the current candidate is retrieved based on the identity ){
// If (submitted ){
// ClientTimer1.TimerEnabled = false; // No time needed
// Report submitted information
//} Else {
// If (current time <answer End Time ){
// ClientTimer1.TimerEnabled = true; // enable the timing Function
// ClientTimer1.TimeOutUnits = myControl. TimeOutUnitsType. Minute; // set the unit to Minute.
// ClientTimer1.TimeOutLength = the difference between the answer End Time and the start time; // you can specify the total answer time.
// ClientTimer1.PassTimeLength = the difference between the answer End Time and the current time; // set the used time
/// Continue to answer questions
//} Else {
// ClientTimer1.TimerEnabled = false; // No time needed
// Submit the exam forcibly
//}
//}
//} Else {
// Add exam information for the examinee
// Set the start time (set to the current time), answer end time (the current time plus the total available time), and score (false)
// ClientTimer1.TimerEnabled = true; // enable the timing Function
// ClientTimer1.TimeOutUnits = myControl. TimeOutUnitsType. Minute; // set the unit to Minute.
// ClientTimer1.TimeOutLength = total available time; // you can specify the total answer time.
// ClientTimer1.PassTimeLength = 0; // set the time in use
// Enter the test room normally
//}
}
Private void ClientTimer1_onTimeOut (){
This. ClientTimer1.TimerEnabled = false; // No time needed
// Here is the code for forcible submission.
}
Additional instructions
Pay attention to the timing unit selection during use. The timing unit should be consistent on the whole. We recommend that you use the minute.
In addition, I did not carefully consider the design of the entire examination system. I just selected the rolling area timing for analysis. I hope it will help my friends who will design the examination system.