unit_sel_rs.jsp
上传用户:nbluoke
上传日期:2013-08-09
资源大小:4851k
文件大小:12k
源码类别:

教育系统应用

开发平台:

WORD

  1. <%@ page contentType="text/html; charset=gb2312" language="java" %>
  2. <%@ page import="java.sql.*" %>
  3. <%@ page import="jinghua.*"%>
  4. <%@ page import="java.util.*"%>
  5. <%@ page import="java.text.*"%>
  6. <%! boolean debug=false;%>
  7. <jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
  8. </jsp:useBean>
  9. <%
  10. String testID=request.getParameter("testid");
  11. String studentID=request.getParameter("studentid");
  12. //String testID="62";
  13. //String studentID="1";
  14. ResultSet rs=null;
  15. Statement stmt=null;
  16. String sql="";
  17. String title="";
  18. int testnum=0;
  19. int i=0;
  20. StringBuffer sb=new StringBuffer();
  21. PreparedStatement pstmt=null;
  22. String name="";//考生姓名
  23. int correct=0;
  24. int error=0;
  25. int count=0;
  26. String correctAns="";
  27. StringBuffer dbmsg=new StringBuffer();
  28. StringBuffer testIDs=new StringBuffer();
  29. StringBuffer Answer=new StringBuffer();
  30. StringBuffer Mark=new StringBuffer();
  31. StringBuffer SubAns=new StringBuffer();
  32. StringBuffer TF=new StringBuffer();
  33. StringBuffer Dif=new StringBuffer();
  34. Vector explain=new Vector();
  35. String [] arrMark=null;
  36. String [] arrAnswer=null;
  37. String [] arrSubAns=null;
  38. String [] arrTestID=null;
  39. String arrTF="";
  40. String temp="";
  41. float testmark=0.0f;
  42. float totalmark=0.0f;
  43. int testNumber=0;
  44. try{
  45.     Connection con=DBCon.getConnection();
  46.     sql="select id,paper,title,testnum from test where id="+testID;
  47.     pstmt=con.prepareStatement(sql);
  48.     rs=pstmt.executeQuery();
  49.    // pstmt.close();
  50.     if(debug){
  51.         out.print("<br>sql="+sql);
  52.     }
  53.     if(rs.next()){
  54.         //分析试题:试题ID@答案@分数@难易度;     一道试题的格式,以#号结束
  55.         if(debug) out.print("<br>begin:");
  56.         String paper=rs.getString("paper");
  57.         title=rs.getString("title");
  58.         testnum=rs.getInt("testnum");//总试题数量
  59.         if(debug) out.print("<br>paper="+paper+"<br>testnum="+testnum);
  60.         String [] tests=paper.split("#");
  61.         for(i=0;i<testnum;i++){
  62.             //取回试题号
  63.             String [] test=tests[i].split("@");
  64.             if(debug) {
  65.                 out.print("<BR>tests["+i+"]="+tests[i]);
  66.             }
  67.             testIDs.append(test[0]+",");//题号
  68.             Answer.append(test[1]+",");//答案
  69. Mark.append(test[2]+"#");
  70.             Dif.append(test[3]+"#");
  71.             testmark+=Float.parseFloat(test[2]);//总分数
  72.         }
  73.         arrMark=Mark.toString().split("#");
  74.         arrAnswer=Answer.toString().split(",");
  75.         arrTestID=testIDs.toString().split(",");
  76.         //根据arrTestID提取考生提交的答案信息,不填写的为"空";
  77.         if(debug){
  78.             out.print("<br>Mark="+Mark.toString());
  79.             out.print("<br>Answer="+Answer.toString());
  80.             out.print("<br>TestID="+testIDs.toString());
  81.         }
  82.         for( i=0;i<testnum;i++){
  83.            temp=request.getParameter("radio"+arrTestID[i]);
  84.            if (temp==null){
  85.                SubAns.append("空"+",") ;
  86.                //arrSubAns[i]=new String("@");
  87.            }else{
  88.                SubAns.append(temp+",");
  89.                //arrSubAns[i]=new String(temp);
  90.            }
  91.         }
  92.         if(debug){
  93.             out.print("<br>Mark="+Mark.toString());
  94.             out.print("<br>Answer="+Answer.toString());
  95.             out.print("<br>TestID="+testIDs.toString());
  96.             out.print("<br>SubAns="+SubAns.toString());
  97.         }
  98.         arrSubAns=SubAns.toString().split(",");
  99.         //评分
  100.         correct=0;
  101.         error=0;
  102.         testmark=0;
  103.         totalmark=0.0f;
  104.         for(i=0;i<testnum;i++)
  105.         {
  106.             totalmark+=Float.parseFloat(arrMark[i]);
  107.             if(arrSubAns[i].equals(arrAnswer[i])){
  108.                 TF.append("T");
  109.                 correct++;
  110.                 if(debug){
  111.                     Tools.debugmsg("<br>arrMark["+i+"]="+arrMark[i],out);
  112.                 }
  113.                 testmark+=Float.parseFloat(arrMark[i]);
  114.             }else {
  115.                 error++;
  116.                 if(arrSubAns[i].equals(" "))
  117.                     TF.append("@");
  118.                 else
  119.                     TF.append("F");
  120.             }
  121.         }
  122.         arrTF=TF.toString();
  123.         //考生信息
  124.         rs.close();
  125.         pstmt.close();
  126.         sql="select vcUserNo,vcName from UserInfo where vcUserNo="+"'"+studentID+"'";
  127.         pstmt=con.prepareStatement(sql);
  128.         rs=pstmt.executeQuery();
  129.         if(rs.next()){
  130.             name=""+rs.getString("vcName");
  131.         }
  132.         rs.close();
  133.         pstmt.close();
  134.         //记录考试结果
  135.         DecimalFormat df=new DecimalFormat("###.0");//分数换算
  136.         String r=df.format(testmark/totalmark*100);
  137.         jinghua.T_score t_score=new jinghua.T_score(studentID,Integer.parseInt(testID) ,testmark ,"2",1);    //2:自由单元测试 1:系统判分
  138.         r=t_score.storeMark(2);
  139.         if(debug){
  140.             out.print("<br>t_score:"+r);
  141.         }
  142.         if(!r.equals("OK")){
  143.             throw new Exception("自由单元测试成绩入库错误!cbd");
  144.         }
  145. //将错题插入错题本
  146. for(i=0;i<testnum;i++){
  147. if(debug) out.println("<BR>question error id="+arrTestID[i]+
  148.              ": result="+arrTF.charAt(i) );
  149. if(arrTF.charAt(i)!='T'){
  150. count=0;
  151. sql=" select count(*) as errcount from errorpad where stu_id='"+studentID+"'"+
  152. " and question_id="+arrTestID[i];
  153. try{
  154.      stmt=con.createStatement();
  155.      rs=stmt.executeQuery(sql);
  156.      if(rs.next()){
  157. count=rs.getInt("errcount");
  158.      }
  159. rs.close();
  160. stmt.close();
  161. if(debug){
  162.              out.print("<br>errorpad question_id="+arrTestID[i]+
  163. "<br>count="+count);
  164.          }
  165. if(count==0){//插入新记录
  166. sql=" insert into errorpad(stu_id,question_id,add_date,errorcount,test_id,sourcetype)"+
  167. " values('"+studentID+"',"+arrTestID[i]+",CURRENT_TIMESTAMP,1,"+testID+",2) ";
  168. stmt=con.createStatement();
  169. stmt.executeUpdate(sql);
  170. stmt.close();
  171. }else{
  172. sql=" update errorpad set errorcount=errorcount+1 where stu_id='"+studentID+"'"+
  173. " and question_id="+arrTestID[i];
  174. stmt=con.createStatement();
  175. stmt.executeUpdate(sql);
  176. stmt.close();
  177. }
  178. }
  179.      catch(SQLException se){
  180.              out.print("<br> query errorpad info error sql="+sql);
  181.          out.print("<br>"+se.toString());
  182.      }
  183.     catch(Exception e){
  184.          out.print("<br> query errorpad info error sql="+sql);
  185.         out.print("<br>"+e.toString());
  186.     }
  187. }//end_if
  188. }//end for errorpad
  189.     //试题记录集
  190. sql=testIDs.toString().substring(0,testIDs.length()-1);
  191.         sql="select id,questtext,tip,mark from question where id in ("+sql+") order by id";
  192. pstmt=con.prepareStatement(sql);
  193.         rs=pstmt.executeQuery();
  194.      }
  195. %>
  196. <html>
  197. <head>
  198. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  199. <title>成绩查询 | 考试成绩 |  | 单项选择题</title>
  200. <link rel="stylesheet" type="text/css" href="../css.css">
  201. </head>
  202. <body>
  203. <center>
  204.   <table border="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2" height="25">
  205.     <tr>
  206.       <td width="100%" height="29" style="border-left-style: solid; border-left-width: 0; border-right-style: solid; border-right-width: 0; border-top-style: solid; border-top-width: 0; border-bottom: 1px solid #000000">
  207.         <img border="0" src="../images/cxcj.gif"></td>
  208.     </tr>
  209.     <tr>
  210.       <p>&nbsp;</p>
  211.     </tr>
  212.   </table>
  213.   <p>&nbsp;</p>
  214. </center>
  215. <div align="center">
  216.   <center>
  217.   <table cellspacing="1" style="border-collapse: collapse" bordercolor="#799AE1" width="469" id="AutoNumber2" border="1">
  218.       <form method="POST" action=""><tr>
  219.       <td width="100%" height="25" bgcolor="#6699CC" background="images/admin_bg_1.gif" bordercolor="#799AE1">
  220.       <p align="center"><b>&nbsp;<font color="#FFFFFF">成绩单</font></b></td>
  221.     </tr>
  222.     <tr>
  223.       <td width="100%" height="160" bgcolor="#FFFDE8" bordercolor="#799AE1">
  224.         <p align="center"> </p>
  225.             <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="202">
  226.               <tr>
  227.                 <td width="8%" height="28"> <p align="right">考生编号:</td>
  228.                 <td height="28" colspan="4"> <%=studentID%></td>
  229.               </tr>
  230.               <tr>
  231.                 <td width="8%" height="29"> <p align="right">姓&nbsp;&nbsp;&nbsp;
  232.                     名:</td>
  233.                 <td height="29" colspan="4"><%=name%>&nbsp;</td>
  234.               </tr>
  235.               <tr>
  236.                 <td width="8%" height="29"> <p align="right">得&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;分:</td>
  237.                 <td width="13%" height="29">卷面分:</td>
  238.                 <td width="23%"><%=testmark%>&nbsp;</td>
  239.                 <td width="15%">百分制:</td>
  240.                 <td width="41%">
  241.                 <% DecimalFormat df=new DecimalFormat("###");
  242.                     String r=df.format(testmark/totalmark*100);
  243.                     out.print(r);
  244.                 %>
  245.             &nbsp;&nbsp;</td>
  246.               </tr>
  247.               <tr>
  248.                 <td width="8%" height="29"> <p align="right">答&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;错:</td>
  249.                 <td height="29" colspan="4"><%=error%>&nbsp;</td>
  250.               </tr>
  251.               <tr>
  252.                 <td width="8%" height="29"> <p align="right">答&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;对:</td>
  253.                 <td height="29" colspan="4"><%=correct%>&nbsp;</td>
  254.               </tr>
  255.               <tr>
  256.                 <td height="29"> <p align="right">正确答案:</p></td>
  257.                 <td height="29" colspan="4"><%=Answer.toString() %>&nbsp;</td>
  258.               </tr>
  259.               <tr>
  260.                 <td height="29"><p align="right">您的答案:</p></td>
  261.                 <td height="29" colspan="4"><%=SubAns.toString()%>&nbsp;</td>
  262.               </tr>
  263.             </table>
  264.         <p align="center"> </p>
  265.       </td>
  266.     </tr>
  267.     <tr>
  268.           <td width="100%" height="25" bgcolor="#FFFFFF" bordercolor="#799AE1"> <p align="center">
  269.               <INPUT class="s02" onclick="window.close()" type=button value=返回 name=close2>
  270.               <span lang="en-us"> </span></td>
  271.  </tr></form>
  272.   </table>
  273.   </center>
  274. </div>
  275. <center><form name="viewdatabase"  ACTION=""  method="post">
  276.   <table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#799AE1" width="100%" id="AutoNumber1" height="82">
  277.     <tr class="trh">
  278.       <td width="44" align="center" bgcolor="#799AE1" height="24">
  279.       <font color="#FFFFFF"><b>序号</b></font></td>
  280.         <td align="center" bgcolor="#799AE1" width="592" height="24"> <p align="center"><font color="#FFFFFF">
  281. <b>单项选择题(共<%=testnum%>&nbsp;题,<%=totalmark%>分)</b></font></td>
  282.     </tr>
  283. <% testNumber=0;
  284. while(rs.next()){%>
  285.     <tr class="trh1">
  286.         <td align="center"   height="35" width="44"> 
  287. <center><%out.print(testNumber+1);%></center>&nbsp;</td>
  288.         <td align="left" width="592" height="35"><br>
  289. <%
  290. out.print("正确答案是"+arrAnswer[testNumber]+",&nbsp;&nbsp;");
  291.                         if(arrTF.charAt(testNumber)=='T'){
  292.                             out.print("您的答案是"+arrSubAns[testNumber] +"<br>");
  293.                         }else{
  294.                             out.print("<font color=Red>您的答案是"+arrSubAns[testNumber] +"</font><br>");
  295.                         }
  296. out.print("原题目:<br>"+rs.getString("questtext"));
  297. out.print("<br>提示:<br>"+""+rs.getString("tip"));
  298. testNumber++;
  299. %>
  300. </td>
  301.     </tr>
  302. <%}
  303.     rs.close();
  304.     pstmt.close();
  305.     %>
  306.     <tr>
  307.       <td align="center" bgcolor="#FFFFFF" height="16" width="640" colspan="2" bordercolor="#FFFFFF">
  308.       <p align="center">
  309.       <INPUT class="s02" onclick="window.close()" type=button value=返回 name=close>
  310.       </p>
  311.       </td>
  312.       </tr>
  313.   </table>
  314. </form>
  315.  </center>
  316.  <center> <form ACTION="" METHOD="GET">
  317.     <table style="border-collapse: collapse" bordercolor="#111111" cellpadding="0" cellspacing="0">
  318.       <tr>
  319.         <td width="576">
  320.         <p ALIGN="center">&nbsp;</p>
  321.         <p> </td>
  322.       </tr>
  323.     </table>
  324.   </form>
  325.  </center>
  326. </body>
  327. </html>
  328. <%}
  329. catch (Exception e){
  330.     if(debug){
  331.        Tools.debugmsg("<BR>Exception:"+e.toString() ,out);
  332.     }
  333. }
  334. finally{
  335.     DBCon.dropConnection();
  336. }
  337. %>