注:使用asp.net+sqlserver2000,题目只针对选择题
一.数据库设计
1.题目存在一个表中
字段包括:编号id(标识字段),题目内容,题目答案
2.选项存在一个表中
字段包括:编号(标识字段),题目id,显示顺序
二.页面设计
人员的登录什么的就不说了,重点就说说出题
1. 如果随机出题,那么可以在数据库中查询题目时使用order by newid()
如:select * from tablename order by newid()
读出题目后根据题目id去选项表中搜题目的选项,然后绑定。同时需要将答案一并读出并绑定到页面上。
如果选项为单选那就可以绑定一个radiobuttonlist,复选就使用checkboxlist。
绑定好后就产生一个session[“time”]用于保存时间datetime.now()。
2. 如果题目为固定的且每个答题人看的都是一样的,那么题目和选项最好放在页面中静态显示,或者从数据库读出后放在一个静态变量中(如:application),这样在效率上能大大的提高,减轻服务器的压力。
3. 在提交的时候记录好提交时间并与进入页面中产生的session[“time”]相减,得出答题时间。将提交的答案与页面保存的标准答案进行比对,算出答题的正确率与正确题数,与答题时间一并保存入库。
提交的时候需要些客户端的验证,下面是一个验证的javascript代码
function checkitem()
{
alchk=0;//用来保存回答题数
for(k=0;k<44;k++)//44表示有44道题目
{
chkc=0;//每题的回答中有几个选中,这里我使用的是checkbox,如果使用radiobottonlist就只能有一个选中
for(j=0;j<4;j++)//4表示每题都有4个选择项
{
strid = dlquestion__ctl+k+_dlselection__ctl+j+_ckselection;//获得选项在页面中的id
if((document.getelementbyid(strid)).checked)//如果选中
{
chkc++;
}
}
if(chkc>1)//表示超过一个选项
{
h=k+1;
alert(第+h+题答案超过一个!);
return false;
}
if(chkc<1)
{
}
else
{
alchk++;
}
}
if(alchk<44)// alchk<44表示没有答完题目
{
//alert(not finished);
return confirm(您有题目没有完成,是否提交?);
}
return confirm(确定提交吗?);
}
4. 页面中还需要用到一些javascript脚本,如下
<script language="javascript">
//计时器
function display(){
rtime=etime-ctime;
sstime=1800-rtime;
if (rtime>60)
{
m=parseint(rtime/60);
}
else{
m=0;
}
if (sstime>=60)
{
m1=parseint(sstime/60);
}
else{
m1=0;
}
s=parseint(rtime-m*60);
if(s<10)
s="0"+s
s1=parseint(sstime-m1*60);
if(s1<10)
s1="0"+s1
document.getelementbyid(lbleftmin).innertext=m+":"+s
document.getelementbyid(lbcostmin).innertext=m1+":"+s1
window.settimeout("checktime()",1000)
}
function settimes(){
//alert("you have 20 minutes time !")
var time= new date();
hours= time.gethours();
mins= time.getminutes();
secs= time.getseconds();
etime=hours*3600+mins*60+secs;
etime+=1800; //you can change the value of 1200 according to how much time you wish to set the timer. where 1200 is time in secs (1200 = 20 mins * 60 secs/min). max time is 60 mins (3600secs)
checktime();
noback();
}
function checktime(){
var time= new date();
hours= time.gethours();
mins= time.getminutes();
secs= time.getseconds();
ctime=hours*3600+mins*60+secs
if(ctime>=etime){
expired();
}
else
display();
}
function expired(){
document.getelementbyid(btnhid).click();//强制提交,btnhid为一个在页面中高度为0,宽度为0的按钮,按钮的事件在.cs文件写好
//alert("time expired");
//location.href="main.html"; //或者转到其他的页面
}
<!–
//屏蔽鼠标右键
if (window.event)
document.captureevents(event.mouseup);
function nocontextmenu()
{
event.cancelbubble = true
event.returnvalue = false;
return false;
}
function norightclick(e)
{
if (window.event)
{
if (e.which == 2 || e.which == 3)
return false;
}
else
if (event.button == 2 || event.button == 3)
{
event.cancelbubble = true
event.returnvalue = false;
return false;
}
}
document.oncontextmenu = nocontextmenu; // for ie5+
document.onmousedown = norightclick; // for all others
//–>
//屏蔽 f5 刷新键等键
document.onkeydown=function(){
if(event.keycode==8||event.keycode==116||(event.ctrlkey && event.keycode==116)){
alert("禁止刷新网页!");
event.keycode=0;
return false;
}
}
随便写了点,可能不是很成熟,希望和大家分享,如果大家有什么高见欢迎提出。
msn:kingo_x@hotmail.com
