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

教育系统应用

开发平台:

WORD

  1. <%@ page contentType="text/html; charset=gb2312" language="java" %>
  2. <%@ page import="java.sql.*" %>
  3. <%@ page import="jinghua.*"%>
  4. <%@ page import="java.text.*" %>
  5. <jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
  6. </jsp:useBean>
  7. <%! boolean debug=false;
  8. String studentID;
  9. %>
  10. <%
  11. try{
  12.     studentID=(String)session.getAttribute("studentID");
  13.     if(studentID==null){
  14.         throw new Exception();
  15.     }
  16.     //Tools.showalert(studentID,out);
  17. }catch(Exception e){
  18.     Tools.showalert("您还没有登录,或连接超时,请重新登录!",out);
  19.      Tools.showJS("window.open('../login.jsp','_self')",out);
  20. }
  21. //testtype: 1浏览的错题;2浏览列表中选中的错题;3错题本中的所有错题
  22. //testorder:2随机顺序;2从难到易;3从易到难
  23. int testtype=Integer.parseInt(request.getParameter("testtype"));
  24. int testorder=Integer.parseInt(request.getParameter("testorder"));
  25. int testnumber=Integer.parseInt(request.getParameter("testnumber"));
  26. boolean printtest;
  27. boolean printanswer;
  28. boolean printtip;
  29. int rownum=0;
  30. if(request.getParameter("printtest")==null)
  31.     printtest=false;
  32. else{
  33.     printtest=true;
  34.     rownum++;
  35. }
  36. if(request.getParameter("printanswer")==null)
  37.     printanswer=false;
  38. else{
  39.     printanswer=true;
  40.     rownum++;
  41. }
  42. if(request.getParameter("printtip")==null)
  43.     printtip=false;
  44. else{
  45.     printtip=true;
  46.     rownum+=2;
  47. }
  48. int selectnum=0;
  49. String errorpad_selectID=(String)session.getAttribute("errorpad_selectID");
  50. String errorpad_sqlcon=(String)session.getAttribute("errorpad_sqlcon");
  51. if(debug){
  52.     out.print("<br>testtype="+testtype+
  53.             "<br>testorder="+testorder+
  54.             "<br>errorpad_sqlcon="+errorpad_sqlcon+
  55.             "<br>errorpad_selectid="+errorpad_selectID+
  56.             "<br>printtest="+printtest+
  57.             "<br>printanswer="+printanswer+
  58.             "<br>printtip="+printtip+
  59.             "<br>rownum="+rownum);
  60. }
  61. ResultSet rs=null;
  62. String sql="";
  63. String sqlcon="";
  64. String sqlorder="";
  65. int testnum=0;
  66. int testmark=0;
  67. PreparedStatement pstmt=null;
  68. Statement stmt=null;
  69. StringBuffer dbmsg=new StringBuffer();
  70. StringBuffer testIDs=new StringBuffer();
  71. StringBuffer errorIDs=new StringBuffer();
  72. //StringBuffer Answer=new StringBuffer();
  73. //StringBuffer Mark=new StringBuffer();
  74. int testNumber=0;
  75. String strName=null;
  76. String strDate=null;
  77. try{
  78.     Connection con=DBCon.getConnection();
  79.     //查询学生信息
  80.     try{
  81.         sql="SELECT   CURRENT_DATE as curdate,`UserInfo`.`vcName` FROM  `UserInfo`"+
  82.             " WHERE  (`UserInfo`.`vcUserNo` = '"+studentID+"')";
  83.         stmt=con.createStatement();
  84.         rs=stmt.executeQuery(sql);
  85.         if(rs.next()){
  86.             strName=rs.getString("vcName");
  87.             strDate=rs.getString("curdate");
  88.         }
  89.         rs.close();
  90.         stmt.close();
  91.     }
  92.     catch(Exception e){
  93.         out.println("<BR>Query student error sql="+sql);
  94.         out.print("<br>"+e.toString());
  95.     }
  96. //构造查询条件
  97. //testtype: 1浏览的错题;2浏览列表中选中的错题;3错题本中的所有错题
  98. //testorder:2随机顺序;2从难到易;3从易到难
  99. switch(testtype){
  100.     case 1:
  101.         sqlcon=errorpad_sqlcon;
  102.         break;
  103.     case 2:
  104.         //计算提交的所选择的错题的数量
  105.         if(errorpad_selectID==null|| errorpad_selectID.trim().equals("")){
  106.             Tools.showalert("还没有从错题本中选择错题!",out);
  107.             Tools.goback(out);
  108.         }else{
  109.        // String [] strarr=errorpad_selectID.split(",");
  110.        // if(debug)   out.print("<br>select num="+strarr.length);
  111.        // if(strarr.length<testnumber){
  112.        //     Tools.showalert("您从错题本中选择的题目数量不足!!",out);
  113.        //     Tools.goback(out);
  114.        // }else{
  115.             sqlcon=errorpad_sqlcon+ " AND (errorpad.id IN ("+errorpad_selectID+")) ";
  116.        // }
  117.         }
  118.         break;
  119.     case 3:
  120.         sqlcon="(`errorpad`.`stu_id` = '"+studentID+"')";
  121.         break;
  122.     default:
  123.         break;
  124. }
  125. switch(testorder){
  126.     case 1:
  127.         sqlorder=" ORDER BY RAND()";
  128.         break;
  129.     case 2:
  130.         sqlorder=" ORDER BY errorpad.errorcount DESC,errorpad.add_date DESC";
  131.         break;
  132.     case 3:
  133.         sqlorder=" ORDER BY errorpad.errorcount ASC,errorpad.add_date DESC";
  134.         break;
  135.     default:
  136.         break;
  137. }
  138. sql="SELECT  errorpad.`id` as errorID,  `question`.`ID`,`question`.`Tip`,`question`.`PreHard` , `question`.`QuestText`,  "+
  139.     " `question`.`Mark`,  `question`.`Answer`"+
  140.     " FROM  `errorpad`"+
  141.     " LEFT OUTER JOIN `question` ON (`errorpad`.`question_id` = `question`.`ID`) "+
  142.     " WHERE "+sqlcon+sqlorder+" LIMIT "+testnumber;
  143.     pstmt=con.prepareStatement(sql);
  144.     rs=pstmt.executeQuery();
  145.     testmark=0;
  146.     testnum=0;
  147.     while(rs.next()){
  148.         testmark+=rs.getInt("Mark");
  149.         testnum++;
  150.         //试题ID@答案@分数@难易度;     一道试题的格式,以#号结束
  151.         testIDs.append(rs.getString("ID")+"@"+rs.getString("Answer")+"@"+rs.getString("Mark")+
  152.             "@"+ rs.getString("PreHard")+"#");
  153.         errorIDs.append(rs.getString("errorID")+",");
  154.     }
  155.     rs.beforeFirst();
  156.     if(debug){
  157.         out.print("<br>query question sql="+sql);
  158.     }
  159. %>
  160. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  161. <!-- saved from url=(0041)http://jsptestonline.cosoft.org.cn/senior/none_xt.jsp -->
  162. <HTML><HEAD><TITLE>共创学堂-错题本在线测验</TITLE>
  163. <META http-equiv=Content-Type content="text/html; charset=gb2312">
  164. <LINK
  165. href="../student/style/style.css" type=text/css rel=stylesheet>
  166. <SCRIPT src="../student/js/html.js"></SCRIPT>
  167. <SCRIPT src="../student/js/gnb_menus_layer.js"></SCRIPT>
  168. <SCRIPT src="../student/js/menu.js"></SCRIPT>
  169. <SCRIPT src="../student/js/jumpmenu.js"></SCRIPT>
  170. <SCRIPT src="../student/js/Valid.js"></SCRIPT>
  171. <META content="MSHTML 6.00.2722.900" name=GENERATOR>
  172. <style media="print">
  173. .noprint { display: none }
  174. </style>
  175. <script language="VBScript">
  176. dim hkey_root,hkey_path,hkey_key
  177. hkey_root="HKEY_CURRENT_USER"
  178. hkey_path="SoftwareMicrosoftInternet ExplorerPageSetup"
  179. '//设置网页打印的页眉页脚为空
  180. function pagesetup_null()
  181. on error resume next
  182. Set RegWsh = CreateObject("WScript.Shell")
  183. hkey_key="header"
  184. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
  185. hkey_key="footer"
  186. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,""
  187. end function
  188. '//设置网页打印的页眉页脚为默认值
  189. function pagesetup_default()
  190. on error resume next
  191. Set RegWsh = CreateObject("WScript.Shell")
  192. hkey_key="header"
  193. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&w&b页码,&p/&P"
  194. hkey_key="footer"
  195. RegWsh.RegWrite hkey_root+hkey_path+hkey_key,"&u&b&d"
  196. end function
  197. </script>
  198. </HEAD>
  199. <BODY text=#000000 bgColor=#ffffff onLoad="pagesetup_null()">
  200. <CENTER>
  201.   <form  ACTION="err_test_rs.jsp"  method="post" name="viewdatabase" target="_blank">
  202.     <table width="80%" border="0" cellspacing="0" cellpadding="0">
  203.       <tr>
  204.         <td width="64%"><img src="../student/images/test_pop_01.gif" width="102" height="27"></td>
  205.         <td align="right"><img src="../student/images/test_pop_02.gif" width="134" height="27"></td>
  206.       </tr>
  207.     </table>
  208.     <!--begin test -->
  209.     <div align="right" class=noprint>
  210.       <OBJECT classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 id=WebBrowser width=0>
  211.       </OBJECT>
  212.       <input name=Button onClick=document.all.WebBrowser.ExecWB(6,6) type=button value=直接打印>
  213.       <input name=Button onClick=document.all.WebBrowser.ExecWB(7,1) type=button value=打印预览>
  214.       <input name=Button onClick=document.all.WebBrowser.ExecWB(8,1) type=button value=页面设置>
  215.       <input name=Button onClick=document.all.WebBrowser.ExecWB(45,1) type=button value=关闭>
  216.     </div>
  217.     <table width="100%" border="0" cellspacing="0" cellpadding="0">
  218.       <tr>
  219.         <td align="center" nowrap class="title1"><div align="center"><font color="#74a8d1" size="+2"><strong><b>共创学堂-错题本</b></strong></font>
  220.           </div></td>
  221.       </tr>
  222.       <tr>
  223.         <td align="center" nowrap class="title1"> <div align="right"> <font color="#74a8d1" size="+2"><strong>
  224.             </strong></font></div>
  225.           <div align="right"></div>
  226.           <div align="left">
  227.             <table width="85%" height="21" border="0" align="center" cellpadding="0" cellspacing="0">
  228.               <tr>
  229.                 <td width="26%"><div align="right"></div></td>
  230.                 <td width="15%" nowrap> <div align="right">姓名:</div></td>
  231.                 <td width="10%" nowrap> <div align="right"><%=strName%></div></td>
  232.                 <td width="4%"><div align="left"></div>
  233.                   <div align="right"></div></td>
  234.                 <td width="45%"><div align="left"><%=strDate%></div></td>
  235.               </tr>
  236.             </table>
  237.           </div>
  238.         </td>
  239.       </tr>
  240.     </table>
  241.   <br>
  242.     <table id=AutoNumber1 style="BORDER-COLLAPSE: collapse"
  243. height=82 cellspacing=1 width="85%" border=0 cellpadding="2" bgcolor="#c1c1c1">
  244.       <tbody>
  245.         <tr class=trh>
  246.           <td width=34 align=center nowrap bgcolor=#eaeaea><b>序号</b></td>
  247.           <td align=middle bgcolor=#eaeaea> <p align=center><b>共<%=testnum%>题</b></p></td>
  248.         </tr>
  249.         <%while(rs.next()){%>
  250.         <tr class=trh1 bgcolor="#FFFFFF">
  251.           <td width="34"  align=center valign="top"><%=(++testNumber)%>. </td>
  252.           <td align=left valign="top">
  253.             <div align="left" >
  254.               <table width="100%" border="0" cellspacing="0" cellpadding="0">
  255.                 <tr class=trh1>
  256.                   <td height="22">
  257.                     <%
  258.          String temp=rs.getString("questtext");
  259.          temp=jinghua.TransformString.deTransformSelection(temp);
  260.          temp=jinghua.TransformString.DeleteBR(temp);
  261.          out.print(temp);
  262.          %>
  263.                   </td>
  264.                 </tr>
  265.         <%if(printanswer){%>
  266.                 <tr class=trh1>
  267.                   <td height="25" align="left" valign="bottom">答案:<%=rs.getString("Answer")%></td>
  268.                 </tr>
  269.         <%}
  270.         if(printtip){
  271.         %>
  272.                 <tr>
  273.                   <td height="22" align="left" valign="bottom">提示:</td>
  274.                 </tr>
  275.                 <tr>
  276.                   <td >
  277.                   <%
  278.                   temp=rs.getString("Tip");
  279.                   temp=jinghua.TransformString.DeleteBR(temp);
  280.                   out.print(temp);
  281.                   %></td>
  282.                 </tr>
  283.         <%}%>
  284.               </table>
  285.             </div>
  286.           </td>
  287.         </tr>
  288.         <%}
  289.     rs.close();
  290.     pstmt.close();
  291.     %>
  292.       </tbody>
  293.     </table>
  294.     <p>&nbsp;</p><p>&nbsp;</p></form></CENTER></BODY></HTML>
  295. <%
  296. }catch(SQLException e){
  297.     out.print("<br>SQL Error:sql="+sql+"<br>"+e.toString());
  298. }catch(Exception e){
  299.     out.print(e.toString() );
  300. }
  301. finally{
  302.     DBCon.dropConnection();
  303. }
  304. %>