?? inputapplyaction.java
字號:
package com.action;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.Date;
import java.text.SimpleDateFormat;
import com.bean.InputApply;
import com.dao.*;
import com.tool.QueryStrCreator;
import com.tool.LogTableWriter;
import com.tool.pagetool.PageTool;
import com.tool.pagetool.Page;
import com.tool.pagetool.PageToolBuilder;
/**
* <p>Title: 入庫申報(bào)</p>
*
* <p>Description: 添加入庫申報(bào)、撤消入庫申報(bào)</p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class InputApplyAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
InputApply inputApply = (InputApply) form;
String flag = request.getParameter("flag");
ActionErrors actionErrors = new ActionErrors();
String target = "";
//入庫申報(bào)
if (flag.equals("forA")) {
try {
InputApplyDAO.startTransation();
int lastId = InputApplyDAO.getLastId();
inputApply.setInApId(lastId + 1);
inputApply.setDelFlag(0);
String sysDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); //獲得系統(tǒng)當(dāng)前時(shí)間
inputApply.setApplyDate(sysDate);
InputApplyDAO.insertInputApply(inputApply);
InputApplyDAO.commit();
request.setAttribute("inputAppForM", inputApply);
ActionError actionError = new ActionError(
"errors.addSuccese");
actionErrors.add("addInputApplySuccese", actionError);
saveErrors(request, actionErrors);
target = "addInputApply";
//寫入日志
String operatorType = "增";
String sql = "insert into INPUT_APPLY (in_ap_id," +
"client_id,sh_id,product_id,apply_date,apply_peop," +
"tel,handset,email,stock_request,insurance_flag,"+
"insurance_count,insurance_perod,app_in_date,"+
"input_amount,input_weight,used_area)"+
" values (" + inputApply.getInApId() + "," +
inputApply.getClientId()+","+inputApply.getShId()
+","+inputApply.getProductId()+","+inputApply.getApplyDate()
+","+inputApply.getApplyPeop()+","+inputApply.getTel()+","+inputApply.getHandset()
+","+inputApply.getEmail()+","+inputApply.getStockRequest()
+","+inputApply.getInsuranceFlag()+","+inputApply.getInputAmount()
+","+inputApply.getInsurancePerod()+","+inputApply.getAppInDate()
+","+inputApply.getInputAmount()+","+inputApply.getInputWeight()
+","+inputApply.getUsedArea()+")";
LogTableWriter.write(request, operatorType, sql);
} catch (SQLException e) {
e.printStackTrace();
ActionError actionError = new ActionError("errors.generally.failed",e.getMessage());
actionErrors.add("addInputApplyFeiled", actionError);
saveErrors(request, actionErrors);
target = "addInputApplyFeiled";
} finally {
InputApplyDAO.rollback();
}
}
//刪除入庫申請,只作標(biāo)記不物理刪除
if (flag.equals("delete")) {
String inApIdStr = request.getParameter("inApId");
int inApId = -1;
if (inApIdStr != null) {
try {
inApId = Integer.parseInt(inApIdStr);
InputApplyForeignkeyViewDAO.startTransation();
InputApplyForeignkeyViewDAO.updateInputApplySetDelFlagYes(inApId);
InputApplyForeignkeyViewDAO.commit();
ActionError actionError = new ActionError(
"errors.cancleInputApplySuccese");
actionErrors.add("CancleInputApplySuccese", actionError);
saveErrors(request, actionErrors);
target = "listForMInputApp";
//寫入日志
String operatorType = "刪";
String sql = "update INPUT_APPLY set " +
"DEL_FLAG=1 where IN_AP_ID = " +
inApId;
LogTableWriter.write(request, operatorType, sql);
} catch (Exception e) {
e.printStackTrace();
ActionError actionError = new ActionError(
"errors.deleteFeiled");
actionErrors.add("cancleInputApplyFeiled", actionError);
saveErrors(request, actionErrors);
target = "listForMInputApp";
} finally {
InputApplyForeignkeyViewDAO.rollback();
}
}
}
//激活入庫申請,將標(biāo)記改為1
if (flag.equals("deleteActDo")) {
String inApIdStr = request.getParameter("inApId");
int inApId = -1;
if (inApIdStr != null) {
try {
inApId = Integer.parseInt(inApIdStr);
InputApplyForeignkeyViewDAO.startTransation();
InputApplyForeignkeyViewDAO.updateInputApplySetDelFlagNo(inApId);
InputApplyForeignkeyViewDAO.commit();
ActionError actionError = new ActionError(
"errors.activeInputApplySuccese");
actionErrors.add("ActiveInputApplySuccese", actionError);
saveErrors(request, actionErrors);
target = "activeCancledInputApp";
//寫入日志
String operatorType = "激活";
String sql = "update INPUT_APPLY set " +
"DEL_FLAG=0 where IN_AP_ID = " +
inApId;
LogTableWriter.write(request, operatorType, sql);
} catch (Exception e) {
e.printStackTrace();
ActionError actionError = new ActionError(
"errors.activeInputApplyFeiled");
actionErrors.add("activeInputApplyFeiled", actionError);
saveErrors(request, actionErrors);
target = "listForMInputApp";
} finally {
InputApplyForeignkeyViewDAO.rollback();
}
}
}
//修改入庫申報(bào)(select具體要修改的)
if(flag.equals("doEdit")){
String inApIdStr = request.getParameter("inApId");
String forNotify = (request.getParameter("forNotify")==null?"":request.getParameter("forNotify"));
int inApId = -1;
if (inApIdStr != null) {
try {
inApId = Integer.parseInt(inApIdStr);
InputApply inputApp=InputApplyDAO.selectInputApplyByinApId(inApId);
request.setAttribute("inputAppForM", inputApp);
} catch (Exception e) {
e.printStackTrace();
ActionError actionError = new ActionError(
"errors.diplayInputApplyFeiled");
actionErrors.add("diplayInputApplyFeiled", actionError);
saveErrors(request, actionErrors);
target = "listForMInputApp";
} finally {
InputApplyForeignkeyViewDAO.rollback();
}
}
if(forNotify.equalsIgnoreCase("yes")){
target = "forNotify";
}else target = "inputAppForM";
}
//入庫申報(bào)修改
if (flag.equals("inDoEdit")) {
try {
String sysDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); //獲得系統(tǒng)當(dāng)前時(shí)間
inputApply.setApplyDate(sysDate);
InputApplyDAO.startTransation();
InputApplyDAO.updateInputApply(inputApply);
InputApplyDAO.commit();
request.setAttribute("inputAppForM", inputApply);
ActionError actionError = new ActionError(
"errors.editSuccese");
actionErrors.add("editInputApplySuccese", actionError);
saveErrors(request, actionErrors);
target = "editSuccessed";
//寫入日志
String operatorType = "改";
String sql = "update INPUT_APPLY set client_id="+inputApply.getClientId()+",sh_id="+inputApply.getShId()+
",,product_id="+inputApply.getProductId()+",apply_date="+inputApply.getApplyDate()+",apply_peop="+
inputApply.getApplyPeop()+",tel="+inputApply.getTel()+",handset="+inputApply.getHandset()+
",email="+inputApply.getEmail()+",stock_request="+inputApply.getStockRequest()+",insurance_flag="+
inputApply.getInsuranceFlag()+",insurance_count="+inputApply.getInputAmount()+",insurance_perod"+
inputApply.getInsurancePerod()+",app_in_date="+inputApply.getAppInDate()+",input_amount="+
inputApply.getInputAmount()+",input_weight"+inputApply.getInputWeight()+",used_area="+inputApply.getUsedArea();
LogTableWriter.write(request, operatorType, sql);
} catch (SQLException e) {
e.printStackTrace();
ActionError actionError = new ActionError("errors.editFailed",e.getMessage());
actionErrors.add("addInputApplyFeiled", actionError);
saveErrors(request, actionErrors);
request.setAttribute("inputAppForM", inputApply);
target = "inputAppForM";
} finally {
InputApplyDAO.rollback();
}
}
//選擇分頁及跳轉(zhuǎn)
if ((!flag.equals("forA")) && (!flag.equals("inDoEdit")) && (!flag.equals("doEdit"))) {
if (flag.equals("forActive")||flag.equals("deleteActDo")){
initPage(request,true); //初始化分頁數(shù)據(jù)并放于request中
target = "activeCancledInputApp"; //重定向到入庫申報(bào)激活頁面
}else if (flag.equals("forM")) {
initPage(request,false); //初始化分頁數(shù)據(jù)并放于request中
target = "listForMInputApp"; //重定向到入庫申報(bào)撤消頁面
}else if(flag.equals("forEdit")){
initPage(request,false); //初始化分頁數(shù)據(jù)并放于request中
target = "listForMInputApp"; //重定向到入庫申報(bào)撤消頁面
}else if(flag.equals("forNotify")){
initPage(request,false); //初始化分頁數(shù)據(jù)并放于request中
target = "listForCreateNotify"; //重定向到產(chǎn)生入庫通知頁面
}else if(flag.equals("forCreateInReg")){
initPage(request,false);
target="listForCreateInReg";
}else {
initPage(request,false);
} //初始化分頁數(shù)據(jù)并放于request中
}
return mapping.findForward(target);
}
//初始化并獲得分頁
private Page initPage(HttpServletRequest request,boolean isActive) {
String currentPageStr = request.getParameter("currentPage");
String queryStr = QueryStrCreator.create("inputApply", request);
int currentPage = 1; //當(dāng)前頁碼
int size = 20; //每頁的記數(shù)
try { //防止從地址欄直接輸入非法頁碼
if (currentPageStr != null) currentPage = new Integer(
currentPageStr).intValue();
} catch (Exception e) {
e.printStackTrace();
}
//處理分頁
//會話中是否已有分頁生成工具
PageTool pageTool = null;
HttpSession session = request.getSession();
if(!isActive){
pageTool = (PageTool) session.getAttribute("inputApplyPageTool"); //有,則直接拿來用
if (pageTool == null) { //沒有,則新建,并放進(jìn)會話中,以備下次用
pageTool = PageToolBuilder.builder(new
InputApplyForeignkeyViewDAO(isActive));
session.setAttribute("inputApplyPageTool", pageTool);
}
}else{
pageTool = (PageTool) session.getAttribute("inputApplyPageToolForAct"); //有,則直接拿來用
if (pageTool == null) { //沒有,則新建,并放進(jìn)會話中,以備下次用
pageTool = PageToolBuilder.builder(new
InputApplyForeignkeyViewDAO(isActive));
session.setAttribute("inputApplyPageToolForAct", pageTool);
}
}
//由分頁工具生成分頁
Page page = null;
try {
String flag = request.getParameter("flag");
if (flag.equals("query") || flag.equals("forCreateInReg") || flag.equals("forM") || flag.equals("forEdit") || flag.equals("forNotify")) //查詢時(shí)的分頁
page = pageTool.createPage(currentPage, size, queryStr);
else //其它非查詢的分頁
page = pageTool.createPage(currentPage, size);
} catch (SQLException ex) {
ex.printStackTrace();
}
//將分頁放進(jìn)請求中,分發(fā)到下一個(gè)頁面顯示
if(!isActive) request.setAttribute("allInputApplyPage", page);
else request.setAttribute("allInputApplyPageForAct", page);
return page;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -