Ejemplo n.º 1
0
  public ActionForward orderList(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    ActionForward forward = null;

    Session session = null;
    Transaction tran = null;
    IOrderDao dao = new OrderDaoHibernateImp();
    Order order = new Order();
    ShopCart shopCart = (ShopCart) request.getSession().getAttribute("shopCart");

    User user = (User) request.getSession().getAttribute("user");
    int id = Integer.parseInt(request.getParameter("payWay"));

    OrderStatus status = new OrderStatus();
    status.setId(1);
    status.setName("配货状态");
    status.setDescriptions("订单正在配货状态三天内将发出");

    session = HibernateUtils.getSession();
    tran = session.beginTransaction();
    String hql = "from PayWay p where p.id=:id";
    PayWay payWay = (PayWay) session.createQuery(hql).setInteger("id", id).uniqueResult();
    tran.commit();

    if (shopCart == null) {
      System.out.println("shopCart is null.");
      shopCart = new ShopCart();
    }
    order = shopCart.getOrder();
    order.setName(user.getName());
    order.setPayWay(payWay);
    order.setStatus(status);
    order.setUser(user);
    order.setCost(shopCart.getTotal());
    Iterator it = order.getOrderlines().iterator();
    OrderLine orderLine = null;

    while (it.hasNext()) {
      orderLine = (OrderLine) it.next();
      orderLine.setOrder(order);
    }

    dao.addOrder(order);
    List<Order> orderList = (List<Order>) dao.findAll(user.getName());
    request.getSession().setAttribute("orderList", orderList);

    forward = mapping.findForward("orderList");

    return forward;
  }
Ejemplo n.º 2
0
  public ActionForward viewOrder(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    ActionForward forward = null;

    IOrderDao dao = new OrderDaoHibernateImp();
    Order order = new Order();
    Integer id = Integer.parseInt(request.getParameter("orderId"));
    System.out.println(id);
    try {
      order = dao.findById(id);
      request.setAttribute("orderdetails", order);
      forward = mapping.findForward("viewOrder");
    } catch (Exception e) {
      e.printStackTrace();
    }

    return forward;
  }