📄 goodcartbiz.java
字号:
package eshopsys.cart.biz;
import eshopsys.cart.biz.*;
import eshopsys.good.model.GoodEntity;
import eshopsys.tools.base.BaseEntity;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
public class GoodCartBiz {
public ArrayList<CartGoodEntity> cart=new ArrayList<CartGoodEntity>();
///////////////////////////////////////////////
public GoodCartBiz()
{
//cart=new ArrayList<CartGoodEntity>();
}
//////////////////////////////////////////////
public void addInCart(CartGoodEntity cartgood)
{
int goodTypeCount=cart.size();
CartGoodEntity cgood=null;
if(goodTypeCount>0)
{
int findIndex=findInCart(cartgood);
if(findIndex>=0)
{
//在原来记录中修改
cgood=(CartGoodEntity)cart.get(findIndex);
cgood.setGoodNum(cgood.getGoodNum()+cartgood.getGoodNum());
cart.remove(findIndex);
cart.add(cgood);
}
else
{
//在新增记录
cart.add(cartgood);
}
}
else
{//在新增记录
cart.add(cartgood);
}
}
//////////////////////////////////////////////
//////////////////////////////////////////////
public void updateInCart(CartGoodEntity cartgood)
{
int goodTypeCount=cart.size();
CartGoodEntity cgood=null;
if(goodTypeCount>0)
{
int findIndex=findInCart(cartgood);
if(findIndex>=0)
{
//更新原来的记录
cart.remove(findIndex);
cart.add(cartgood);
}
else
{
//在新增记录
cart.add(cartgood);
}
}
}
//////////////////////////////////////////////
public void deleteInCart(CartGoodEntity cartgood)
{
int goodTypeCount=cart.size();
CartGoodEntity cgood=null;
if(goodTypeCount>0)
{
int findIndex=findInCart(cartgood);
if(findIndex>=0)
{
//在原来记录删除
cart.remove(findIndex);
}
}
}
////////////////////////////////////////////////
////////////////////////////////////////////////
public int findInCart(CartGoodEntity cartgood)
{
int index=-1;
int goodTypeCount=cart.size();
CartGoodEntity cgood=null;
for(int i=0;i<goodTypeCount;i++)
{cgood=(CartGoodEntity)cart.get(i);
if(cgood.goodId==cartgood.goodId)
{index=i;break;}
}
return index;
}
public CartGoodEntity[] GetCartList()
{
int goodTypeCount=cart.size();
CartGoodEntity[] cartgoods = null;
if (goodTypeCount > 0) {
cartgoods= new CartGoodEntity[goodTypeCount];
cart.toArray(cartgoods);
}
return cartgoods;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -