永发信息网

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

答案:2  悬赏:10  手机版
解决时间 2021-04-08 08:02
  • 提问者网友:萌卜娃娃
  • 2021-04-07 10:54
求ASP.NET购物车实现代码,用SESSION实现的那种主要是 购物车的那部分就可以了
最佳答案
  • 五星知识达人网友:酒醒三更
  • 2021-04-07 11:04
这个是我自己写的代码,希望对你有帮助: public void GetBuyShop(int shopId)
{
//获取当前点击的商品信息
Shop shop = ShopManager.GetShopByShopId(shopId);
//获取购物车
Dictionary cart = Session["cart"] as Dictionary;
//判断购物车是否存在
if (cart == null)
{
cart = new Dictionary();
} ShopItem shopitem = null;
//判断当前添加的商品在购物车中是否村
foreach (string str in cart.Keys)
{
//如果相等,表示存在
if (str == shop.ShopName)
{
...获取当前点击的商品信息
Shop shop = ShopManager, 1))这个是我自己写的代码;string: public void GetBuyShop(int shopId)
{
/, ShopItem>/.ShopName)
{
shopitem = cart[str];] = cart;
}
else
{
shopitem;cart"
} ShopItem shopitem = null;如果为null;
} Session["
}
} /.aspx".Add(shop,希望对你有帮助.ShopName,表示当前添加的商品早购物车中是不存在的
if (shopitem == null)
{
cart.GetShopByShopId(shopId);获取购物车
Dictionary //,表示存在
if (str == shop;Cart;();~//判断购物车是否存在
if (cart == null)
{
cart = new Dictionary<, ShopItem>.Keys)
{
/, new ShopItem(shop.Redirect(", ShopItem>
/如果相等;
Response;string;cart" cart = Session["] as Dictionary foreach (string str in cart;/);
/
全部回答
  • 1楼网友:毛毛
  • 2021-04-07 11:49

这个是我自己写的代码,希望对你有帮助:

 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");

    }

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯