?? orderaction.java
字號:
package com.cargo.crotrol;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import com.cargo.filter.Line;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cargo.db.Orderdb;
import java.util.Collection;
import org.apache.struts.action.ActionErrors;
import com.cargo.db.Keywords;
import com.cargo.db.Html;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: MR</p>
* @author BWM
* @version 1.0
*/
public class OrderAction extends Action implements Keywords {
private Line online = new Line();
private ActionForward forward = new ActionForward();
private Orderdb db = new Orderdb();
private int t = 0;
private Collection coll;
private ActionErrors errors = new ActionErrors();
private Html html=new Html();
public ActionForward perform(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
OrderForm orderForm = (OrderForm) actionForm;
String action = actionMapping.getParameter();
forward = online.down("id", actionMapping, httpServletRequest,
"errors");
if (forward != null && forward.getName().equals("errors")) {
return forward;
}
if ("".equalsIgnoreCase(action)) {
forward = actionMapping.findForward("errors");
} else {
if ("send".equalsIgnoreCase(action)) {
forward = Add(actionMapping, orderForm, httpServletRequest,
httpServletResponse);
} else if ("view".equalsIgnoreCase(action)) {
forward = View(actionMapping, orderForm, httpServletRequest,
httpServletResponse);
} else if ("manadel".equalsIgnoreCase(action)) {
forward = Del(actionMapping, orderForm, httpServletRequest,
httpServletResponse);
} else if ("list".equalsIgnoreCase(action)) {
forward = List(actionMapping, actionForm, httpServletRequest,
httpServletResponse);
} else {
forward = actionMapping.findForward("errors");
}
}
return forward;
}
private ActionForward Add(ActionMapping mapping, OrderForm orderForm,
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession();
orderForm.getOrder().setId();
orderForm.getOrder().setUserid(online.getUserId());
orderForm.getOrder().setTime();
Collection coll = (Collection) session.getAttribute("car");
if (coll == null || coll.isEmpty()) {
errors.clear();
errors.add("insertfail", new ActionError("error.data.null"));
return (new ActionForward(mapping.getInput()));
} else {
t = db.Change(orderForm.getOrder(), coll);
errors.clear();
if (t <=-2) {
errors.add(Action.ERROR_KEY, new ActionError("error.order.user"));
}else if(t==-1){
errors.add(Action.ERROR_KEY, new ActionError("error.order.eorder"));
}else if(t==1){
errors.add(Action.ERROR_KEY, new ActionError("error.order.border"));
}else if(t==2){
errors.add(Action.ERROR_KEY, new ActionError("error.order.send"));
}
if(!errors.empty()){
saveErrors(request, errors);
session.removeAttribute("car");
return mapping.findForward("errors");
}
session.removeAttribute("car");
request.getAttribute("car");
request.setAttribute("info", "true");
return mapping.findForward("success");
}
}
private ActionForward Del(ActionMapping mapping, OrderForm orderForm,
HttpServletRequest request,
HttpServletResponse response) {
String id = request.getParameter("orderdel").toString();
t = db.delete(DELETE + "tb_order" + WHERE + "id='" + id + "'");
if (t <= 0) {
errors.clear();
errors.add("insertfail", new ActionError("error.insert.fail"));
saveErrors(request, errors);
}
request.setAttribute("info", "true");
return mapping.findForward("success");
}
private ActionForward View(ActionMapping mapping, OrderForm orderForm,
HttpServletRequest request,
HttpServletResponse response) {
String id = online.getUserId();
coll = db.select(db.WHERE + "userid='" + id + "'");
if (coll == null || coll.isEmpty()) {
errors.clear();
errors.add("selectfail", new ActionError("error.order.null"));
saveErrors(request, errors);
}
request.setAttribute("Order", coll);
return mapping.findForward("success");
}
private ActionForward List(ActionMapping mapping, ActionForm orderForm,
HttpServletRequest request,
HttpServletResponse response) {
int page=0;
try{
page=Integer.parseInt((String)request.getParameter("page"));
}catch(Exception e){
page=1;
}
coll = db.select(Keywords.STEP,page);
if (coll == null || coll.isEmpty()) {
errors.clear();
errors.add("selectfail", new ActionError("error.order.null"));
saveErrors(request, errors);
}
String showpage=html.Table(Keywords.STEP,db.getRowCount("tb_order"),page,"orderview.do");
request.setAttribute("page",showpage);
request.setAttribute("Order", coll);
return mapping.findForward("success");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -