?? cartbean.java
字號(hào):
/* * CartBean.java * * Created on 2006年5月17日, 下午9:40 * * To change this template, choose Tools | Template Manager * and open the template in the editor. */package Bean;import VO.CartProduct;import VO.ProductBean;import java.util.*;/** * * @author boyingking */public class CartBean { /** Creates a new instance of CartBean */ private Hashtable hash=new Hashtable();//充當(dāng)購(gòu)物車的角色 public CartBean() { } public void addToCart(Vector vec,String id){ if (hash.get(id)!=null){ CartProduct tempcp=(CartProduct)hash.get(id); CartProduct cp=new CartProduct(); cp.setProductId(tempcp.getProductId()); cp.setProductName(tempcp.getProductName()); cp.setSelectedCount((tempcp.getSelectedCount())+1); cp.setProductPrice(tempcp.getProductPrice()); hash.remove(id); hash.put(id,cp); }else{ this.productNotExit(vec,id); } } //如果當(dāng)前購(gòu)物車中不存在該商品,則將該商品添加到購(gòu)物車中。 private void productNotExit(Vector vec,String id){ //獲取當(dāng)前查詢出來(lái)的所有商品,并根據(jù)其ID號(hào)重新組織CartProduct的內(nèi)容 Enumeration enume=vec.elements(); int tempid=Integer.parseInt(id); while(enume.hasMoreElements()){ ProductBean pb=(ProductBean)enume.nextElement(); if(tempid==(pb.getProductId())){ CartProduct cp=new CartProduct(); cp.setProductId(pb.getProductId()); //從Vector中獲取具有相同Id號(hào)碼的商品名稱,作為CartProduct的productName屬性的值。 cp.setProductName(pb.getProductName()); cp.setSelectedCount(1); cp.setProductPrice(pb.getProductPrice()); hash.put(id,cp); return ; } } } public Hashtable getCartContent(){ return this.hash; } public void deleteFromCart(String id){ this.hash.remove(id); } public void clearCart(){ this.hash.clear(); } public boolean isEmpty(){ boolean empty=false; if(this.hash.isEmpty()){ empty=true; }else{ empty=false; } return empty; }}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -