📄 wareaction.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.Waredb;
import java.util.Collection;
import java.util.ArrayList;
import com.cargo.db.Car;
import java.util.Iterator;
import com.cargo.model.Ware;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: MR</p>
* @author BWM
* @version 1.0
*/
public class WareAction extends Action {
private ActionForward forward = new ActionForward();
private ActionErrors errors = new ActionErrors();
private Line online = new Line();
private Waredb db = new Waredb();
private Collection coll = new ArrayList();
private int t;
public ActionForward perform(ActionMapping actionMapping,
ActionForm actionForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
WareForm wareForm = (WareForm) actionForm;
String action = actionMapping.getParameter();
if ("view".equalsIgnoreCase(action)) {
forward = View(actionMapping, wareForm, httpServletRequest,
httpServletResponse);
return forward;
}
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 ("add".equalsIgnoreCase(action)) {
forward = Add(actionMapping, wareForm, httpServletRequest,
httpServletResponse);
} else if ("save".equalsIgnoreCase(action)) {
forward = Change(actionMapping, wareForm, httpServletRequest,
httpServletResponse);
} else if ("del".equalsIgnoreCase(action)) {
forward = Del(actionMapping, wareForm, httpServletRequest,
httpServletResponse);
} else if ("caradd".equalsIgnoreCase(action)) {
forward = Caradd(actionMapping, wareForm, httpServletRequest,
httpServletResponse);
} else if ("carchange".equalsIgnoreCase(action)) {
forward = Carchange(actionMapping, wareForm, httpServletRequest,
httpServletResponse);
} else if ("cardel".equalsIgnoreCase(action)) {
forward = Cardel(actionMapping, wareForm, httpServletRequest,
httpServletResponse);
} else {
forward = actionMapping.findForward("errors");
}
return forward;
}
private ActionForward Change(ActionMapping actionMapping, WareForm wareForm,
HttpServletRequest request,
HttpServletResponse response) {
t = db.update(wareForm.getWare());
if (t <= 0) {
errors.clear();
errors.add("insertfail", new ActionError("error.update.fail"));
saveErrors(request, errors);
return (new ActionForward(actionMapping.getInput()));
}
request.setAttribute("info", "true");
return actionMapping.findForward("success");
}
private ActionForward Cardel(ActionMapping mapping, WareForm wareForm,
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession();
String wareid=(String)request.getParameter("wareid");
wareForm.getWare().setId(wareid);
coll = (Collection) session.getAttribute("car");
Car car = new Car(coll);
coll = car.DeltoCar(wareForm.getWare());
session.setAttribute("car", coll);
return mapping.findForward("success");
}
private ActionForward Carchange(ActionMapping mapping, WareForm wareForm,
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession();
coll = (Collection) session.getAttribute("car");
Car car = new Car(coll);
coll = car.ChangetoCar(wareForm.getWare());
session.setAttribute("car", coll);
return mapping.findForward("success");
}
private ActionForward View(ActionMapping actionMapping, WareForm wareForm,
HttpServletRequest request,
HttpServletResponse response) {
String id = "";
try {
id = request.getParameter("id").toString();
} catch (Exception e) {
id = null;
}
if (id != null && id.trim().length() > 0) {
coll = db.select(db.WHERE + "id='" + id + "'");
} else {
coll = db.select();
}
if (coll == null || coll.isEmpty()) {
errors.clear();
errors.add("selectfail", new ActionError("error.manage.addware"));
saveErrors(request, errors);
}
request.setAttribute("Ware", coll);
return actionMapping.findForward("success");
}
private ActionForward Del(ActionMapping actionMapping, WareForm form,
HttpServletRequest request,
HttpServletResponse response) {
String id = request.getParameter("id").toString();
t = db.delete(db.DELETE + "tb_ware" + db.WHERE + "id='" + id + "'");
if (t <= 0) {
errors.clear();
errors.add("deletefail", new ActionError("error.delete.fail"));
saveErrors(request, errors);
}
request.setAttribute("info", "true");
return actionMapping.findForward("success");
}
private ActionForward Caradd(ActionMapping mapping, WareForm wareForm,
HttpServletRequest request,
HttpServletResponse response) {
HttpSession session = request.getSession();
coll = (Collection) session.getAttribute("car");
Car car = new Car(coll);
coll = car.AddtoCar(wareForm.getWare());
session.setAttribute("car", coll);
return mapping.findForward("success");
}
private ActionForward Add(ActionMapping actionMapping, WareForm wareForm,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
t = db.getRowCount("tb_ware" + db.WHERE + "id='" +
wareForm.getWare().getId() + "'");
if (t > 0) {
errors.clear();
errors.add("insertfail", new ActionError("error.insert.repeat"));
saveErrors(httpServletRequest, errors);
return (new ActionForward(actionMapping.getInput()));
}
t = db.insert(wareForm.getWare());
if (t <= 0) {
errors.clear();
errors.add("insertfail", new ActionError("error.insert.fail"));
saveErrors(httpServletRequest, errors);
return (new ActionForward(actionMapping.getInput()));
}
httpServletRequest.setAttribute("info", "true");
return actionMapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -