?? storehousemanageraction.java
字號:
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 + -