コード例 #1
0
ファイル: CartManager.cs プロジェクト: ue96/ue96
        /// <summary>
        /// ���ﳵ�����Ʒ
        /// �ڿͻ�����cookie����ʽ����
        /// �ڷ������HashTable����ʽ����
        /// �ڷ���ˣ��Թ��ﳵ�ĸ��ֲ�����hashtable����ʽ����
        /// </summary>
        /// <returns></returns>
        public Hashtable GetCartHash()
        {
            //get cart string;
            //build cart hash;
            //������������������ProductSysNo1,Quantity1,ExpectQty1;ProductSysNo2,Quantity2,ExpectQty2
            Hashtable ht = new Hashtable(5);

            string cartCookieValue = CookieUtil.GetDESEncryptedCookieValue("cart");
            if (cartCookieValue == null)
                return ht;
            string[] cartItems = cartCookieValue.Split(';');
            try
            {
                for (int i = 0; i < cartItems.Length; i++)
                {
                    string cartItem = cartItems[i];
                    string[] cartValues = cartItem.Split(',');
                    CartInfo oCart = new CartInfo();
                    oCart.ProductSysNo = Convert.ToInt32(cartValues[0]);
                    oCart.Quantity = Convert.ToInt32(cartValues[1]);
                    if (cartValues.Length > 2)
                    {
                        oCart.ExpectQty = Convert.ToInt32(cartValues[2]);
                    }
                    else
                    {
                        oCart.ExpectQty = Convert.ToInt32(cartValues[1]);
                    }
                    if (oCart.Quantity > 99)
                        oCart.Quantity = 99;
                    ht.Add(oCart.ProductSysNo, oCart);
                }
            }
            catch
            {

            }
            return ht;
        }
コード例 #2
0
ファイル: CartManager.cs プロジェクト: ue96/ue96
 public void UpdateCart(CartInfo oCart)
 {
     Hashtable ht = GetCartHash();
     if (ht.ContainsKey(oCart.ProductSysNo))
     {
         ht.Remove(oCart.ProductSysNo);
         ht.Add(oCart.ProductSysNo, oCart);
     }
     SaveCart(ht);
 }
コード例 #3
0
ファイル: ShoppingCartService.aspx.cs プロジェクト: ue96/ue96
 protected void Page_Load(object sender, EventArgs e)
 {
     if (CommonUtility.GetUserSession(Context).sCustomer != null)
     {
         if (!IsPostBack)
         {
             string msg = String.Empty;
             bool result = false;
             try
             {
                 switch (Cmd)
                 {
                     //添加商品到购物车
                     case "add":
                         {
                             CartInfo oInfo = new CartInfo()
                             {
                                 ProductSysNo = ProductSysNo,
                                 Quantity = ProductQty,
                                 ExpectQty = ProductQty,
                             };
                             newHt = CartManager.GetInstance().GetCartHash();
                             newHt.Add(ProductSysNo, oInfo);
                             Hashtable ht = new Hashtable();
                             ht.Add(ProductSysNo, oInfo);
                             CartManager.GetInstance().AddToCart(ht);
                             result = true;
                             msg = "成功添加";
                             Response.Write(JsonContentTransfomer<object>.GetJsonContent(new { IsSuccess = result, Msg = msg }));
                             break;
                         }
                     //删除单个购物车中的商品
                     case "delete":
                         {
                             CartManager.GetInstance().DeleteFromCart(ProductSysNo);
                             msg = "删除成功";
                             result = true;
                             Response.Write(JsonContentTransfomer<object>.GetJsonContent(new { IsSuccess = result, Msg = msg }));
                             break;
                         }
                     //更新购物车商品数量
                     case "update":
                         {
                             CartInfo cart = new CartInfo();
                             newHt = CartManager.GetInstance().GetCartHash();
                             cart = (CartInfo)newHt[ProductSysNo];
                             cart.Quantity = ProductQty;
                             CartManager.GetInstance().UpdateCart(cart);
                             msg = "修改成功";
                             result = true;
                             Response.Write(JsonContentTransfomer<object>.GetJsonContent(new { IsSuccess = result, Msg = msg }));
                             break;
                         }
                     case "clear":
                         {
                             CartManager.GetInstance().ClearCart();
                             msg = "成功清空购物车";
                             result = true;
                             Response.Write(JsonContentTransfomer<object>.GetJsonContent(new { IsSuccess = result, Msg = msg }));
                             break;
                         }
                     case "viewshortcuts":
                         {
                             //浏览购物车
                             Hashtable ht = new Hashtable();
                             if (newHt.Count == 0)
                             {
                                 ht = CartManager.GetInstance().GetCartHash();
                             }
                             else
                             {
                                 ht = newHt;
                             }
                             if (ht == null || ht.Count == 0)
                             {
                                 Response.Write(emptyShoppingCartHTML);
                             }
                             else
                             {
                                 Response.Write(CustomerHelper.GetCustomerShoppingCartShortCuts(ht));
                             }
                             break;
                         }
                     //默认什么都不做
                     case "viewcart":
                         {
                             break;
                         }
                     case "goshopping":
                         {
                             goShopping();
                             break;
                         }
                     default:
                         {
                             break;
                         }
                 }
             }
             catch
             {
                 msg = "用户请求的操作失败";
                 Response.Write(JsonContentTransfomer<object>.GetJsonContent(new { IsSuccess = result, Msg = msg }));
             }
         }
     }
     else
     {
         Response.Write(JsonContentTransfomer<object>.GetJsonContent(new { IsSuccess = false, Msg = "请先登录" }));
     }
 }