?? cart.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 + -