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

📄 cartbean.java

📁 精通NetBeans光盘源代码,很好很好的资料
💻 JAVA
字号:
/*
 * 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 org.netbeans.web;
import java.util.*;

/**
 *
 * @author boyingking
 */
public class CartBean {
    
    /** Creates a new instance of CartBean */
    private Hashtable hash=new Hashtable();//充当购物车的角色
    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);
        }
    }
    //如果当前购物车中不存在该商品,则将该商品添加到购物车中。
    private void productNotExit(Vector vec,String id){
        //获取当前查询出来的所有商品,并根据其ID号重新组织CartProduct的内容
        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号码的商品名称,作为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;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -