⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mertmngoperatoraction.java

📁 培训考试系统代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
   * @throws IOException
   */
  private void upfile(FormFile file, String path) throws FileNotFoundException,
      IOException {
    log("upfile now ...." + path);
    File filepath = new File(path);
    if (!filepath.exists())
      filepath.mkdirs();

    String fileName = path + File.separator + file.getFileName();
    String contentType = file.getContentType();
    String size = (file.getFileSize() + " bytes");

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    InputStream stream = file.getInputStream();
    OutputStream bos = new FileOutputStream(fileName);
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
    //System.out.println("filename" +theForm.getFilePath());
    while ( (bytesRead = stream.read(buffer, 0, 8192)) != -1) {
      bos.write(buffer, 0, bytesRead);
    }
    bos.close();
    stream.close();
    file.destroy();
  }

  /**
   * 给资料的权限赋值
   * @param mapping
   * @param form
   * @param req
   * @return
   */
  private ActionForward auth(ActionMapping mapping,
                             MertMngOperatorForm form,
                             HttpServletRequest req) {
    log("auth now ....");
    SysConnPool cspool = null;
    SysDbConn con = null;

    try {
      cspool = SysConnPool.getInstance();
      con = cspool.getAplComs();
      con.preparedQuery("");
      SysResultSet res = con.csCommonQuery("SQL_Agt_GetStaffNo", "1", "-1").
      getResultSet();
      req.getSession().setAttribute("MERT_AUTHRES", new ResUtil(res));
    }
    catch (SysDbException e) {
      //e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.COMMONSERVICE_ERROR);
      return servlet.findForward("error");
    }
    catch (java.sql.SQLException e) {
      e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.DATABASE_ERROR);
      return servlet.findForward("error");
    }
    finally {
      con.close();
    }
    return mapping.findForward("auth");
  }

  /**
   * 得到资料的详细信息,可以被用来view跟修改的页面进入
   * @param mapping
   * @param form
   * @param req
   * @return
   */
  private ActionForward modify(ActionMapping mapping,
                               MertMngOperatorForm form,
                               HttpServletRequest req) {
    log("search now ....");
    SysConnPool cspool = null;
    SysDbConn con = null;
    try {
      cspool = SysConnPool.getInstance();
      con = cspool.getAplComs();
      con.preparedSP();
      getDetail(con, form, req);
    }
    catch (SysDbException e) {
      e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.COMMONSERVICE_ERROR);
      return servlet.findForward("error");
    }
    catch (java.sql.SQLException e) {
      e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.DATABASE_ERROR);
      return servlet.findForward("error");
    }
    finally {
      con.close();
    }
    req.setAttribute("searchSQL", form.getSearchSQL());
    if (form.getOperatorFlag().equals(OperatorFlagCode.MERT_VIEW)) {
      return mapping.findForward("view");
    }
    else {
      return mapping.findForward("modify");
    }
  }

  /**
   *
   * @param mapping
   * @param form
   * @param req
   * @return
   */
  private void getDetail(SysDbConn con,
                         MertMngOperatorForm form,
                         HttpServletRequest req) throws
      SysDbException, java.sql.SQLException {

    con.preparedSP();
    con.setString(1, form.getMatid()[0]);
    SysResultSet res = con.csCommonSP("P_Agt_MaterDetail").getResultSet();
    req.setAttribute("matid", form.getMatid()[0]);
    while (res.next()) {
      req.setAttribute("title", res.getString("TITLE"));
      req.setAttribute("keyWord", res.getString("KEYWORD"));
      req.setAttribute("abstracts", res.getString("ABSTRACT"));
      req.setAttribute("matype", res.getString("MATYPE"));
      req.setAttribute("classid", res.getString("CLASSID"));
      req.setAttribute("authinfo", res.getString("AUTH"));
      req.setAttribute("staffnoinfo", res.getString("STAFFNO"));
      String filename1 = res.getString("LINKFILE");
      //用于修改保存的时候传递的参数
      req.setAttribute("fileName", filename1);
      filename1 = filename1.substring(filename1.lastIndexOf(File.separator) + 1);
      //用于在客户端显示,只显示文件名字没有路径信息
      req.setAttribute("fileName1", filename1);
    }
    req.setAttribute("searchSQL", form.getSearchSQL());
  }

  /**
   * 删除资料
   * @param mapping
   * @param form
   * @param req
   * @return
   */
  private ActionForward remove(ActionMapping mapping,
                               MertMngOperatorForm form,
                               HttpServletRequest req) {
    log("remove now ....");
    SysConnPool cspool = null;
    SysDbConn con = null;
    try {
      cspool = SysConnPool.getInstance();
      con = cspool.getAplComs();
      con.preparedSP();
      con.setString(1, form.getMatid()[0]);
      String temp[] = form.getMatid();
      String matids = "";
      for (int i = 0; i < temp.length - 1; i++) {
        matids += temp[i] + "~";
      }

      matids += temp[temp.length - 1];
      log("matids:" + matids);
      con.setString(1, matids);
      SysRecord res = con.csCommonSP("P_Agt_MaterDelete").getParamSet();

      req.setAttribute("searchSQL", form.getSearchSQL());
      //System.out.println("dele ok");
      //判断是否删除成功
      if (res.getInt(0) != 0) {
        req.setAttribute("errorId", ErrorCode.MERT_DEL);
        return servlet.findForward("error");
      }
      //提示不能删除的记录
      //System.out.println("res.getString(1)" + res.getString(1));
      if (res.getString(1) != null) {
        req.setAttribute("message", res.getString(1));
        return mapping.findForward("message");
      }
    }
    catch (SysDbException e) {
      e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.COMMONSERVICE_ERROR);
      return servlet.findForward("error");
    }
    catch (java.sql.SQLException e) {
      e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.DATABASE_ERROR);
      return servlet.findForward("error");
    }
    finally {
      con.close();
    }
    //成功页面提示成功信息后,自动重新查询
    if (req.getParameter("classIdTerm") == null ||
        "".equalsIgnoreCase(req.getParameter("classIdTerm")) ||
        "null".equalsIgnoreCase(req.getParameter("classIdTerm"))) {
      return search(mapping,form,req);
    }
    else {
      return typelist(mapping, form, req);
    }
  }

  /**
   * 实现修改保存功能
   * @param mapping
   * @param form
   * @param req
   * @return
   */
  private ActionForward save(ActionMapping mapping,
                             MertMngOperatorForm form,
                             HttpServletRequest req)
  {
    log("save now ....");
    SysConnPool cspool = null;
    SysDbConn con = null;
    try
    {
      cspool = SysConnPool.getInstance();
      con = cspool.getAplComs();
      log(form.getSearchSQL());
      con.preparedSP();
      con.setString(1, form.getMatid()[0]);
      con.setString(2, form.getTitle());
      con.setString(3, form.getKeyWord());
      con.setString(4, form.getAbstracts());
      con.setString(5, form.getClassType());
      con.setString(6, form.getFileName());
      con.setString(7, form.getClassId());
      con.setString(8, form.getAuthInfo());
      con.setString(9, form.getStaffNoInfo());

      SysRecord res = con.csCommonSP("P_Agt_MaterUpdate").getParamSet();
      if (res.getInt(0) != 0)
      {
        req.setAttribute("errorId", ErrorCode.MERT_MOD);
        return servlet.findForward("error");
      }
      //传递查询条件
      req.setAttribute("searchSQL", form.getSearchSQL());
    }
    catch (SysDbException e)
    {
      e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.COMMONSERVICE_ERROR);
      return servlet.findForward("error");
    }
    catch (java.sql.SQLException e)
    {
      e.printStackTrace();
      req.setAttribute("errorId", ErrorCode.DATABASE_ERROR);
      return servlet.findForward("error");
    }
    finally
    {
      con.close();
    }

    //成功页面提示成功信息后,自动重新查询
    if (req.getParameter("classIdTerm").equals("") ||
        req.getParameter("classIdTerm").equals("null"))
    {
      req.setAttribute("successId", SuccessCode.MERTMNG_SAVE);
      return mapping.findForward("success");
    }
    else
    {
      return typelist(mapping, form, req);
    }
  }

    ///:huangyuyuan add 2004-06-15
    /**
     * 选择不同页面的资料
     * @param operatorFlag 用来判断这是提交动作还是选择动作
     */
    private ActionForward mertSelected(ActionMapping mapping,
                             MertMngOperatorForm form,
                             HttpServletRequest req,HttpServletResponse res,String operatorFlag)
    {
        try
        {
            HttpSession session = req.getSession();
            //matMap用来保存选择的数据
            HashMap matMap = (HashMap)session.getAttribute("matMap");

            //matids和matnames保存的是当前页面选择的数据
            String matids = req.getParameter("matids");
            String matnames = req.getParameter("matnames");
            //获得当前页的页数
            String pageNumStr = req.getParameter("curPageNum");
            //获得最大页的页数
            String maxPageNumStr = req.getParameter("maxPageNum");
            int pageNum = 1;
            int maxPageNum = 1;
            if((null != pageNumStr) && (null != maxPageNumStr))
            {
                pageNum = Integer.parseInt(pageNumStr);
                maxPageNum = Integer.parseInt(maxPageNumStr);
                if(pageNum < maxPageNum)
                {
                    pageNum++;
                }
            }

            StringTokenizer matidsTokenizer = new StringTokenizer(matids,"~");
            StringTokenizer matnamesTokenizer = new StringTokenizer(matnames,",");

            if (null == matMap)
            {
                matMap = new HashMap();
            }

            while((matidsTokenizer.hasMoreTokens()) && (matnamesTokenizer.hasMoreTokens()))
            {
                matMap.put(matidsTokenizer.nextToken(),matnamesTokenizer.nextToken());
            }

            session.setAttribute("matMap",matMap);

            //判断是否已经提交
            if(operatorFlag.equals(OperatorFlagCode.MERT_SELECTED_SUBMIT))
            {
                //forward到另一个页面
                req.getRequestDispatcher("/agt/lessonmng/SelectMert.jsp?selectDone=1&pageNum=" + pageNum).forward(req,res);
            }
            else
            {
                //forward到另一个页面
                req.getRequestDispatcher("/agt/lessonmng/SelectMert.jsp?selectDone=0&pageNum=" + pageNum).forward(req,res);
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
            req.setAttribute("errorId", ErrorCode.UNKNOW_ERROR);
            return servlet.findForward("error");
        }

        return null;
    }
    ///:~

  /**
   *
   * @param mes
   */
  private void log(String mes)
  {
    //System.out.println(mes);
  }
}

⌨️ 快捷键说明

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