📄 mn_test_rs.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.sql.*" %>
<%@ page import="jinghua.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%! boolean debug=false;%>
<jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
</jsp:useBean>
<%
String testID=request.getParameter("testid");
String studentID=request.getParameter("studentid");
String mn_testID=request.getParameter("mn_testID");
int valid=Integer.parseInt(request.getParameter("valid"));
int old=Integer.parseInt(request.getParameter("old"));
//String testID="62";
//String studentID="1";
if(studentID==null){
Tools.showalert("您还没有登录,或连接超时,请重新登录!",out);
Tools.showJS("window.open('../login.jsp','_self')",out);
}
ResultSet rs=null;
String sql="";
String title="";
int testnum=0;
StringBuffer sb=null;
PreparedStatement pstmt=null;
Statement stmt=null;
String name="";//考生姓名
int correct=0;
int error=0;
String correctAns="";
String youAns="";
StringBuffer dbmsg=new StringBuffer();
StringBuffer testIDs=new StringBuffer();
StringBuffer Answer=new StringBuffer();
StringBuffer Mark=new StringBuffer();
StringBuffer SubAns=new StringBuffer();
StringBuffer SubMark=new StringBuffer();
StringBuffer TF=new StringBuffer();
StringBuffer Dif=new StringBuffer();
int sub_num=0;
Vector explain=new Vector();
String [] arrMark=null;
String [] arrAnswer=null;
String [] arrSubAns=null;
String [] arrTestID=null;
String [] arrTF=null;
String temp="";
String subid="";//科目ID
String markPercent="";//百分制的分数
float testmark=0.0f;
float totalmark=0.0f;
int testNumber=0;
try{
Connection con=DBCon.getConnection();
sql="select id,paper,title,testnum,subid from test where id="+testID;
pstmt=con.prepareStatement(sql);
rs=pstmt.executeQuery();
// pstmt.close();
if(debug){
out.print("<br>sql="+sql);
}
if(rs.next()){
//分析试题:试题ID@答案@分数@难易度; 一道试题的格式,以#号结束
if(debug) out.print("<br>begin:");
String paper=rs.getString("paper");
title=rs.getString("title");
testnum=rs.getInt("testnum");//总试题数量
subid=rs.getString("subid");
if(debug) out.print("<br>paper="+paper+"<br>testnum="+testnum);
String [] tests=paper.split("#");
for(int i=0;i<testnum;i++){
//取回试题号
String [] test=tests[i].split("@");
if(debug) {
out.print("<BR>tests["+i+"]="+tests[i]);
}
testIDs.append(test[0]+",");//题号
Answer.append(test[1]+",");//答案
Mark.append(test[2]+",");
Dif.append(test[3]+",");
testmark+=Float.parseFloat(test[2]);//总分数
}
arrMark=Mark.toString().split(",");
arrAnswer=Answer.toString().split(",");
arrTestID=testIDs.toString().split(",");
//根据arrTestID提取考生提交的答案信息,不填写的为"空";
if(debug){
out.print("<br>Mark="+Mark.toString());
out.print("<br>Answer="+Answer.toString());
out.print("<br>TestID="+testIDs.toString());
out.print("<br>Mark="+Mark.toString() );
out.print("<br>Dif="+Dif.toString());
}
//取回用户提交的答案
for(int i=0;i<testnum;i++){
temp=request.getParameter("radio"+arrTestID[i]);
if (temp==null){
SubAns.append("空"+",") ;
//arrSubAns[i]=new String("@");
}else{
SubAns.append(temp+",");
//arrSubAns[i]=new String(temp);
}
}
if(debug){
out.print("<br>Mark="+Mark.toString());
out.print("<br>Answer="+Answer.toString());
out.print("<br>TestID="+testIDs.toString());
out.print("<br>SubAns="+SubAns.toString());
}
arrSubAns=SubAns.toString().split(",");
//评分
correct=0;
error=0;
testmark=0;
totalmark=0.0f;
for(int i=0;i<testnum;i++)
{
if(valid==1 && old==0){
jinghua.T_Question.addUsedCount(con,Integer.parseInt(arrTestID[i]));
}
totalmark+=Float.parseFloat(arrMark[i]);
if(arrSubAns[i].equals(arrAnswer[i])){
if(valid==1 && old==0){
jinghua.T_Question.addCorrectCount(con,Integer.parseInt(arrTestID[i]));
}
TF.append("T,");
SubMark.append(arrMark[i]+",");
correct++;
if(debug){
Tools.debugmsg("<br>arrMark["+i+"]="+arrMark[i],out);
}
testmark+=Float.parseFloat(arrMark[i]);
}else {
error++;
SubMark.append("0,");
if(arrSubAns[i].equals(" "))
TF.append("@,");
else
TF.append("F,");
}
}
if(debug){
out.print("<br>TF="+TF.toString() );
out.print("<br>SubMark="+SubMark.toString() );
out.print("<br>TF[2]="+TF.toString().charAt(2));
}
arrTF=TF.toString().split(",");
//考生信息
rs.close();
pstmt.close();
sql="select vcUserNo,vcName from UserInfo where vcUserNo="+"'"+studentID+"'";
pstmt=con.prepareStatement(sql);
rs=pstmt.executeQuery();
if(rs.next()){
name=""+rs.getString("vcName");
}
rs.close();
pstmt.close();
//将错题插入错题本
for(int i=0;i<testnum;i++){
if(debug) out.println("<BR>question error id="+arrTestID[i]+
": result="+arrTF[i] );
if(!arrTF[i].equals("T")){
int count=0;
sql=" select count(*) as errcount from errorpad where stu_id='"+studentID+"'"+
" and question_id="+arrTestID[i];
try{
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next()){
count=rs.getInt("errcount");
}
rs.close();
stmt.close();
if(debug){
out.print("<br>errorpad question_id="+arrTestID[i]+
"<br>count="+count);
}
if(count==0){//插入新记录
sql=" insert into errorpad(stu_id,question_id,add_date,errorcount,test_id,mn_test_id,sourcetype)"+
" values('"+studentID+"',"+arrTestID[i]+",CURRENT_TIMESTAMP,1,"+testID+","+mn_testID+",3) ";
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
}else{
sql=" update errorpad set errorcount=errorcount+1 where stu_id='"+studentID+"'"+
" and question_id="+arrTestID[i];
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
}
}
catch(SQLException se){
out.print("<br> query errorpad info error sql="+sql);
out.print("<br>"+se.toString());
}
catch(Exception e){
out.print("<br> query errorpad info error sql="+sql);
out.print("<br>"+e.toString());
}
}//end_if
}//end for errorpad
//记录考试结果
if(valid==1 && old==0){
DecimalFormat df=new DecimalFormat("###.0");//分数换算
markPercent=df.format(testmark/totalmark*100);
//将分数记录到mn_scores表:
//查询mn_scores中是否有相应记录,有则删除
sql="select * from mn_scores where stu_id='"+studentID+"' and mn_test_id="+mn_testID+" and sub_id="+subid;
try{
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next()){//已经有记录,则不更新
rs.close();
stmt.close();
}else
{
rs.close();
stmt.close();
//在mn_scores中增加新的记录
//构造test_rs串:正确答案串#分数串#个人答案串#TF串#难易度串#得分串
//temp=Answer.toString()+"#"+Mark.toString()+"#"+SubAns.toString()+"#"+
//TF.toString()+"#"+Dif.toString()+"#"+SubMark.toString();
temp=SubAns.toString()+"#"+TF.toString()+"#"+SubMark.toString();
sql=" insert into mn_scores(stu_id,mn_test_id,sub_id,score,tea_id,test_date,test_id,test_rs)"+
" values( "+
"'"+studentID+"',"+mn_testID+","+subid+","+testmark+",1,CURRENT_DATE,"+testID+",'"+
temp+"'"+" )";
try{
stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
if(debug){
out.print("<br>insert into mn_scores sql="+sql);
}
}catch(SQLException se){
out.print("<br> insert into mn_scores error sql="+sql);
out.print("<br>"+se.toString());
}
catch(Exception e){
out.print("<br> insert into mn_scores error sql="+sql);
out.print("<br>"+e.toString());
}
//检查这次模拟考试的总科目数
try{
sql="select sub_num from mn_test where id="+mn_testID;
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
sub_num=rs.getInt("sub_num");
else
sub_num=Integer.MAX_VALUE;
rs.close();
stmt.close();
if(debug){
out.print("<br>select subnum sql="+sql);
}
}
catch(SQLException se){
out.print("<br> query mn_test error sql="+sql);
out.print("<br>"+se.toString());
}
catch(Exception e){
out.print("<br> query mn_test error sql="+sql);
out.print("<br>"+e.toString());
}
//查询已经完成的科目数
int have_test=0;
try{
sql="select count(*) as tnum from mn_scores where stu_id='"+studentID+"' and mn_test_id="+mn_testID;
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next()){
have_test=rs.getInt("tnum");
}
rs.close();
stmt.close();
if(debug){
out.print("<br>have test subs="+have_test);
}
}
catch(SQLException se){
out.print("<br> query mn_scores error sql="+sql);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -