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

📄 storehousemanageraction.java

📁 hibernate应用测试,初学hibernate 的会员可以看看.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            int shmIdI = -1;

            try{
                managerIdI = Integer.parseInt(managerId);
                compFlagI = Integer.parseInt(compFlag);
                shmIdI = Integer.parseInt(shmId);
            }catch(Exception e){
                e.printStackTrace();
            }
//            System.out.println("managerIdI="+managerIdI);
//             System.out.println("compFlagI="+compFlagI);
            if(compFlagI==0&&managerIdI>0){//当为自有仓管时

               target="gotoMUserStr";
               request.setAttribute("gotoMUserStr",request.getContextPath()+"/compuser/compUserAction.do?flag=modify&compUserId="+managerIdI);
           }else if(compFlagI==1&&managerIdI>0){//当为第三方仓管时
              StorehouseManagerOutView outView= StorehouseManagerOutViewDAO.selectStorehouseManagerOutViewByshmId(managerIdI);

              request.setAttribute("outView",outView);
              target="modifySHManager";
            }
        }
        //修改
        else if(flag.equals("modify")){
            try{
                OutShManagerDAO.startTransation();
                storehouseManager.setCompFlag(1);
                //判断仓管员类型.true表示自有仓管员;false表示第三方仓管员
                boolean managerType = com.tool.StorehouseTool.getSHManagerType(storehouseManager.getShmId());
                if(!managerType){
                    StorehouseManagerDAO.updateStorehouseManager(storehouseManager);
                    OutShManagerDAO.updateOutShManager(storehouseManager);
                }
                OutShManagerDAO.commit();
                ActionError actionError = new ActionError(
                       "errors.addSuccese");
               actionErrors.add("", actionError);
               saveErrors(request, actionErrors);

            }catch(Exception e){
                e.printStackTrace();
                ActionError actionError = new ActionError(
                           "errors.generally.failed",e.getMessage());
                   actionErrors.add("", actionError);
                   saveErrors(request, actionErrors);
            }finally{
                StorehouseManagerDAO.rollback();
                //最后继续跳转到修改页面
                StorehouseManagerOutView outView= StorehouseManagerOutViewDAO.selectStorehouseManagerOutViewByshmId(storehouseManager.getOutShMagerId());
                request.setAttribute("outView",outView);
                target="modifySHManager";
                System.out.println("in modify manqager");
                System.out.println("storehouseManager.getShmId()="+storehouseManager.getShmId());
            }
        }
        //查看详细
        //radioValue参数的组成:“自有仓管员ID(或第三方仓管员ID)||||仓管类型标识and仓库ID”
        //仓管类型标识的值为:1或0。1 表示自有仓库,0表示第三方仓库
       else  if (flag.equals("detail")) {
            String radioValue = request.getParameter("radioValue");
            String managerId = radioValue.substring(0, radioValue.indexOf("|"));
            String compFlag = radioValue.substring(radioValue.lastIndexOf("|") +
                    1);

        }
        //跳转到分配仓库窗体
        else if (flag.equals("giveSH")) {
//            System.out.println("in asdfasdfasdasd2----");
            String radioValue = request.getParameter("radioValue");
             if(radioValue==null||radioValue.length()<5) return mapping.findForward("editSHManager");
            String shmId = radioValue.substring(radioValue.lastIndexOf("d")+1,radioValue.length());//统一仓库管理员Id
//            System.out.println("shmId="+shmId);
//            System.out.println("radioValue="+radioValue);
            request.setAttribute("realName",StorehouseShmanagerViewDAO.selectStorehouseShmanagerViewByshmId(new Integer(shmId.trim()).intValue()).getRealName());
            request.setAttribute("managerId",shmId);
            StorehouseAction storehouseAction = new StorehouseAction();
            storehouseAction.initPage(request);
            target="listSHForManager";
        }

        //执行分配仓库
        else  if(flag.equals("forManager")){
            try{
                String shIdStr = (String)request.getParameter("shId");
                String managerIdStr = (String)request.getParameter("managerId");
                int shId = new Integer(shIdStr.trim()).intValue();
                int managerId = new Integer(managerIdStr.trim()).intValue();
                StorehouseShmanagerDAO.startTransation();
                int shmanagerId = StorehouseShmanagerDAO.getLastId();
                StorehouseShmanager storehouseShmanager = new StorehouseShmanager();
                storehouseShmanager.setDelFlag(0);
                storehouseShmanager.setSelfId(shmanagerId+1);
                storehouseShmanager.setShId(shId);
                storehouseShmanager.setShmId(managerId);
                //判断当前仓管员能否添加到当前仓库
                boolean tmp = com.tool.StorehouseTool.isShMCanAddToSh(managerId,
                        shId);
                request.setAttribute("realName",StorehouseShmanagerViewDAO.selectStorehouseShmanagerViewByshmId(managerId).getRealName());
                request.setAttribute("managerId",managerIdStr);

                if (!tmp) {
                    ActionError actionError = new ActionError(
                            "errors.generally.failed","仓管员类型与仓库类型不匹配!");
                    actionErrors.add("", actionError);
                    saveErrors(request, actionErrors);
                    StorehouseAction storehouseAction = new StorehouseAction();
                    storehouseAction.initPage(request);
                    return mapping.findForward("listSHForManager");
                }
                StorehouseShmanagerDAO.insertStorehouseShmanager(
                        storehouseShmanager);
                StorehouseShmanagerDAO.commit();

                ActionError actionError = new ActionError(
                        "errors.addSuccese");
                actionErrors.add("", actionError);
                saveErrors(request, actionErrors);
            }catch(Exception e){
                e.printStackTrace();
            }finally{
                StorehouseShmanagerDAO.rollback();
                StorehouseAction storehouseAction = new StorehouseAction();
                storehouseAction.initPage(request);
                target="listSHForManager";
            }
        }
        else if(flag.equals("queryForImport")){
            initPage(request);
            target="importShM";
        }

        return mapping.findForward(target);
    }

    //初始化并获得分页
    private Page initPage(HttpServletRequest request) {
        String currentPageStr = request.getParameter("currentPage");
        String queryStr = QueryStrCreator.create("Shmanager", request);
//        System.out.println("#"+queryStr);
        int currentPage = 1; //当前页码
        int size = 20; //每页的记录数

        try { //防止从地址栏直接输入非法页码
            if (currentPageStr != null) currentPage = new Integer(
                    currentPageStr).intValue();
        } catch (Exception e) {
            e.printStackTrace();
        }

        //处理分页
        //会话中是否已有分页生成工具
        PageTool pageTool = null;
        HttpSession session = request.getSession();
        pageTool = (PageTool) session.getAttribute("shManagerPageTool"); //有,则直接拿来用
        if (pageTool == null) { //没有,则新建,并放进会话中,以备下次用
            pageTool = PageToolBuilder.builder(new StorehouseShmanagerViewDAO());
            session.setAttribute("shManagerPageTool", pageTool);
        }
        //由分页工具生成分页
        Page page = null;
        try {
            String flag = request.getParameter("flag");
            if (flag.equals("query")||flag.equals("queryForImport")) //查询时的分页
                page = pageTool.createPage(currentPage, size, queryStr);
            else //其它非查询的分页
                page = pageTool.createPage(currentPage, size);
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
        //将分页放进请求中,分发到下一个页面显示
        request.setAttribute("allshManagerPage", page);
        return page;
    }


}

⌨️ 快捷键说明

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