Beispiel #1
0
        /// <summary>
        /// 获取购物车中产品的Quantity
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        protected string GetProductCount(object id)
        {
            UserInfo user = Session["user"] as UserInfo;

            if (user == null)
            {
                List <CartTemp> cartlist = Session["nologinCart"] as List <CartTemp>;
                if (cartlist != null)
                {
                    if (cartlist.Count > 0)
                    {
                        foreach (CartTemp ct in cartlist)
                        {
                            if (ct.productId == Convert.ToInt32(id))
                            {
                                return(ct.productCount.ToString());
                            }
                        }
                    }
                }
            }
            else
            {
                Session["nologinCart"] = null;
                CartTemp item = CartTempService.GetModelByProductId(user.id, Convert.ToInt32(id));
                if (item != null)
                {
                    return(item.productCount.ToString());
                }
            }
            return("");
        }
Beispiel #2
0
 /// <summary>
 /// 控件行命令事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void repInfo_ItemCommand(object source, RepeaterCommandEventArgs e)
 {
     if (e.CommandName.Equals("add"))
     {
         int      id = Convert.ToInt32(e.CommandArgument);
         CartTemp ct = CartTempService.GetModel(id);
         if (ct != null)
         {
             ct.productCount++;
             Product p = ProductService.GetModel(ct.productId);
             if (p != null)
             {
                 ct.remark = (ct.productCount * p.price1).ToString("0.00");
             }
             CartTempService.UpdateCart(ct);
         }
     }
     if (e.CommandName.Equals("del"))
     {
         CartTempService.Delete(Convert.ToInt32(e.CommandArgument));
     }
     if (e.CommandName.Equals("reduce"))
     {
         int      id = Convert.ToInt32(e.CommandArgument);
         CartTemp ct = CartTempService.GetModel(id);
         if (ct != null)
         {
             if (ct.productCount > 1)
             {
                 ct.productCount--;
                 Product p = ProductService.GetModel(ct.productId);
                 if (p != null)
                 {
                     ct.remark = (ct.productCount * p.price1).ToString("0.00");
                 }
                 CartTempService.UpdateCart(ct);
             }
         }
     }
     BindData();
 }