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

📄 storehousemanageraction.java

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

import org.apache.struts.action.*;
import java.io.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.sql.SQLException;

import com.bean.*;
import com.bean.*;
import com.dao.*;
import com.tool.pagetool.*;
import com.tool.QueryStrCreator;
import com.tool.LogTableWriter;

public class StorehouseManagerAction extends Action {
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) throws Exception {
        request.setCharacterEncoding("gb2312");
        response.setContentType("text/html;charset=gb2312");

        StorehouseManager storehouseManager = (StorehouseManager) form;
        String flag = request.getParameter("flag");
        ActionErrors actionErrors = new ActionErrors();
        String target = "";

        //添加仓管
        if (flag.equals("forA")) {
            try {
                StorehouseManagerDAO.startTransation();
                int lastId = 0;
                if (storehouseManager.getCompFlag() == 0) { //添加自有仓管员
                    lastId = StorehouseManagerDAO.getLastId();
                    //从公司用户表中获取真实姓名和姓别
                    CompUser compUser = CompUserDAO.selectCompUserBycompUserId(
                            storehouseManager.getCompUserId());
                    storehouseManager.setRealName(compUser.getRealName());
                    storehouseManager.setSex(compUser.getSex());
                    storehouseManager.setShmId(lastId + 1);
                    storehouseManager.setDelFlag(0);
                }
                if (storehouseManager.getCompFlag() == 1) { //添加第三方仓管员
                    lastId = OutShManagerDAO.getLastId();
                    storehouseManager.setOutShMagerId(lastId + 1);
                    lastId = StorehouseManagerDAO.getLastId();
                    storehouseManager.setShmId(lastId + 1);
                    storehouseManager.setShmId(lastId + 1);
                    storehouseManager.setDelFlag(0);
                    OutShManagerDAO.insertOutShManager(storehouseManager);
                }
                StorehouseManagerDAO.insertStorehouseManager(
                        storehouseManager);
                StorehouseManagerDAO.commit();
                ActionError actionError = new ActionError(
                        "errors.addSuccese");
                actionErrors.add("addClientSuccese", actionError);
                saveErrors(request, actionErrors);
                target = "addSHManager";
                //写入日志
                String operatorType = "增";
                String sql = "insert into STOREHOUSE_MANAGER " +
                             "(shm_id,comp_flag,del_flag,comp_user_id,out_sh_mager_id,real_name,sex) " +
                             "values (" + storehouseManager.getShmId() + "," +
                             storehouseManager.getCompFlag()
                             + "," + storehouseManager.getDelFlag() + "," +
                             storehouseManager.getCompUserId() + "," +
                             storehouseManager.getOutShMagerId() + "," +
                             storehouseManager.getRealName() + "," +
                             storehouseManager.getSex() + ")";
                LogTableWriter.write(request, operatorType, sql);
                if (storehouseManager.getCompFlag() == 1) { //如果是添加第三方仓管员
                    sql = "insert into OUT_SH_MANAGER "
                          + "(out_sh_mager_id,real_name,sex,tel,fax,email) " +
                          "values (" + storehouseManager.getOutShMagerId() +
                          "," +
                          storehouseManager.getRealName() + "," +
                          storehouseManager.getSex() + "," +
                          storehouseManager.getTel()
                          + "," + storehouseManager.getFax() + "," +
                          storehouseManager.getEmail() + ")";
                    LogTableWriter.write(request, operatorType, sql);
                }
            } catch (SQLException e) {
                e.printStackTrace();
                ActionError actionError = new ActionError("errors.addFailed");
                actionErrors.add("addClientFeiled", actionError);
                saveErrors(request, actionErrors);
                target = "addSHManager";
            } finally {
                StorehouseManagerDAO.rollback();
            }
        }

        //列表
        else if (flag.equals("forList")) {
            initPage(request);
            target = "editSHManager";
        }

        //删除
         else if (flag.equals("delete")) {
            String radioValue = request.getParameter("radioValue");
            if(radioValue==null||radioValue.length()<5) return mapping.findForward("editSHManager");
            String managerId = radioValue.substring(0, radioValue.indexOf("|"));
            String compFlag = radioValue.substring(radioValue.lastIndexOf("|") +
                    1,radioValue.lastIndexOf("and"));
            String shmId = radioValue.substring(radioValue.lastIndexOf("and")+4,radioValue.length());
            int managerIdI=-1;
            int compFlagI=-1;
            int shmIdI = -1;

            try{
                managerIdI = Integer.parseInt(managerId);
                compFlagI = Integer.parseInt(compFlag);
                shmIdI = Integer.parseInt(shmId);
            }catch(Exception e){
                e.printStackTrace();
            }
            try{
                StorehouseManagerDAO.startTransation();
                if (compFlagI == 0 && shmIdI > 0) {//删除自有仓管员
                    storehouseManager.setCompFlag(compFlagI);
                    storehouseManager.setCompUserId(managerIdI);
                    storehouseManager.setDelFlag(1);
                    storehouseManager.setShmId(shmIdI);
                    StorehouseManagerDAO.updateStorehouseManagerDelFlag(
                            storehouseManager);
                } else if (compFlagI == 1 && managerIdI > 0 && shmIdI>0) {//删除第三方仓管员
                    storehouseManager.setCompFlag(compFlagI);
                    storehouseManager.setOutShMagerId(managerIdI);
                    storehouseManager.setDelFlag(1);
                    storehouseManager.setShmId(shmIdI);
                    StorehouseManagerDAO.updateStorehouseManagerDelFlag(
                            storehouseManager);
                    OutShManagerDAO.updateOutShManagerDelFlag(storehouseManager);
                }
                StorehouseManagerDAO.commit();

                //写入日志
                 if (compFlagI == 0 && shmIdI > 0) {
                     String operatorType = "删";
                     String sql = "update STOREHOUSE_MANAGER set DEL_FLAG="+storehouseManager.getDelFlag()
                             +" where SHM_ID = "+storehouseManager.getShmId();
                     LogTableWriter.write(request, operatorType, sql);

                 }else if (compFlagI == 1 && managerIdI > 0 && shmIdI>0){
                     String operatorType = "删";
                     String sql = "update STOREHOUSE_MANAGER set DEL_FLAG="+storehouseManager.getDelFlag()
                             +" where SHM_ID = "+storehouseManager.getShmId();
                     LogTableWriter.write(request, operatorType, sql);
                     sql = "update OUT_SH_MANAGER set DEL_FLAG="+storehouseManager.getDelFlag()
                           +" where OUT_SH_MAGER_ID = "+storehouseManager.getOutShMagerId();
                     LogTableWriter.write(request, operatorType, sql);
                 }

            }catch(SQLException e){
                e.printStackTrace();
            }finally{
                StorehouseManagerDAO.rollback();
            }
            target = "editSHManager";
        }

        //跳到修改页面
        else  if (flag.equals("forModify")) {
            String radioValue = request.getParameter("radioValue");
            if(radioValue==null||radioValue.length()<5) return mapping.findForward("editSHManager");
            String managerId = radioValue.substring(0, radioValue.indexOf("|"));//自有仓管员或第三方仓管员ID
            String compFlag = radioValue.substring(radioValue.lastIndexOf("|") +
                    1,radioValue.lastIndexOf("and"));//仓库类型标识
            String shmId = radioValue.substring(radioValue.lastIndexOf("and")+4,radioValue.length());//统一仓库管理员Id
            int managerIdI=-1;
            int compFlagI=-1;

⌨️ 快捷键说明

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