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

教育系统应用

开发平台:

WORD

  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
  2. <%@ page import="jinghua.*"%>
  3. <jsp:useBean id="DBCon" class="jinghua.JinghuaConn" scope="session">
  4. </jsp:useBean>
  5. <%!boolean debug=false;
  6. %>
  7. <%
  8. String test_grade=request.getParameter("Grade");
  9. String test_sub=request.getParameter("Subject");
  10. String test_knowpoint=request.getParameter("KnowPoint");
  11. String test_testtype=request.getParameter("testtype");
  12. if(debug){
  13.     out.print("<br>grade="+test_grade+
  14.     "<br>sub="+test_sub+
  15.     "<br>knowpoint="+test_knowpoint+
  16.     "<br>testtype="+test_testtype);
  17. }
  18. String [] ids=request.getParameterValues("id");
  19. if(ids==null){
  20.      Tools.showalert("请您选择欲删除的知识点!",out);
  21.     Tools.goback(out);
  22. }else
  23. {
  24. String [] question=null;
  25. String sql=null;
  26. String paper=null;
  27. Connection con=null;
  28. StringBuffer sb=null;
  29. Statement stmt=null;
  30. ResultSet rs=null;
  31. try{
  32.     con=DBCon.getConnection();
  33.     con.setAutoCommit(false);
  34.     if(test_testtype.equals("2") || test_testtype.equals("1") ){
  35.     //单元测试
  36.     for(int i=0;i<ids.length;i++)
  37.     if(debug) out.print("<br>delete 单元测试:");
  38.     for(int i=0;i<ids.length;i++){
  39.         //取回试题
  40.                 if(debug) out.print("<br> test id="+ids[i]);
  41.         sql="SELECT  `test`.`paper` FROM  `test` WHERE  (`test`.`id` = "+ids[i]+")";
  42.         stmt=con.createStatement();
  43.         rs=stmt.executeQuery(sql);
  44.         if(rs.next())
  45.             paper=rs.getString("paper");
  46.         rs.close();
  47.         stmt.close();
  48.                 if(debug) out.print("<br>test paer="+paper);
  49.         //delete question
  50. if(!(paper==null || paper.equals(""))){
  51.          question=paper.split("#");
  52.          sb=new StringBuffer();
  53.          //585@A@5@A#586@B@6@B#587@C@7@C#588@D@8@E#
  54.         for(int j=0;j<question.length;j++){
  55.             //delete question ID
  56.             sb.append(question[j].substring(0,question[j].indexOf("@"))+",");
  57.         }
  58.         paper=sb.toString().substring(0,sb.toString().length()-1);
  59.         if(debug) out.print("<br>delete question id="+paper);
  60.         sql="delete from question where id in ("+paper+")";
  61.         stmt=con.createStatement();
  62.         stmt.executeUpdate(sql);
  63.         stmt.close();
  64. }//end if paper not null
  65.         //delete scores
  66.         sql="delete from scores where test_id="+ids[i];
  67.         if(debug) out.print("<br>delete scores sql="+sql);
  68.         stmt=con.createStatement();
  69.         stmt.executeUpdate(sql);
  70.         stmt.close();
  71.          //delete errorpad
  72.         sql="delete from errorpad where test_id="+ids[i];
  73.         if(debug) out.print("<br>delete errorpad sql="+sql);
  74.         stmt=con.createStatement();
  75.         stmt.executeUpdate(sql);
  76.         stmt.close();
  77.         //delete test
  78.         sql="delete from test where id="+ids[i];
  79.         if(debug) out.print("<br>delete test sql="+sql);
  80.         stmt=con.createStatement();
  81.         stmt.executeUpdate(sql);
  82.         stmt.close();
  83.         con.commit();
  84.     }//end for delete test
  85.     }//end if
  86.     else if(test_testtype.equals("3")){
  87.      //delete mn_test
  88.         if(debug) out.print("<br>delete 模拟测试:");
  89.         for(int k=0;k<ids.length;k++){
  90.         //取回试题
  91.         sql="SELECT  `mn_test`.`test_paper` FROM  `mn_test` WHERE  (`mn_test`.`id` = "+ids[k]+")";
  92.         stmt=con.createStatement();
  93.         rs=stmt.executeQuery(sql);
  94.         if(rs.next())
  95.             paper=rs.getString("test_paper");
  96.         rs.close();
  97.         stmt.close();
  98.         if(debug) out.print("<br>mn_test: test_paper="+paper);
  99.         if(!(paper==null || paper.equals(""))){
  100.         //delete test
  101.         String [] testIDs=paper.split(",");
  102.         //单元测试
  103.         if(debug) out.print("<br>delete 单元测试:");
  104.         for(int i=0;i<testIDs.length;i++){
  105.             //取回试题
  106.             sql="SELECT  `test`.`paper` FROM  `test` WHERE  (`test`.`id` = "+testIDs[i]+")";
  107.             stmt=con.createStatement();
  108.             rs=stmt.executeQuery(sql);
  109.             if(rs.next())
  110.                 paper=rs.getString("paper");
  111.             rs.close();
  112.             stmt.close();
  113.             if(debug) out.print("<br>test paer="+paper);
  114.             if(!(paper==null || paper.equals(""))){
  115.             //delete question
  116.             question=paper.split("#");
  117.             sb=new StringBuffer();
  118.             //585@A@5@A#586@B@6@B#587@C@7@C#588@D@8@E#
  119.             for(int j=0;j<question.length;j++){
  120.                 //delete question ID
  121.                 sb.append(question[j].substring(0,question[j].indexOf("@"))+",");
  122.             }
  123.             paper=sb.toString().substring(0,sb.toString().length()-1);
  124.             if(debug) out.print("<br>delete question id="+paper);
  125.             sql="delete from question where id in ("+paper+")";
  126.             stmt=con.createStatement();
  127.             stmt.executeUpdate(sql);
  128.             stmt.close();
  129.             }//end if paper not null
  130.             //delete test
  131.             sql="delete from test where id="+testIDs[i];
  132.             if(debug) out.print("<br>delete test sql="+sql);
  133.             stmt=con.createStatement();
  134.             stmt.executeUpdate(sql);
  135.             stmt.close();
  136.         }//end for delete test
  137.         }//end if paper not null
  138.         //delete mn_scores
  139.         sql="delete from mn_scores where mn_test_id="+ids[k];
  140.         if(debug) out.print("<br>delete mn_scores sql="+sql);
  141.         stmt=con.createStatement();
  142.         stmt.executeUpdate(sql);
  143.         stmt.close();
  144.         //delete mn_history
  145.         sql="delete from mn_history where mn_test_id="+ids[k];
  146.         if(debug) out.print("<br>delete mn_history sql="+sql);
  147.         stmt=con.createStatement();
  148.         stmt.executeUpdate(sql);
  149.         stmt.close();
  150.         //delete errorpad
  151.         sql="delete from errorpad where mn_test_id="+ids[k];
  152.         if(debug) out.print("<br>delete errorpad sql="+sql);
  153.         stmt=con.createStatement();
  154.         stmt.executeUpdate(sql);
  155.         stmt.close();
  156.          //delete mn_test
  157.         sql="delete from mn_test where id="+ids[k];
  158.         if(debug) out.print("<br>delete mn_test sql="+sql);
  159.         stmt=con.createStatement();
  160.         stmt.executeUpdate(sql);
  161.         stmt.close();
  162.         con.commit();
  163.         }//end for delete mn_test
  164.     }//end if
  165.      if(!debug)
  166.              response.sendRedirect("modify_test.jsp");
  167.     }//end try
  168.     catch(SQLException se){
  169.         out.println("<br>sql="+sql);
  170.         out.println("<br>"+se.toString());
  171.     }
  172.     catch(Exception e){
  173.         out.println("<br>sql="+sql);
  174.         out.print(e.toString());
  175.     }
  176.     finally{
  177.         DBCon.dropConnection();
  178.     }
  179. }
  180. %>