コード例 #1
0
 // 关于商品删除后,历史订单如何引用此商品,待讨论
 private void remove() {
   Session se = HibernateSessionFactory.getSession();
   Transaction tran = se.beginTransaction();
   tran.begin();
   Itemlist rmvItemlist = (Itemlist) se.load(Itemlist.class, rmvItemlistId);
   se.delete(rmvItemlist);
   tran.commit();
   se.close();
 }
コード例 #2
0
  private void getData() throws ParseException {
    Session se = HibernateSessionFactory.getSession();
    Criteria store_cri = se.createCriteria(Store.class);
    store_cri.add(
        Restrictions.and(
            Restrictions.ne("name", "superDepartment"), Restrictions.ne("name", "server")));
    store_list = store_cri.list();
    staItem_list = new LinkedList<StaItemBean>();

    now = new java.sql.Date(new java.util.Date().getTime());
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // 制定日期格式
    Calendar c = Calendar.getInstance();
    java.util.Date date = new java.util.Date();
    c.setTime(date);
    c.add(Calendar.MONTH, -1); // 将当前日期加一个月
    String beforeStr = df.format(c.getTime()); // 返回String型的时间
    if (beginDateStr == null || beginDateStr.isEmpty()) beginDateStr = beforeStr;
    if (endDateStr == null || endDateStr.isEmpty()) endDateStr = df.format(now);
    java.util.Date tempdate = df.parse(beginDateStr);
    beginDate = new java.sql.Date(tempdate.getTime());
    java.util.Date tempdate2 = df.parse(endDateStr);
    endDate = new java.sql.Date(tempdate2.getTime());

    Criteria item_cri = se.createCriteria(Items.class);
    List<Items> itemlist = item_cri.list();
    Store currStore;
    if (store_id == 0) storeName = "所有店铺";
    else {
      currStore = (Store) se.load(Store.class, store_id);
      storeName = currStore.getName();
    }
    Iterator<Items> item_it = itemlist.iterator();
    while (item_it.hasNext()) {
      Items currItem = item_it.next();
      int tempNum = 0;
      float tempPrice = 0;
      curr = new StaItemBean(currItem.getName());
      Criteria detail_cri = se.createCriteria(Orderdetails.class);
      List<Orderdetails> detail_list;
      detail_cri.add(Restrictions.eq("itemName", currItem.getName()));
      if (store_id == 0) detail_list = detail_cri.list();
      else {
        List<Orderdetails> tempDetail = detail_cri.list();
        detail_list = new LinkedList<Orderdetails>();
        currStore = (Store) se.load(Store.class, store_id);
        Iterator<Orderdetails> d_it = tempDetail.iterator();
        while (d_it.hasNext()) {
          Orderdetails currD = d_it.next();
          if (currStore.getName().equals(currD.getOrders().getStoreName())) detail_list.add(currD);
        }
      }

      if (detail_list.isEmpty()) continue;
      Iterator<Orderdetails> detail_it = detail_list.iterator();
      while (detail_it.hasNext()) {
        Orderdetails currdetail = detail_it.next();
        tempNum += currdetail.getNumber();
        tempPrice += currdetail.getTotalPrice();
      }
      curr.setItemNum(tempNum);
      curr.setTotalPrice(tempPrice);

      staItem_list.add(curr);
    }

    se.close();
  }