⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 orderaction.java

📁 第1章 大学生就业求职网 第2章 网上物流平台 第3章 华奥汽车销售集团网 第4章 佳美网络购物中心 第5章 科研成果申报管理系统 第6章 安瑞奥国际商务学院招生网 第7章 在线宽带影院
💻 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 + -