求ASP.NET购物车实现代码,用SESSION实现的那种

求ASP.NET购物车实现代码,用SESSION实现的那种主要是 购物车的那部分就可以了

第1个回答  2013-10-16
这个是我自己写的代码,希望对你有帮助: public void GetBuyShop(int shopId)
{
//获取当前点击的商品信息
Shop shop = ShopManager.GetShopByShopId(shopId);
//获取购物车
Dictionary<string, ShopItem> cart = Session["cart"] as Dictionary<string, ShopItem>;
//判断购物车是否存在
if (cart == null)
{
cart = new Dictionary<string, ShopItem>();
} ShopItem shopitem = null;
//判断当前添加的商品在购物车中是否村
foreach (string str in cart.Keys)
{
//如果相等,表示存在
if (str == shop.ShopName)
{
shopitem = cart[str];
}
} //如果为null,表示当前添加的商品早购物车中是不存在的
if (shopitem == null)
{
cart.Add(shop.ShopName, new ShopItem(shop, 1));
}
else
{
shopitem.Count = shopitem.Count + 1;
} Session["cart"] = cart;
Response.Redirect("~/Cart.aspx");
}
第2个回答  2013-10-16
参考下微软的petshop,那里很详细的
相似回答