onlineexamaction.java

来自「培训考试系统代码」· Java 代码 · 共 1,182 行 · 第 1/3 页

JAVA
1,182
字号
           SysResultSet rs1 = aplcoms.csCommonQuery("SQL_Agt_EPaperQueryDetail" ,"1" ,"-1").getResultSet();

           if(rs1.next())
           {
              req.setAttribute("title",rs1.getString(1));
           }

            //从数据库中获取考试试卷的试题列表记录
            aplcoms.preparedQuery("");
            aplcoms.setString(1 ,paperId);   //设置条件参数:考试ID号
            SysResultSet rs2 = aplcoms.csCommonQuery("SQL_Agt_OnTestGetTest" ,"1" ,"-1").getResultSet();

            //把结果集存放到session中
            req.setAttribute("ONLINETEST-GETTEST-RESULTSET",rs2);

            //定向到自测页面
            return (mapping.findForward("ontestdo"));
       }
       catch (SysDbException aple)
       {//捕获CommonService系统异常,定向到出错页面
           //输出异常信息
           aple.printStackTrace();
           req.setAttribute("errorId",ErrorCode.COMMONSERVICE_ERROR);
           return (mapping.findForward("error"));
       }
       catch(java.sql.SQLException sqle)
       {//捕获调用aplcoms异常,定向到出错页面
           // 输出异常信息
           sqle.printStackTrace();
           req.setAttribute("errorId",ErrorCode.DATABASE_ERROR);
           return (mapping.findForward("error"));
       }
       catch(Exception e)
       {//捕获未知异常,定向到出错页面
           //输出异常信息
           e.printStackTrace();
           req.setAttribute("errorId",ErrorCode.UNKNOW_ERROR);
           return (mapping.findForward("error"));
       }
       finally
       {//关闭连接实例
           if(aplcoms != null)
           {
              aplcoms.close();
           }
       }
    }



   /**
     * 处理考试的答卷
     */
    private ActionForward dealExamPaper(ActionMapping mapping,
           ActionForm form, HttpServletRequest req,
           HttpServletResponse res)
    {

       //从OnlineExamForm中获取所答考卷的数据信息;
       String[] testIdsArr = ((OnlineExamForm)form).getTestIds();
       int[] testTypeArr = ((OnlineExamForm)form).getTestType();
       int[] scoreArr = ((OnlineExamForm)form).getScore();
       String[] replyArr = ((OnlineExamForm)form).getReply();
       String[] resultArr = ((OnlineExamForm)form).getResult();
       String timeLongStr = ((OnlineExamForm)form).getTimeLong();
       String examId = ((OnlineExamForm)form).getExamId();

       //考试的时间格式为mm:ss,只取mm
       int timeLong = Integer.parseInt(timeLongStr.substring(0,timeLongStr.indexOf(":")));


       //从Session中获取工号
       String staffNo = (String)req.getSession().getAttribute("workerNo");

       //定义连接的实例
       SysDbConn aplcoms = null;
       try
       {
           //得到一个连接的实例
           aplcoms = SysConnPool.getInstance().getAplComs();

/*           //调用存储过程P_Agt_OnExamAddRecord插入考试记录
           aplcoms.preparedSP();
           //设置参数:员工工号、考试ID、考试的时间、考试的时长
           aplcoms.setString(1, staffNo);
           aplcoms.setString(2, examId);
           aplcoms.setInt(3,timeLong);

           SysDataSet ds1 = aplcoms.csCommonSP("P_Agt_OnExamAddRecord");
           SysRecord rc1 = ds1.getParamSet() ;

           if(rc1==null || rc1.getInt(2) == OperatorFlagCode.OPERATOR_EORROR)
           {//定向到出错页面,错误号为:ONEXAM_RECORDADD_ERROR
               req.setAttribute("errorId",ErrorCode.ONEXAM_RECORDADD_ERROR);
               return (mapping.findForward("error"));
           }

           String recordId = rc1.getString(0);
*/
           String recordId = req.getParameter("recordId");

           //答卷试题类型的标志,0:客观题,1:主观题
           int paperFlag = Integer.parseInt(req.getParameter("paperFlag"));

           boolean dealFail = false;
           int allScore = 0;  //得到的分数
           int totalScore = 0; //总分

           //循环调用存储过程P_Agt_OnExamDealReply处理所答的题
           for(int i=0;i<testIdsArr.length;i++)
           {
               aplcoms.preparedSP();
               //设置参数:记录ID号、第i+1道所答试题的信息
               aplcoms.setString(1, recordId);
               aplcoms.setString(2, testIdsArr[i]);
               aplcoms.setString(3, replyArr[i]);
               int theScore = 0;
               if(testTypeArr[i]==1 || testTypeArr[i]==2)
               {//判断题,单选题,计算分数
                  if(replyArr[i].equalsIgnoreCase(resultArr[i]))
                  {//正确
                      theScore = scoreArr[i];
                  }
               }
               if(testTypeArr[i]==3)
               {//多选题;计算分数
                  if(replyArr[i] != null )
                  {
                      if(replyArr[i].length() == resultArr[i].length())
                      {
                         int rightCount = 0;
                         for(int t=0;t<replyArr[i].length();t++)
                         {
                            if(resultArr[i].indexOf(replyArr[i].substring(t,t+1)) != -1)
                            {
                                rightCount++;
                            }
                         }
                         if(rightCount == replyArr[i].length())
                         {//正确
                            theScore = scoreArr[i];
                         }

                      }
                  }
               }

               aplcoms.setInt(4,theScore);

               SysDataSet ds2 = aplcoms.csCommonSP("P_Agt_OnExamDealReply");
               SysRecord rc2 = ds2.getParamSet() ;
               if(paperFlag == 0)
               {//都为客观题
                    allScore += theScore;
               }
               totalScore += scoreArr[i];  //累加试卷的总分
               if(rc2==null || rc2.getInt(0) == OperatorFlagCode.OPERATOR_EORROR)
               {
                   dealFail = true;
                   break;
               }
           }
           if(dealFail == true)
           {
               //调用存储过程P_Agt_OnExamDeleteRecord删除该考试记录;
               //定向到出错页面,错误号为:ONEXAM_RECORDADD_ERROR
               req.setAttribute("errorId",ErrorCode.ONEXAM_RECORDADD_ERROR);
               return (mapping.findForward("error"));
           }
           if(paperFlag == 0)
           {//都为客观题
               SimpleDateFormat sFormat = new SimpleDateFormat("yyyyMMdd");
               //调用存储过程P_Agt_OnExamAddTrain增加培训记录;
               aplcoms.preparedSP();
               aplcoms.setString(1, staffNo);
               aplcoms.setString(2, examId);
               aplcoms.setInt(3,allScore);
               aplcoms.setInt(4,totalScore);
               aplcoms.setString(5,sFormat.format(new Date()));
               aplcoms.setString(6,recordId);

               SysDataSet ds3 = aplcoms.csCommonSP("P_Agt_OnExamAddTrain");
               SysRecord rc3 = ds3.getParamSet() ;
               if(rc3==null || rc3.getInt(0) == OperatorFlagCode.OPERATOR_EORROR)
               {//定向到出错页面,错误号为:ONEXAM_TRAINADD_ERROR
                   req.setAttribute("errorId",ErrorCode.ONEXAM_TRAINADD_ERROR);
                   return (mapping.findForward("error"));
               }

           }
           else
           {//为主观题
               aplcoms.preparedQuery("");
               aplcoms.setString(1 ,recordId);

               aplcoms.csCommonQuery("SQL_Agt_OnExamUpdateStatus" ,"1" ,"-1");

           }
           //定向到考试结果显示页面
           //把考试的答卷为主观题还是客观题信息传送到页面,时长

           //把考试的总分传送到页面
           req.setAttribute("allScore",String.valueOf(allScore));
           req.setAttribute("paperType",String.valueOf(paperFlag));
           req.setAttribute("timeLong",String.valueOf(timeLong));
           return (mapping.findForward("onexamresult"));
       }
       catch (SysDbException aple)
       {//捕获CommonService系统异常,定向到出错页面
           //输出异常信息
           aple.printStackTrace();
           req.setAttribute("errorId",ErrorCode.COMMONSERVICE_ERROR);
           return (mapping.findForward("error"));
       }
       catch(java.sql.SQLException sqle)
       {//捕获调用aplcoms异常,定向到出错页面
           // 输出异常信息
           sqle.printStackTrace();
           req.setAttribute("errorId",ErrorCode.DATABASE_ERROR);
           return (mapping.findForward("error"));
       }
       catch(Exception e)
       {//捕获未知异常,定向到出错页面
           //输出异常信息
           e.printStackTrace();
           req.setAttribute("errorId",ErrorCode.UNKNOW_ERROR);
           return (mapping.findForward("error"));
       }
       finally
       {//关闭连接实例
           if(aplcoms != null)
           {
              aplcoms.close();
           }
       }
    }


   /**
     * 处理自测试题
     */
    private ActionForward dealTestPaper(ActionMapping mapping,
           ActionForm form, HttpServletRequest req,
           HttpServletResponse res)
    {

       //从OnlineExamForm中获取所答考卷的数据信息;
       String[] testIdsArr = ((OnlineExamForm)form).getTestIds();
       int[] testTypeArr = ((OnlineExamForm)form).getTestType();
       int[] scoreArr = ((OnlineExamForm)form).getScore();
       String[] replyArr = ((OnlineExamForm)form).getReply();
       String[] resultArr = ((OnlineExamForm)form).getResult();

       //定义连接的实例
       SysDbConn aplcoms = null;
       try
       {
           //得到一个连接的实例

           int allScore = 0;  //得到的分数
           int totalScore = 0; //总分

           //循环处理所答的题
           for(int i=0;i<testIdsArr.length;i++)
           {

               //设置参数:记录ID号、第i+1道所答试题的信息
               int theScore = 0;
               if(testTypeArr[i]==1 || testTypeArr[i]==2 || testTypeArr[i]==3)
               {//判断题,单选题,多选题;计算分数
                  if(replyArr[i].equalsIgnoreCase(resultArr[i]))
                  {//正确
                      theScore = scoreArr[i];
                  }
               }

               allScore += theScore;

               totalScore += scoreArr[i];  //累加试卷的总分
           }

           //把该自测题总分保存以便统计
           String staffNo = (String)req.getSession().getAttribute("workerNo");
           String lessonId = req.getParameter("lessonId");
           String paperId = ((OnlineExamForm)form).getPaperId();

           //得到一个连接的实例
           aplcoms = SysConnPool.getInstance().getAplComs();

           aplcoms.preparedSP();
           aplcoms.setString(1, lessonId);
           aplcoms.setString(2, staffNo);
           aplcoms.setString(3,paperId);
           aplcoms.setInt(4,allScore);


           SysDataSet ds3 = aplcoms.csCommonSP("P_Agt_OnTestAddRecord");
           SysRecord rc3 = ds3.getParamSet() ;
           if(rc3==null || rc3.getInt(0) == OperatorFlagCode.OPERATOR_EORROR)
           {//定向到出错页面,错误号为:ONEXAM_RECORDADD_ERROR
                req.setAttribute("errorId",ErrorCode.ONEXAM_RECORDADD_ERROR);
                return (mapping.findForward("error"));
           }


           //定向到考试结果显示页面
           //把考试的答卷为主观题还是客观题信息传送到页面,时长

           //把考试的总分传送到页面

           req.setAttribute("replyArr",replyArr);
           req.setAttribute("allScore",String.valueOf(allScore));
           req.setAttribute("totalScore",String.valueOf(totalScore));
           return (mapping.findForward("ontestresult"));
       }
       catch (SysDbException aple)
       {//捕获CommonService系统异常,定向到出错页面
           //输出异常信息
           aple.printStackTrace();
           req.setAttribute("errorId",ErrorCode.COMMONSERVICE_ERROR);
           return (mapping.findForward("error"));
       }
       catch(java.sql.SQLException sqle)
       {//捕获调用aplcoms异常,定向到出错页面
           // 输出异常信息
           sqle.printStackTrace();
           req.setAttribute("errorId",ErrorCode.DATABASE_ERROR);
           return (mapping.findForward("error"));
       }
       catch(Exception e)
       {//捕获未知异常,定向到出错页面
           //输出异常信息
           e.printStackTrace();
           req.setAttribute("errorId",ErrorCode.UNKNOW_ERROR);
           return (mapping.findForward("error"));
       }
       finally
       {//关闭连接实例
           if(aplcoms != null)
           {
              aplcoms.close();
           }
       }
    }

  /**
     * 根据试卷的ID号获取的试卷信息
     */
    private ActionForward getExamResultPaper(ActionMapping mapping,
           ActionForm form, HttpServletRequest req,
           HttpServletResponse res)
    {

       //从OnlineExamForm中获取试卷的ID;
       String paperId = ((OnlineExamForm)form).getPaperId();
       String recordId = req.getParameter("recordId");

       //定义连接的实例
       SysDbConn aplcoms = null;
       try
       {
           //得到一个连接的实例
           aplcoms = SysConnPool.getInstance().getAplComs();

            //从数据库中获取考试试卷的试题列表记录
            aplcoms.preparedQuery("");
            aplcoms.setString(1 ,paperId);   //设置条件参数:考试ID号
            aplcoms.setString(2 ,recordId);
            SysResultSet rs2 = aplcoms.csCommonQuery("SQL_Agt_OnExamResultGetTest" ,"1" ,"-1").getResultSet();

            //把结果集存放到session中
            req.setAttribute("ONLINETEST-GETTEST-RESULTSET",new ResUtil(rs2));

            aplcoms.preparedQuery("");
            aplcoms.setString(1 ,recordId);   //设置条件参数:考试ID号
            SysResultSet rs3 = aplcoms.csCommonQuery("SQL_Agt_ExamGetPublicR" ,"1" ,"-1").getResultSet();
            if(rs3 != null)
            {
               rs3.next();
               req.setAttribute("EXAMPUBLICRESULT",rs3.getString(0));
            }
            //定向到自测页面
            return (mapping.findForward("onexamgetresult"));
       }
       catch (SysDbException aple)
       {//捕获CommonService系统异常,定向到出错页面
           //输出异常信息
           aple.printStackTrace();
           req.setAttribute("errorId",ErrorCode.COMMONSERVICE_ERROR);
           return (mapping.findForward("error"));
       }
       catch(java.sql.SQLException sqle)
       {//捕获调用aplcoms异常,定向到出错页面
           // 输出异常信息

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?