예제 #1
0
  // 导出商品
  public void load(String content) {
    if (content == null || content.equals("0")) {
      return;
    }
    String[] pcs = content.split(";");
    for (int i = 0; i < pcs.length; i++) {
      String pc = pcs[i];
      String[] strs = pc.split(",");
      int id = Integer.parseInt(strs[0]);
      int qty = Integer.parseInt(strs[1]);
      boolean buy = Boolean.parseBoolean(strs[2]);

      try {
        Product pro = productDAO.findById(id);
        CartItem item = new CartItem();
        item.setProduct(pro);
        item.setQty(qty);
        item.setBuy(buy);
        store.add(item);

      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
예제 #2
0
 public boolean buy(int id) throws Exception {
   // 判断是否购买过
   if (store == null) return false;
   for (CartItem item : store) {
     if (item.getProduct().getId() == id) {
       return false;
     }
   }
   // 未购买过
   System.out.println(id + "进去了");
   System.out.println(productDAO);
   Product pro = productDAO.findById(id);
   System.out.println("没结果");
   // System.out.println(pro.getProductName());
   CartItem item = new CartItem();
   item.setProduct(pro);
   store.add(item);
   return true;
 }