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

📄 cart.java

📁 电子商城
💻 JAVA
字号:
package com.lmh;

import java.util.HashMap;
import java.util.Map;

import com.lmh.dao.impl.OracleMcDAO;
import com.lmh.dao.vo.McBean;
import com.lmh.dao.vo.OrderItemBean;

/**
 * @author Kenneth
 * 
 */
public class Cart {

	private Map<Integer, OrderItemBean> mcMaps = new HashMap<Integer, OrderItemBean>();// 商品明细

	private int mcSize = 0;// 商品数

	private int mcTypeSize = 0;// 商品类别总数

	private double totalPrice = 0.0;// 商品总价

	public void addMc(int nid) {
		OrderItemBean oib = mcMaps.get(nid);
		if (oib == null) {
			oib = new OrderItemBean();
			OracleMcDAO mcDao = new OracleMcDAO();
			McBean mcBean = mcDao.selectMc(nid);
		
			oib.setNmcid(mcBean.getNid());
			oib.setSimg(mcBean.getSimg());
			oib.setSmcname(mcBean.getSname());
			oib.setNcount(1);
			oib.setSdescription(mcBean.getSdescription());
			oib.setNprice(mcBean.getNprice());
			oib.setNtotalprice(mcBean.getNprice());
			mcMaps.put(nid, oib);
			mcTypeSize++;
			mcSize++;
			totalPrice += oib.getNprice();
		} else {
			oib.setNcount(oib.getNcount() + 1);
			oib.setNtotalprice(oib.getNtotalprice() + oib.getNprice());
			mcSize++;
			totalPrice += oib.getNprice();
		}

	}

	public void deleteMc(int nid) {
		OrderItemBean oib = mcMaps.get(nid);
		int mcCount = oib.getNcount();

		if (mcCount == 1) {
			mcMaps.remove(nid);
			mcTypeSize--;
			mcSize--;
			totalPrice -= oib.getNprice();
		} else {
			mcCount--;
			oib.setNcount(mcCount);
			oib.setNprice(oib.getNprice());
			oib.setNtotalprice(oib.getNtotalprice() - oib.getNprice());
			mcSize--;
			totalPrice -= oib.getNprice();
		}
	}

	public void updateMc(int nid, int newCount) {
		OrderItemBean oib = mcMaps.get(nid);
		int oldCount = oib.getNcount();

		oib.setNcount(newCount);
		oib.setNprice(oib.getNprice());
		oib.setNtotalprice(oib.getNprice()*newCount);
		mcSize += newCount - oldCount;
		totalPrice = totalPrice - oib.getNprice() * (oldCount - newCount);
	}

	public void clearAllMc() {
		mcMaps.clear();
		mcSize = 0;
		mcTypeSize = 0;
		totalPrice = 0.0;
	}

	/**
	 * @return the mcMaps
	 */
	public Map<Integer, OrderItemBean> getMcMaps() {
		return mcMaps;
	}

	/**
	 * @param mcMaps
	 *            the mcMaps to set
	 */
	public void setMcMaps(Map<Integer, OrderItemBean> mcMaps) {
		this.mcMaps = mcMaps;
	}

	/**
	 * @return the mcSize
	 */
	public int getMcSize() {
		return mcSize;
	}

	/**
	 * @param mcSize
	 *            the mcSize to set
	 */
	public void setMcSize(int mcSize) {
		this.mcSize = mcSize;
	}

	/**
	 * @return the mcTypeSize
	 */
	public int getMcTypeSize() {
		return mcTypeSize;
	}

	/**
	 * @param mcTypeSize
	 *            the mcTypeSize to set
	 */
	public void setMcTypeSize(int mcTypeSize) {
		this.mcTypeSize = mcTypeSize;
	}

	/**
	 * @return the totalPrice
	 */
	public double getTotalPrice() {
		return totalPrice;
	}

	/**
	 * @param totalPrice
	 *            the totalPrice to set
	 */
	public void setTotalPrice(double totalPrice) {
		this.totalPrice = totalPrice;
	}

}

⌨️ 快捷键说明

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