?? inputshformaction.java
字號:
package com.action;
import org.apache.struts.action.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.SQLException;
import com.tool.pagetool.Page;
import javax.servlet.http.HttpSession;
import com.tool.QueryStrCreator;
import com.tool.pagetool.PageTool;
import com.tool.pagetool.PageToolBuilder;
import com.bean.InputShForm;
import com.dao.InputShFormDAO;
import java.util.Date;
import java.text.SimpleDateFormat;
import com.dao.InputRegisterDAO;
/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class InputShFormAction extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception {
request.setCharacterEncoding("gb2312");
response.setContentType("text/html;charset=gb2312");
InputShForm inputShForm = (InputShForm) form;
String flag = request.getParameter("flag");
ActionErrors actionErrors = new ActionErrors();
String target = null;
if(flag.equals("doAudit")){ //產生入庫審核
int inRegId=(request.getParameter("inRegId")==null?-1:Integer.parseInt(request.getParameter("inRegId").toString()));
if(inRegId!=-1){
InputShForm isExist=InputShFormDAO.selectInputShFormByInputAppId(inRegId);
try{
if(isExist!=null){
isExist.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
isExist.setDelFlag(0);
isExist.setPrintFlag(0);
InputShFormDAO.startTransation();
InputShFormDAO.updateInputShForm(isExist);
InputShFormDAO.updateInputRegStateTo1(inRegId); //將入庫登記狀態置為:1
InputShFormDAO.commit();
}else{
InputShForm newinputSHForm=new InputShForm();
InputShFormDAO.startTransation();
int maxID=InputShFormDAO.getLastId();
newinputSHForm.setInputShFormId(maxID+1);
newinputSHForm.setInRegiId(inRegId);
newinputSHForm.setCreateDate(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
newinputSHForm.setPrintFlag(0);
newinputSHForm.setDelFlag(0);
InputShFormDAO.insertInputShForm(newinputSHForm);
InputShFormDAO.updateInputRegFirstAudTo1(inRegId); //將第一次審核標示置為:1
InputShFormDAO.updateInputRegStateTo1(inRegId); //將入庫登記狀態置為:1
InputShFormDAO.commit();
}
ActionError actionError = new ActionError("errors.auditSuccess");
actionErrors.add("auditSuccess", actionError);
saveErrors(request, actionErrors);
target="doActiveInputAudit";
initPage(request,"forInputShForm");
request.setAttribute("forInputShForm",new String("forInputShForm"));
}catch(Exception e){
e.printStackTrace();
ActionError actionError = new ActionError("errors.generally.failed", e.getMessage());
actionErrors.add("auditFeiled",actionError);
saveErrors(request, actionErrors);
InputShFormDAO.rollback();
}
}
}else if(flag.equals("doDel")){
int inShFormId=(request.getParameter("inShFormId")==null?-1:Integer.parseInt(request.getParameter("inShFormId").toString()));
if(inShFormId!=-1){
try{
InputShFormDAO.delInputShFormById(inShFormId);
ActionError actionError = new ActionError("errors.deleteSuccese");
actionErrors.add("auditDeleteSuccess", actionError);
saveErrors(request, actionErrors);
initPage(request,"allActive");
target="allActiveInputAudit";
}catch(Exception e){
e.printStackTrace();
ActionError actionError = new ActionError("errors.generally.failed", e.getMessage());
actionErrors.add("auditDeleteFeiled",actionError);
saveErrors(request, actionErrors);
}
}
}else if(flag.equals("allActive")){ //產生入庫審核
initPage(request,flag);
target="allActiveInputAudit";
}
return mapping.findForward(target);
}
//初始化并獲得分頁
private Page initPage(HttpServletRequest request,String flag) {
String currentPageStr = request.getParameter("currentPage");
String queryStr = null;
if(flag.equals("allActive")){
queryStr = QueryStrCreator.create("listInputAuditActive", request);
}else if(flag.equals("listCancledInReg")){
queryStr = QueryStrCreator.create("listInputAuditActive", request);
}else if(flag.equals("forInputShForm")){
queryStr = QueryStrCreator.create("listAllInReg", request);
}
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();
if(flag.equals("forInputShForm")){
pageTool = (PageTool) session.getAttribute("inputRegisterPageTool"); //有,則直接拿來用
if (pageTool == null) { //沒有,則新建,并放進會話中,以備下次用
pageTool = PageToolBuilder.builder(new InputRegisterDAO());
session.setAttribute("inputRegisterPageTool", pageTool);
}
}else{
pageTool = (PageTool) session.getAttribute("inputAuditPageTool"); //有,則直接拿來用
if (pageTool == null) { //沒有,則新建,并放進會話中,以備下次用
pageTool = PageToolBuilder.builder(new InputShFormDAO());
session.setAttribute("inputAuditPageTool", pageTool);
}
}
//由分頁工具生成分頁
Page page = null;
try {
if (flag.equals("allActive") || flag.equals("forInputShForm")){ //查詢時的分頁,是否需要查詢條件
page = pageTool.createPage(currentPage, size, queryStr);
}else{//其它非查詢的分頁
page = pageTool.createPage(currentPage, size);
}
} catch (SQLException ex) {
ex.printStackTrace();
}
//將分頁放進請求中,分發到下一個頁面顯示
if(flag.equals("forInputShForm")){
request.setAttribute("allInputRegisterPage", page);
}else if(flag.equals("allActive")){
request.setAttribute("allActieInputAuditPage", page);
}else request.setAttribute("allActieInputAuditPage", page);
return page;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -