コード例 #1
0
    /// <summary>
    /// Get an item from the databes into a cart item
    /// </summary>
    /// <param name="itemId">Item Id of item to add</param>
    public static CartItemInfo getCartItemInfo(int productID)
    {
        CartItemInfo item = new CartItemInfo();

        item.ProductId = -1;

        SqlParameter productIDSqlParameter = new SqlParameter("@ProductID", SqlDbType.Int);

        productIDSqlParameter.Value = productID;

        using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.mainConnectionString, CommandType.StoredProcedure, "GetProduct", productIDSqlParameter))
        {
            while (rdr.Read())
            {
                item.ProductId    = productID;
                item.ProductName  = rdr["ProductName"].ToString();
                item.Quantity     = 1;
                item.Price        = Convert.ToDecimal(rdr["Price"]);
                item.CategoryId   = Convert.ToInt32(rdr["CategoryID"]);
                item.CategoryName = rdr["CategoryName"].ToString();
            }
        }

        return(item);
    }
コード例 #2
0
        /// <summary>
        /// Retrieve collection of shopping cart items
        /// </summary>
        /// <param name="userName">User Name</param>
        /// <param name="appName">Application Name</param>
        /// <param name="isShoppingCart">Shopping cart flag</param>
        /// <returns>Collection of shopping cart items</returns>
        public IList <CartItemInfo> GetCartItems(string userName, string appName, bool isShoppingCart)
        {
            string sqlSelect = "SELECT Cart.ItemId, Cart.Name, Cart.Type, Cart.Price, Cart.CategoryId, Cart.ProductId, Cart.Quantity FROM Profiles, Cart WHERE Profiles.UniqueID = Cart.UniqueID AND Profiles.Username = :Username AND Profiles.ApplicationName = :ApplicationName AND IsShoppingCart = :IsShoppingCart";

            OracleParameter[] parms =
            {
                new OracleParameter(":Username",        OracleType.VarChar, 256),
                new OracleParameter(":ApplicationName", OracleType.VarChar, 256),
                new OracleParameter(":IsShoppingCart",  OracleType.VarChar, 1)
            };
            parms[0].Value = userName;
            parms[1].Value = appName;
            parms[2].Value = OracleHelper.OraBit(isShoppingCart);

            OracleDataReader dr = OracleHelper.ExecuteReader(OracleHelper.ConnectionStringProfile, CommandType.Text, sqlSelect, parms);

            IList <CartItemInfo> cartItems = new List <CartItemInfo>();

            while (dr.Read())
            {
                CartItemInfo cartItem = new CartItemInfo(dr.GetString(0), dr.GetString(1), dr.GetInt32(6), dr.GetDecimal(3), dr.GetString(2), dr.GetString(4), dr.GetString(5));
                cartItems.Add(cartItem);
            }
            dr.Close();
            return(cartItems);
        }
コード例 #3
0
ファイル: Cart.cs プロジェクト: hwman-qq/PetShopMvc
        /// <summary>
        /// Removes item from cart at specific index
        /// </summary>
        /// <param name="index">Element number of item to remove</param>
        public void RemoveAt(int index)
        {
            CartItemInfo item = (CartItemInfo)_items[index];

            _total = _total - (item.Price * item.Quantity);
            _items.RemoveAt(index);
        }
コード例 #4
0
        /// <summary>
        /// Retrieve collection of shopping cart items
        /// </summary>
        /// <param name="userName">User Name</param>
        /// <param name="appName">Application Name</param>
        /// <param name="isShoppingCart">Shopping cart flag</param>
        /// <returns>Collection of shopping cart items</returns>
        public IList <CartItemInfo> GetCartItems(string userName, string appName, bool isShoppingCart)
        {
            string sqlSelect = "SELECT Cart.ItemId, Cart.Name, Cart.Type, Cart.Price, Cart.CategoryId, Cart.ProductId, Cart.Quantity FROM Profiles INNER JOIN Cart ON Profiles.UniqueID = Cart.UniqueID WHERE Profiles.Username = @Username AND Profiles.ApplicationName = @ApplicationName AND IsShoppingCart = @IsShoppingCart;";

            SqlParameter[] parms =
            {
                new SqlParameter("@Username",        SqlDbType.VarChar, 256),
                new SqlParameter("@ApplicationName", SqlDbType.VarChar, 256),
                new SqlParameter("@IsShoppingCart",  SqlDbType.Bit)
            };
            parms[0].Value = userName;
            parms[1].Value = appName;
            parms[2].Value = isShoppingCart;

            SqlDataReader dr = SqlHelper.ExecuteReader(SqlHelper.ConnectionStringProfile, CommandType.Text, sqlSelect, parms);

            IList <CartItemInfo> cartItems = new List <CartItemInfo>();

            while (dr.Read())
            {
                CartItemInfo cartItem = new CartItemInfo(dr.GetString(0), dr.GetString(1), dr.GetInt32(6), dr.GetDecimal(3), dr.GetString(2), dr.GetString(4), dr.GetString(5));
                cartItems.Add(cartItem);
            }
            dr.Close();
            return(cartItems);
        }
コード例 #5
0
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "s")
        {
            //Response.Write("选择, StudentID=" + e.CommandArgument);
        }
        else if (e.CommandName == "e")
        {
            Response.Write("编辑");
        }
        else if (e.CommandName == "d")
        {
            Response.Write("删除");
        }
        else if (e.CommandName == "AddToCart")
        {
            string itemId = e.CommandArgument.ToString();
            string name = (e.Item.FindControl("lblName") as Label).Text;
            float price = Convert.ToSingle((e.Item.FindControl("lblPrice") as Label).Text);
            int quantity = Convert.ToInt32(txtQuantity.Text);
            CartItemInfo itemInfo = new CartItemInfo(itemId, name, price, quantity);

            cart.Add(itemInfo);

            Response.Write("将 " +e.CommandArgument+ "号商品加入购物车");
        }
    }
コード例 #6
0
        public AddToCartViewVM(ProductInfo productInfo)
        {
            Product     = productInfo;
            MallPrice   = Product.itemAttributeValues[0].mallPrice.ToString();
            MemberPrice = Product.itemAttributeValues[0].memberPrice.ToString();
            Index       = 0;

            //CusPriceVisible = GlobalVariables.LoggedUser.userType == "0";
            MemberPriceVisible = GlobalVariables.IsLogged;

            ProductNum = 1;

            AddToCartCommand = new Command(async() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    AddToCartAsync();
                }
                await PopupNavigation.Instance.PopAsync();
            }, () => { return(true); });

            ToOrderCommand = new Command(async() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    List <CartItemInfo> productList = new List <CartItemInfo>();

                    CartItemInfo cartItemInfo = new CartItemInfo();
                    Tools.AutoMapping <ProductInfo, CartItemInfo>(Product, cartItemInfo);
                    cartItemInfo.productNum       = 1;
                    cartItemInfo.productImg       = Product.productImageBig;
                    cartItemInfo.attributesValues = Product.itemAttributeValues[Index].attributeValue;

                    productList.Add(cartItemInfo);

                    OrderingPage orderingPage = new OrderingPage(productList);
                    await PopupNavigation.Instance.PopAsync();
                    await Application.Current.MainPage.Navigation.PushModalAsync(orderingPage);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    await PopupNavigation.Instance.PopAsync();
                    await Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            SelectAttributeCommand = new Command(() =>
            {
                MallPrice   = Product.itemAttributeValues[Index].mallPrice.ToString();
                MemberPrice = Product.itemAttributeValues[Index].memberPrice.ToString();
            }, () => { return(true); });
        }
コード例 #7
0
        /// <summary>
        /// Add an item to the cart.
        /// When ItemId to be added has already existed, this method will update the quantity instead.
        /// </summary>
        /// <param name="item">Item to add</param>
        public void Add(CartItemInfo item)
        {
            CartItemInfo cartItem;

            if (!cartItems.TryGetValue(item.CartKey.ToString(), out cartItem))
            {
                cartItems.Add(item.CartKey.ToString(), item);
            }
            else
            {
                cartItem.Quantity += item.Quantity;
            }
        }
コード例 #8
0
ファイル: Cart.cs プロジェクト: simonz130/petshop_kubernetes
        /// <summary>
        /// Add an item to the cart.
        /// When ItemId to be added has already existed, this method will update the quantity instead.
        /// </summary>
        /// <param name="item">Item to add</param>
        public void Add(CartItemInfo item)
        {
            CartItemInfo cartItem;

            if (!cartItems.TryGetValue(item.ItemId, out cartItem))
            {
                cartItems.Add(item.ItemId, item);
            }
            else
            {
                cartItem.Quantity += item.Quantity;
            }
        }
コード例 #9
0
ファイル: CartItem.cs プロジェクト: 2644783865/Infoztc
        public void Add(CartItemInfo item)
        {
            CartItemInfo cartItem;

            if (!cartItems.TryGetValue(Guid.Parse(item.ProductId.ToString()), out cartItem))
            {
                cartItems.Add(Guid.Parse(item.ProductId.ToString()), item);
            }
            else
            {
                cartItem.Quantity += item.Quantity;
            }
        }
コード例 #10
0
        public async Task <StupidRD> DeleteItemInCart(CartItemInfo cartItemInfo)
        {
            string url  = "/member/cartDel";
            string json = "{\"userId\":" + GlobalVariables.LoggedUser.id
                          + ",\"checked\":\"" + cartItemInfo.Checked
                          + "\",\"productId\":" + cartItemInfo.productId
                          + ",\"attributesValues\":\"" + cartItemInfo.attributesValues
                          + "\"}";

            StupidRD stupidRD = await RestSharpHelper <StupidRD> .PostAsync(url, json);

            return(stupidRD);
        }
コード例 #11
0
        public static CartInfo AppendBook(CartInfo cart, BookInfo book, int number)
        {
            CartItemInfo item = new CartItemInfo();

            item.Book     = book;
            item.Quantity = number;
            item.SubTotal = item.Book.UnitPrice * item.Quantity;

            cart.Items.Add(item);
            cart.TotalQuantity += item.Quantity;
            cart.TotalPrice    += item.SubTotal;

            return(cart);
        }
コード例 #12
0
        private async void TwoTapped_TappedAsync(long id)
        {
            try
            {
                string action = await Application.Current.MainPage.DisplayActionSheet("选择操作", "取消", null, "删除", "修改");

                if (action == "删除")
                {
                    if (!Tools.IsNetConnective())
                    {
                        CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Long);
                        return;
                    }

                    CartItemInfo temp = new CartItemInfo();
                    foreach (var item in ItemList)
                    {
                        if (item.productId == id)
                        {
                            temp = item;
                            //ItemList.Remove(item);
                        }
                    }

                    //Frame frame = sender as Frame;
                    //int index = ItemStack.Children.IndexOf(frame);

                    StupidRD stupidRD = await _restSharpService.DeleteItemInCart(temp);

                    if (stupidRD.success)
                    {
                        CrossToastPopUp.Current.ShowToastSuccess("删除成功!", ToastLength.Short);
                        InitCart();
                    }
                    else
                    {
                        CrossToastPopUp.Current.ShowToastError("删除失败!", ToastLength.Short);
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }
        }
コード例 #13
0
ファイル: Cart.cs プロジェクト: simonz130/petshop_kubernetes
        /// <summary>
        /// Add an item to the cart.
        /// When ItemId to be added has already existed, this method will update the quantity instead.
        /// </summary>
        /// <param name="itemId">Item Id of item to add</param>
        public void Add(string itemId)
        {
            CartItemInfo cartItem;

            if (!cartItems.TryGetValue(itemId, out cartItem))
            {
                Item     item = new Item();
                ItemInfo data = item.GetItem(itemId);
                if (data != null)
                {
                    CartItemInfo newItem = new CartItemInfo(itemId, data.ProductName, 1, (decimal)data.Price, data.Name, data.CategoryId, data.ProductId);
                    cartItems.Add(itemId, newItem);
                }
            }
            else
            {
                cartItem.Quantity++;
            }
        }
コード例 #14
0
ファイル: Cart.cs プロジェクト: qq283335746/ECShop
        /// <summary>
        /// Add an item to the cart.
        /// When ItemId to be added has already existed, this method will update the quantity instead.
        /// </summary>
        /// <param name="itemId">Item Id of item to add</param>
        public void Add(string itemId)
        {
            CartItemInfo cartItem;

            if (!cartItems.TryGetValue(itemId, out cartItem))
            {
                Product     pBll  = new Product();
                ProductInfo model = pBll.GetModel(itemId);
                if (model != null)
                {
                    CartItemInfo newItem = new CartItemInfo(itemId, model.ProductName, 1, model.ProductPrice, model.ImagesUrl);
                    cartItems.Add(itemId, newItem);
                }
            }
            else
            {
                cartItem.Quantity++;
            }
        }
コード例 #15
0
 protected void lvwItems_ItemCommand(object sender, System.Web.UI.WebControls.ListViewCommandEventArgs e)
 {
     //通过 CommandName 判断用户在 DataList 中点击的是否是“添加到购物车”按钮,若是
     if (e.CommandName == "AddToCart")
     {
         //获取用户点击的那一项的 ItemID(通过事先通过数据绑定实现的 CommandArgument 属性)
         string itemId = e.CommandArgument.ToString();
         //通过 e.Item.FindControl() 方法,获取用户点击的那一项中的指定名称的控件,并得到控件中的属性值
         string name = (e.Item.FindControl("lblTitle") as Label).Text;
         float price = Convert.ToSingle((e.Item.FindControl("lblPrice") as Label).Text);
         //获取用户在“购买数量”文本框中输入的值
         int quantity = Convert.ToInt32(txtCount.Text);
         //通过调用构造函数,创建一个 CartItemInfo 类型的对象,用于保存购物车中的一条记录
         CartItemInfo itemInfo = new CartItemInfo(itemId, name, price, quantity);
         //将 CartItemInfo 类型的对象作为一个元素,添加到 List<CartItemInfo> 类型的对象中去
         cart.Add(itemInfo);
         //将 List<CartItemInfo> 类型的对象放入 Session 中(以便在另外一个页面得到购物车中的数据)
         Session["cart"] = cart;
     }
 }
コード例 #16
0
ファイル: CartItem.cs プロジェクト: 2644783865/Infoztc
        public void Add(Guid itemId)
        {
            CartItemInfo cartItem;

            if (!cartItems.TryGetValue(itemId, out cartItem))
            {
                Product     bll  = new Product();
                ProductInfo data = bll.GetModel(itemId);
                if (data != null)
                {
                    CartItemInfo newItem = new CartItemInfo {
                        ProductId = itemId, Named = data.Named, CategoryId = data.CategoryId, Price = data.Price, Quantity = 1, LastUpdatedDate = DateTime.Now
                    };
                    cartItems.Add(itemId, newItem);
                }
            }
            else
            {
                cartItem.Quantity++;
            }
        }
コード例 #17
0
ファイル: Cart.cs プロジェクト: hwman-qq/PetShopMvc
        /// <summary>
        /// Add an item to the cart
        /// </summary>
        /// <param name="ItemId">ItemId of item to add</param>
        public void Add(string ItemId)
        {
            foreach (CartItemInfo cartItem in _items)
            {
                if (ItemId == cartItem.ItemId)
                {
                    cartItem.Quantity++;
                    cartItem.InStock = (GetInStock(ItemId) - cartItem.Quantity) >= 0 ? true : false;
                    _total           = _total + (cartItem.Price * cartItem.Quantity);
                    return;
                }
            }

            CartItem item = new CartItem();

            ItemInfo     data    = item.GetItem(ItemId);
            CartItemInfo newItem = new CartItemInfo(ItemId, data.Name, (data.Quantity >= 1), 1, (decimal)data.Price);

            _items.Add(newItem);
            _total = _total + (data.Price);
        }
コード例 #18
0
        public static int AddOrderBook(int orderId, CartItemInfo cartItem)
        {
            string strConn = ConfigurationManager.ConnectionStrings["BookShopConnectionString"].ConnectionString;

            using (SqlConnection conn = new SqlConnection(strConn))
            {
                conn.Open();
                string strSQL = @"insert OrderBooks(OrderID,BookID,Quantity,UnitPrice) values (@OrderID,@BookID,@Quantity,@UnitPrice)";

                SqlCommand     commOrder = new SqlCommand(strSQL, conn);
                SqlParameter[] paras     = new SqlParameter[]
                {
                    new SqlParameter("@OrderID", orderId),
                    new SqlParameter("@BookID", cartItem.Book.Id),
                    new SqlParameter("@Quantity", cartItem.Quantity),
                    new SqlParameter("@UnitPrice", cartItem.Book.UnitPrice)
                };
                commOrder.Parameters.AddRange(paras);

                return(Convert.ToInt32(commOrder.ExecuteNonQuery()));
            }
        }
コード例 #19
0
        public IList <CartItemInfo> GetCartItems(string userName, string appName, bool isShoppingCart)
        {
            string sqlSelect = @"SELECT c.ProfileId,c.ProductId,c.CategoryId,c.Price,c.Quantity,c.Named,c.IsShoppingCart,c.LastUpdatedDate 
                                 FROM Profiles p INNER JOIN Cart c ON p.Id = c.ProfileId WHERE p.Username = @Username AND p.AppName = @AppName 
                                 AND IsShoppingCart = @IsShoppingCart;";

            SqlParameter[] parms =
            {
                new SqlParameter("@Username",       SqlDbType.NVarChar, 50),
                new SqlParameter("@AppName",        SqlDbType.NVarChar, 50),
                new SqlParameter("@IsShoppingCart", SqlDbType.Bit)
            };
            parms[0].Value = userName;
            parms[1].Value = appName;
            parms[2].Value = isShoppingCart;

            IList <CartItemInfo> cartItems = new List <CartItemInfo>();

            using (SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.HnztcShopDbConnString, CommandType.Text, sqlSelect, parms))
            {
                while (reader.Read())
                {
                    CartItemInfo model = new CartItemInfo();
                    model.ProfileId       = reader.GetGuid(0);
                    model.ProductId       = reader.GetGuid(1);
                    model.CategoryId      = reader.GetGuid(2);
                    model.Price           = reader.GetDecimal(3);
                    model.Quantity        = reader.GetInt32(4);
                    model.Named           = reader.GetString(5);
                    model.IsShoppingCart  = reader.GetBoolean(6);
                    model.LastUpdatedDate = reader.GetDateTime(7);
                    cartItems.Add(model);
                }
            }

            return(cartItems);
        }
コード例 #20
0
ファイル: Carts.cs プロジェクト: qq550723504/zone
        /// <summary>
        /// 整理店铺订单商品列表
        /// </summary>
        /// <param name="selectedCartItemKeyList">选中的购物车项键列表</param>
        /// <param name="orderProductList">订单商品列表</param>
        /// <param name="selectedOrderProductList">选中的订单商品列表</param>
        /// <param name="remainedOrderProductList">剩余的订单商品列表</param>
        /// <returns></returns>
        public static List<CartItemInfo> TidyStoreOrderProductList(string[] selectedCartItemKeyList, List<OrderProductInfo> orderProductList, out List<OrderProductInfo> selectedOrderProductList, out List<OrderProductInfo> remainedOrderProductList)
        {
            //声明一个购物车项列表
            List<CartItemInfo> cartItemList = new List<CartItemInfo>();
            //初始化选中的订单商品列表
            selectedOrderProductList = new List<OrderProductInfo>();
            //初始化剩余的订单商品列表
            remainedOrderProductList = new List<OrderProductInfo>();

            //订单商品商品数量
            int count = orderProductList.Count;
            for (int i = 0; i < count; i++)
            {
                OrderProductInfo orderProductInfo = orderProductList[i];
                if (orderProductInfo == null)//如果此订单商品已经被置为null则跳过
                    continue;

                if (orderProductInfo.Type == 0)//当商品是普通订单商品时
                {
                    if (orderProductInfo.ExtCode4 > 0)//满赠订单商品处理
                    {
                        #region 满赠订单商品处理

                        FullSendPromotionInfo fullSendPromotionInfo = Promotions.GetFullSendPromotionByPmIdAndTime(orderProductInfo.ExtCode4, DateTime.Now);
                        if (fullSendPromotionInfo != null)
                        {
                            CartFullSendInfo cartFullSendInfo = new CartFullSendInfo();

                            cartFullSendInfo.FullSendPromotionInfo = fullSendPromotionInfo;

                            List<CartProductInfo> fullSendMainCartProductList = new List<CartProductInfo>();
                            CartProductInfo cartProductInfo1 = new CartProductInfo();
                            cartProductInfo1.Selected = IsSelectCartItem(0, orderProductInfo.Pid, selectedCartItemKeyList);
                            cartProductInfo1.OrderProductInfo = orderProductInfo;
                            orderProductList[i] = null;
                            List<OrderProductInfo> giftList1 = new List<OrderProductInfo>();
                            //获取商品的赠品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 1 && item.ExtCode1 == orderProductInfo.ExtCode3)
                                {
                                    giftList1.Add(item);
                                    orderProductList[j] = null;
                                }
                            }
                            cartProductInfo1.GiftList = giftList1;
                            fullSendMainCartProductList.Add(cartProductInfo1);
                            //获取同一满赠商品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 0 && item.ExtCode4 == orderProductInfo.ExtCode4)
                                {
                                    CartProductInfo cartProductInfo2 = new CartProductInfo();
                                    cartProductInfo2.Selected = IsSelectCartItem(0, item.Pid, selectedCartItemKeyList);
                                    cartProductInfo2.OrderProductInfo = item;
                                    orderProductList[j] = null;
                                    List<OrderProductInfo> giftList2 = new List<OrderProductInfo>();
                                    for (int k = 0; k < count; k++)
                                    {
                                        OrderProductInfo item2 = orderProductList[k];
                                        if (item2 != null && item2.Type == 1 && item2.ExtCode1 == item.ExtCode3)
                                        {
                                            giftList2.Add(item2);
                                            orderProductList[k] = null;
                                        }
                                    }
                                    cartProductInfo2.GiftList = giftList2;
                                    fullSendMainCartProductList.Add(cartProductInfo2);
                                }
                            }
                            cartFullSendInfo.FullSendMainCartProductList = fullSendMainCartProductList;

                            decimal selectedFullSendMainCartProductAmount = 0M;
                            foreach (CartProductInfo fullSendMainCartProductInfo in fullSendMainCartProductList)
                            {
                                if (fullSendMainCartProductInfo.Selected)
                                    selectedFullSendMainCartProductAmount += fullSendMainCartProductInfo.OrderProductInfo.DiscountPrice * fullSendMainCartProductInfo.OrderProductInfo.BuyCount;
                            }
                            cartFullSendInfo.IsEnough = selectedFullSendMainCartProductAmount >= fullSendPromotionInfo.LimitMoney;

                            //获取商品的满赠商品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 4 && item.ExtCode1 == orderProductInfo.ExtCode4)
                                {
                                    cartFullSendInfo.FullSendMinorOrderProductInfo = item;
                                    orderProductList[j] = null;
                                    break;
                                }
                            }

                            CartItemInfo cartItemInfo = new CartItemInfo();
                            cartItemInfo.Type = 2;
                            cartItemInfo.Item = cartFullSendInfo;
                            cartItemList.Add(cartItemInfo);
                        }
                        else//当满赠促销活动不存在时,按照没有满赠促销商品处理
                        {
                            List<OrderProductInfo> updateFullSendOrderProductList = new List<OrderProductInfo>();

                            orderProductInfo.ExtCode4 = 0;
                            updateFullSendOrderProductList.Add(orderProductInfo);

                            CartProductInfo cartProductInfo1 = new CartProductInfo();
                            cartProductInfo1.Selected = IsSelectCartItem(0, orderProductInfo.Pid, selectedCartItemKeyList);
                            cartProductInfo1.OrderProductInfo = orderProductInfo;
                            orderProductList[i] = null;
                            List<OrderProductInfo> giftList1 = new List<OrderProductInfo>();
                            //获取商品的赠品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 1 && item.ExtCode1 == orderProductInfo.ExtCode3)
                                {
                                    giftList1.Add(item);
                                    orderProductList[j] = null;
                                }
                            }
                            cartProductInfo1.GiftList = giftList1;

                            CartItemInfo cartItemInfo1 = new CartItemInfo();
                            cartItemInfo1.Type = 0;
                            cartItemInfo1.Item = cartProductInfo1;
                            cartItemList.Add(cartItemInfo1);

                            //获取同一满赠商品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 0 && item.ExtCode4 == orderProductInfo.ExtCode4)
                                {
                                    item.ExtCode4 = 0;
                                    updateFullSendOrderProductList.Add(item);

                                    CartProductInfo cartProductInfo2 = new CartProductInfo();
                                    cartProductInfo2.Selected = IsSelectCartItem(0, item.Pid, selectedCartItemKeyList);
                                    cartProductInfo2.OrderProductInfo = item;
                                    orderProductList[j] = null;
                                    List<OrderProductInfo> giftList2 = new List<OrderProductInfo>();
                                    for (int k = 0; k < count; k++)
                                    {
                                        OrderProductInfo item2 = orderProductList[k];
                                        if (item2 != null && item2.Type == 1 && item2.ExtCode1 == item.ExtCode3)
                                        {
                                            giftList2.Add(item2);
                                            orderProductList[k] = null;
                                        }
                                    }
                                    cartProductInfo2.GiftList = giftList2;

                                    CartItemInfo cartItemInfo2 = new CartItemInfo();
                                    cartItemInfo2.Type = 0;
                                    cartItemInfo2.Item = cartProductInfo2;
                                    cartItemList.Add(cartItemInfo2);
                                }
                            }

                            //更新商品的满赠促销活动
                            UpdateOrderProductFullSend(updateFullSendOrderProductList);

                            //获取商品的满赠商品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                //当满赠赠品存在时删除满赠赠品
                                if (item != null && item.Type == 4 && item.ExtCode1 == orderProductInfo.ExtCode4)
                                {
                                    DeleteOrderProductList(new List<OrderProductInfo>() { item });
                                    break;
                                }
                            }
                        }

                        #endregion
                    }
                    else if (orderProductInfo.ExtCode5 > 0)//满减订单商品处理
                    {
                        #region 满减订单商品处理

                        FullCutPromotionInfo fullCutPromotionInfo = Promotions.GetFullCutPromotionByStoreIdAndPmIdAndTime(orderProductInfo.StoreId, orderProductInfo.ExtCode5, DateTime.Now);
                        if (fullCutPromotionInfo != null)
                        {
                            CartFullCutInfo cartFullCutInfo = new CartFullCutInfo();

                            cartFullCutInfo.FullCutPromotionInfo = fullCutPromotionInfo;

                            List<CartProductInfo> fullCutCartProductList = new List<CartProductInfo>();
                            CartProductInfo cartProductInfo1 = new CartProductInfo();
                            cartProductInfo1.Selected = IsSelectCartItem(0, orderProductInfo.Pid, selectedCartItemKeyList);
                            cartProductInfo1.OrderProductInfo = orderProductInfo;
                            orderProductList[i] = null;
                            List<OrderProductInfo> giftList1 = new List<OrderProductInfo>();
                            //获取商品的赠品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 1 && item.ExtCode1 == orderProductInfo.ExtCode3)
                                {
                                    giftList1.Add(item);
                                    orderProductList[j] = null;
                                }
                            }
                            cartProductInfo1.GiftList = giftList1;
                            fullCutCartProductList.Add(cartProductInfo1);
                            //获取同一满减商品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 0 && item.ExtCode5 == orderProductInfo.ExtCode5)
                                {
                                    CartProductInfo cartProductInfo2 = new CartProductInfo();
                                    cartProductInfo2.Selected = IsSelectCartItem(0, item.Pid, selectedCartItemKeyList);
                                    cartProductInfo2.OrderProductInfo = item;
                                    orderProductList[j] = null;
                                    List<OrderProductInfo> giftList2 = new List<OrderProductInfo>();
                                    for (int k = 0; k < count; k++)
                                    {
                                        OrderProductInfo item2 = orderProductList[k];
                                        if (item2 != null && item2.Type == 1 && item2.ExtCode1 == item.ExtCode3)
                                        {
                                            giftList2.Add(item2);
                                            orderProductList[k] = null;
                                        }
                                    }
                                    cartProductInfo2.GiftList = giftList2;
                                    fullCutCartProductList.Add(cartProductInfo2);
                                }
                            }
                            cartFullCutInfo.FullCutCartProductList = fullCutCartProductList;

                            decimal selectedFullCutCartProductAmount = 0M;
                            foreach (CartProductInfo fullCutCartProductInfo in fullCutCartProductList)
                            {
                                if (fullCutCartProductInfo.Selected)
                                    selectedFullCutCartProductAmount += fullCutCartProductInfo.OrderProductInfo.DiscountPrice * fullCutCartProductInfo.OrderProductInfo.BuyCount;
                            }
                            if (fullCutPromotionInfo.LimitMoney3 > 0 && selectedFullCutCartProductAmount >= fullCutPromotionInfo.LimitMoney3)
                            {
                                cartFullCutInfo.IsEnough = true;
                                cartFullCutInfo.LimitMoney = fullCutPromotionInfo.LimitMoney3;
                                cartFullCutInfo.CutMoney = fullCutPromotionInfo.CutMoney3;
                            }
                            else if (fullCutPromotionInfo.LimitMoney2 > 0 && selectedFullCutCartProductAmount >= fullCutPromotionInfo.LimitMoney2)
                            {
                                cartFullCutInfo.IsEnough = true;
                                cartFullCutInfo.LimitMoney = fullCutPromotionInfo.LimitMoney2;
                                cartFullCutInfo.CutMoney = fullCutPromotionInfo.CutMoney2;
                            }
                            else if (selectedFullCutCartProductAmount >= fullCutPromotionInfo.LimitMoney1)
                            {
                                cartFullCutInfo.IsEnough = true;
                                cartFullCutInfo.LimitMoney = fullCutPromotionInfo.LimitMoney1;
                                cartFullCutInfo.CutMoney = fullCutPromotionInfo.CutMoney1;
                            }
                            else
                            {
                                cartFullCutInfo.IsEnough = false;
                                cartFullCutInfo.LimitMoney = fullCutPromotionInfo.LimitMoney1;
                                cartFullCutInfo.CutMoney = fullCutPromotionInfo.CutMoney1;
                            }

                            CartItemInfo cartItemInfo = new CartItemInfo();
                            cartItemInfo.Type = 3;
                            cartItemInfo.Item = cartFullCutInfo;
                            cartItemList.Add(cartItemInfo);
                        }
                        else//当满减促销活动不存在时,按照没有满减促销商品处理
                        {
                            List<OrderProductInfo> updateFullCutOrderProductList = new List<OrderProductInfo>();

                            orderProductInfo.ExtCode5 = 0;
                            updateFullCutOrderProductList.Add(orderProductInfo);

                            CartProductInfo cartProductInfo1 = new CartProductInfo();
                            cartProductInfo1.Selected = IsSelectCartItem(0, orderProductInfo.Pid, selectedCartItemKeyList);
                            cartProductInfo1.OrderProductInfo = orderProductInfo;
                            orderProductList[i] = null;
                            List<OrderProductInfo> giftList1 = new List<OrderProductInfo>();
                            //获取商品的赠品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 1 && item.ExtCode1 == orderProductInfo.ExtCode3)
                                {
                                    giftList1.Add(item);
                                    orderProductList[j] = null;
                                }
                            }
                            cartProductInfo1.GiftList = giftList1;

                            CartItemInfo cartItemInfo1 = new CartItemInfo();
                            cartItemInfo1.Type = 0;
                            cartItemInfo1.Item = cartProductInfo1;
                            cartItemList.Add(cartItemInfo1);

                            //获取同一满减商品
                            for (int j = 0; j < count; j++)
                            {
                                OrderProductInfo item = orderProductList[j];
                                if (item != null && item.Type == 0 && item.ExtCode5 == orderProductInfo.ExtCode5)
                                {
                                    item.ExtCode5 = 0;
                                    updateFullCutOrderProductList.Add(item);

                                    CartProductInfo cartProductInfo2 = new CartProductInfo();
                                    cartProductInfo2.Selected = IsSelectCartItem(0, item.Pid, selectedCartItemKeyList);
                                    cartProductInfo2.OrderProductInfo = item;
                                    orderProductList[j] = null;
                                    List<OrderProductInfo> giftList2 = new List<OrderProductInfo>();
                                    for (int k = 0; k < count; k++)
                                    {
                                        OrderProductInfo item2 = orderProductList[k];
                                        if (item2 != null && item2.Type == 1 && item2.ExtCode1 == item.ExtCode3)
                                        {
                                            giftList2.Add(item2);
                                            orderProductList[k] = null;
                                        }
                                    }
                                    cartProductInfo2.GiftList = giftList2;

                                    CartItemInfo cartItemInfo2 = new CartItemInfo();
                                    cartItemInfo2.Type = 0;
                                    cartItemInfo2.Item = cartProductInfo2;
                                    cartItemList.Add(cartItemInfo2);
                                }
                            }

                            //更新商品的满减促销活动
                            UpdateOrderProductFullCut(updateFullCutOrderProductList);
                        }

                        #endregion
                    }
                    else//非满赠和满减订单商品处理
                    {
                        #region 非满赠和满减订单商品处理

                        CartProductInfo cartProductInfo = new CartProductInfo();
                        cartProductInfo.Selected = IsSelectCartItem(0, orderProductInfo.Pid, selectedCartItemKeyList);
                        cartProductInfo.OrderProductInfo = orderProductInfo;
                        orderProductList[i] = null;
                        List<OrderProductInfo> giftList = new List<OrderProductInfo>();
                        //获取商品的赠品
                        for (int j = 0; j < count; j++)
                        {
                            OrderProductInfo item = orderProductList[j];
                            if (item != null && item.Type == 1 && item.ExtCode1 == orderProductInfo.ExtCode3)
                            {
                                giftList.Add(item);
                                orderProductList[j] = null;
                            }
                        }
                        cartProductInfo.GiftList = giftList;

                        CartItemInfo cartItemInfo = new CartItemInfo();
                        cartItemInfo.Type = 0;
                        cartItemInfo.Item = cartProductInfo;
                        cartItemList.Add(cartItemInfo);

                        #endregion
                    }
                }
                else if (orderProductInfo.Type == 3)//当商品是套装商品时
                {
                    #region 套装商品处理

                    CartSuitInfo cartSuitInfo = new CartSuitInfo();
                    cartSuitInfo.Checked = IsSelectCartItem(1, orderProductInfo.ExtCode1, selectedCartItemKeyList);
                    cartSuitInfo.PmId = orderProductInfo.ExtCode1;
                    cartSuitInfo.BuyCount = orderProductInfo.RealCount / orderProductInfo.ExtCode2;

                    decimal suitAmount = 0M;
                    List<CartProductInfo> cartProductList = new List<CartProductInfo>();
                    for (int j = 0; j < count; j++)
                    {
                        OrderProductInfo item = orderProductList[j];
                        //获取同一套装商品
                        if (item != null && item.Type == 3 && item.ExtCode1 == orderProductInfo.ExtCode1)
                        {
                            suitAmount += item.DiscountPrice * item.RealCount;

                            CartProductInfo cartProductInfo = new CartProductInfo();
                            cartProductInfo.Selected = cartSuitInfo.Checked;
                            cartProductInfo.OrderProductInfo = item;
                            orderProductList[j] = null;
                            List<OrderProductInfo> giftList = new List<OrderProductInfo>();
                            //获取商品的赠品
                            for (int k = 0; k < count; k++)
                            {
                                OrderProductInfo item2 = orderProductList[k];
                                if (item2 != null && item2.Type == 2 && item2.ExtCode1 == item.ExtCode2)
                                {
                                    giftList.Add(item2);
                                    orderProductList[k] = null;
                                }
                            }
                            cartProductInfo.GiftList = giftList;

                            cartProductList.Add(cartProductInfo);
                        }
                    }
                    cartSuitInfo.SuitPrice = suitAmount / cartSuitInfo.BuyCount;
                    cartSuitInfo.SuitAmount = suitAmount;
                    cartSuitInfo.CartProductList = cartProductList;

                    CartItemInfo cartItemInfo = new CartItemInfo();
                    cartItemInfo.Type = 1;
                    cartItemInfo.Item = cartSuitInfo;
                    cartItemList.Add(cartItemInfo);

                    #endregion
                }
            }
            cartItemList.Sort();

            foreach (CartItemInfo cartItemInfo in cartItemList)
            {
                if (cartItemInfo.Type == 0)
                {
                    CartProductInfo cartProductInfo = (CartProductInfo)cartItemInfo.Item;
                    if (cartProductInfo.Selected)
                    {
                        selectedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                        selectedOrderProductList.AddRange(cartProductInfo.GiftList);
                    }
                    else
                    {
                        remainedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                        remainedOrderProductList.AddRange(cartProductInfo.GiftList);
                    }
                }
                else if (cartItemInfo.Type == 1)
                {
                    CartSuitInfo cartSuitInfo = (CartSuitInfo)cartItemInfo.Item;
                    if (cartSuitInfo.Checked)
                    {
                        foreach (CartProductInfo cartProductInfo in cartSuitInfo.CartProductList)
                        {
                            selectedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                            selectedOrderProductList.AddRange(cartProductInfo.GiftList);
                        }
                    }
                    else
                    {
                        foreach (CartProductInfo cartProductInfo in cartSuitInfo.CartProductList)
                        {
                            remainedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                            remainedOrderProductList.AddRange(cartProductInfo.GiftList);
                        }
                    }
                }
                else if (cartItemInfo.Type == 2)
                {
                    CartFullSendInfo cartFullSendInfo = (CartFullSendInfo)cartItemInfo.Item;
                    if (cartFullSendInfo.FullSendMinorOrderProductInfo != null)
                    {
                        if (cartFullSendInfo.IsEnough)//当金额足够时才添加
                        {
                            selectedOrderProductList.Add(cartFullSendInfo.FullSendMinorOrderProductInfo);
                        }
                        else
                        {
                            remainedOrderProductList.Add(cartFullSendInfo.FullSendMinorOrderProductInfo);
                        }
                    }
                    foreach (CartProductInfo cartProductInfo in cartFullSendInfo.FullSendMainCartProductList)
                    {
                        if (cartProductInfo.Selected)
                        {
                            selectedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                            selectedOrderProductList.AddRange(cartProductInfo.GiftList);
                        }
                        else
                        {
                            remainedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                            remainedOrderProductList.AddRange(cartProductInfo.GiftList);
                        }
                    }
                }
                else if (cartItemInfo.Type == 3)
                {
                    CartFullCutInfo cartFullCutInfo = (CartFullCutInfo)cartItemInfo.Item;
                    foreach (CartProductInfo cartProductInfo in cartFullCutInfo.FullCutCartProductList)
                    {
                        if (cartProductInfo.Selected)
                        {
                            selectedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                            selectedOrderProductList.AddRange(cartProductInfo.GiftList);
                        }
                        else
                        {
                            remainedOrderProductList.Add(cartProductInfo.OrderProductInfo);
                            remainedOrderProductList.AddRange(cartProductInfo.GiftList);
                        }
                    }
                }
            }

            return cartItemList;
        }
コード例 #21
0
        public ProductDetailVM(string productId)
        {
            //CusPriceVisible = GlobalVariables.LoggedUser.userType == "0";
            MemberPriceVisible = GlobalVariables.IsLogged;
            VisitorVisible     = !MemberPriceVisible;

            Product         = new ProductInfo();
            StarSource      = "star_gray.png";
            IsCollected     = false;
            CusPriceVisible = false;

            BackCommand = new Command(() =>
            {
                Application.Current.MainPage.Navigation.PopModalAsync();
            }, () => { return(true); });

            AddToCartCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    var page = new AddToCartView(Product);
                    PopupNavigation.Instance.PushAsync(page);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            BuyCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    List <CartItemInfo> productList = new List <CartItemInfo>();

                    CartItemInfo cartItemInfo = new CartItemInfo();
                    Tools.AutoMapping <ProductInfo, CartItemInfo>(Product, cartItemInfo);
                    cartItemInfo.productNum = 1;
                    cartItemInfo.productImg = Product.productImageBig;

                    productList.Add(cartItemInfo);

                    OrderingPage orderingPage = new OrderingPage(productList);
                    Application.Current.MainPage.Navigation.PushModalAsync(orderingPage);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            ShareCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    string para = "?productId=" + Product.productId + "&userId=" + GlobalVariables.LoggedUser.id;
                    MessagingCenter.Send(new object(), "Register");//首先进行注册,然后订阅注册的结果。
                    MessagingCenter.Send(new object(), "ShareToFriend", para);
                }
                else
                {
                    LoginPage loginPage = new LoginPage();
                    Application.Current.MainPage.Navigation.PushModalAsync(loginPage);
                }
            }, () => { return(true); });

            CallServiceCommand = new Command(() =>
            {
                try
                {
                    PhoneDialer.Open("18080961008");
                }
                catch (ArgumentNullException)
                {
                    // Number was null or white space
                    CrossToastPopUp.Current.ShowToastError("无联系方式", ToastLength.Short);
                }
                catch (FeatureNotSupportedException)
                {
                    // Phone Dialer is not supported on this device.
                    CrossToastPopUp.Current.ShowToastError("该设备不支持拨号", ToastLength.Short);
                }
                catch (Exception)
                {
                    // Other error has occurred.
                    CrossToastPopUp.Current.ShowToastError("出现其他错误", ToastLength.Short);
                }
            }, () => { return(true); });

            StarCommand = new Command(() =>
            {
                Collect();
            }, () => { return(true); });

            SpeakCommand = new Command(() =>
            {
                if (GlobalVariables.IsLogged)
                {
                    DependencyService.Get <ITextToSpeech>().Speak(Product.productName + " 市场价" + Product.mallPrice + "元 会员价" + Product.memberPrice + "元");
                }
                else
                {
                    DependencyService.Get <ITextToSpeech>().Speak(Product.productName + " 市场价" + Product.mallPrice + "元");
                }
            }, () => { return(true); });

            InitProductDetailPageAsync(productId);
        }