示例#1
0
 public static int Add(BasketDB Content)
 {
     lock (SqlConnect.locker) {
         if (BasketDB.GetItemByID(Content.Id) != null)
         {
             SqlConnect.database.Update(Content);
             return(Content.Id);
         }
         else
         {
             return(SqlConnect.database.Insert(Content));
         }
     }
 }
示例#2
0
        public static void Update(BasketDB entity, int productID, int SizeID)
        {
            BasketDB basket = SqlConnect.database.Table <BasketDB>().FirstOrDefault(g => g.ProductID == productID && g.SizeID == SizeID);

            if (basket == null)
            {
                return;
            }

            basket.SizeID   = entity.SizeID;
            basket.SizeName = entity.SizeName;
            basket.Quantity = entity.Quantity;
            Update(basket);
        }
示例#3
0
        public static void AddCount(BasketDB entity)
        {
            List <BasketDB> basketDBList = GetItems();
            BasketDB        basketDB     = basketDBList.SingleOrDefault(g => g.ProductID == entity.ProductID && g.SizeID == entity.SizeID);

            if (basketDB != null)
            {
                basketDB.Quantity += entity.Quantity;
                Update(basketDB);
            }
            else
            {
                Add(entity);
            }
        }
示例#4
0
        async void ClickDelete(object sender, EventArgs e)
        {
            if (!isError && !await OnePage.mainPage.DisplayMessageQuestion("Подтвердите действие", "Вы действительно хотите удалить этот товар?"))
            {
                return;
            }

            if (User.Singleton != null)
            {
                if (BasketItem.Quantity > 0)
                {
                    BasketItem.Quantity = -BasketItem.Quantity;
                }
                try {
                    await Basket.PushToBasketAsync(BasketItem);
                } catch (Exception) {
                    eventRefresh  = null;
                    eventRefresh += (obj, evn) => {
                        Button content = obj as Button;
                        content.IsEnabled = false;
                        ClickDelete(sender, e);
                    };
                    OnePage.redirectApp.basketView.Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                    isError = true;
                    return;
                }
            }
            else
            {
                BasketDB basketDB;
                if (BasketItem.SizeValueId == null)
                {
                    basketDB = BasketDB.GetItemByID(BasketItem.ProductID);
                }
                else
                {
                    basketDB = BasketDB.GetItem(BasketItem.ProductID, BasketItem.SizeValueId ?? 0);
                }
                BasketDB.DeleteItem(basketDB.Id);
            }
            OnePage.redirectApp.RedirectToPage(PageName.Basket, true, true);

            if (isError)
            {
                OnePage.redirectApp.basketView.Content = OnePage.redirectApp.basketView.mainGrid;
            }
        }
示例#5
0
        public static async Task LoadBasket()
        {
            try {
                List <BasketDB> basketDBList      = BasketDB.GetItems();
                List <Basket>   basketProfileList = await Basket.GetProductInBasketAsync();

                int[] produtIDs = basketDBList.Select(g => g.ProductID).Distinct().ToArray();
                if (produtIDs.Length == 0)
                {
                    return;
                }
                List <Product> productList = await Product.GetProductsByIDsListAsync(produtIDs);

                int[] deleteBasketDBList = await Basket.UpdateBasketAsync(basketDBList, basketProfileList, productList);

                BasketDB.DeleteItems(deleteBasketDBList);
            } catch {
            }
        }
示例#6
0
        public static List <Basket> GetItemsToBasketList()
        {
            List <Basket>   basketList   = new List <Basket>();
            List <BasketDB> basketDBList = BasketDB.GetItems();

            foreach (BasketDB entity in basketDBList)
            {
                Basket basket = new Basket {
                    ProductID      = entity.ProductID,
                    Article        = entity.Article,
                    ProductName    = entity.ProductName,
                    SizeName       = entity.SizeName,
                    ProductImage   = entity.Image,
                    SizeValueId    = entity.SizeID,
                    Price          = entity.Price,
                    Quantity       = entity.Quantity,
                    ProductExpress = entity.ProductExpress,
                    IsSchedule     = entity.IsSchedule,
                    IsLocalBasket  = true
                };
                basketList.Add(basket);
            }
            return(basketList);
        }
示例#7
0
        private async void OnStepperValueChanged(int value)
        {
            btnPlus.IsEnabled  = false;
            btnMinus.IsEnabled = false;

            if (!BasketItem.IsLocalBasket)                      // Товар в глобальной корзине
            {
                Basket basketToServer = new Basket {
                    Id          = BasketItem.Id,
                    ProductID   = BasketItem.ProductID,
                    SizeValueId = BasketItem.SizeValueId,
                    Quantity    = value,
                    Comment     = BasketItem.Comment
                };
                ContentAndHeads contentAndHeads;
                try {
                    contentAndHeads = await Basket.PushToBasketAsync(basketToServer);

                    isError = false;
                } catch (Exception) {
                    eventRefresh  = null;
                    eventRefresh += (sender, e) => {
                        Button content = sender as Button;
                        content.IsEnabled = false;
                        OnStepperValueChanged(value);
                    };
                    OnePage.redirectApp.basketView.Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                    isError = true;
                    return;
                }
                if (contentAndHeads.requestStatus == System.Net.HttpStatusCode.OK)
                {
                    EditTotal(value);
                }
            }
            else                    // Товар в локальной корзине
            {
                BasketDB basketDB = new BasketDB {
                    ProductID = BasketItem.ProductID,
                    SizeID    = BasketItem.SizeValueId ?? 0,
                    Price     = BasketItem.Price,
                    Quantity  = value
                };
                EditTotal(value);
                BasketDB.AddCount(basketDB);
                BasketItem.Quantity += value;
            }

            entCount.Text = BasketItem.Quantity.ToString();
            if (BasketItem.Quantity < BasketItem.ProductActualQuantity)
            {
                btnPlus.IsEnabled = true;
            }
            if (BasketItem.Quantity > 1)
            {
                btnMinus.IsEnabled = true;
            }

            if (!isError)
            {
                OnePage.redirectApp.basketView.Content = OnePage.redirectApp.basketView.mainGrid;
            }
        }
示例#8
0
 public static int Update(BasketDB Content)
 {
     return(SqlConnect.database.Update(Content));
 }
示例#9
0
        async Task AddToBasket(int maxCountProduct)
        {
            /// Если пользователь не зарегистрирован или товар из локальной корзины
            if (User.Singleton == null || (oldBasket != null && oldBasket.IsLocalBasket))
            {
                BasketDB basketBD = new BasketDB {
                    ProductID      = ProductItem.ProductsID,
                    Article        = ProductItem.Article,
                    ProductName    = ProductItem.productsDescription.Name,
                    SizeName       = selectSize.Value,
                    Image          = ProductItem.Image,
                    SizeID         = selectSize.Key,
                    Price          = ProductItem.Price,
                    Quantity       = int.Parse(entCount.Text),
                    ProductExpress = ProductItem.Express,
                    IsSchedule     = ProductItem.SchedulesList.Count > 0
                };
                /// Если мы изменяем размер товара в корзине
                if (oldBasket != null)
                {
                    if (oldBasket.SizeValueId != selectSize.Key || oldBasket.Quantity != basketBD.Quantity)
                    {
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basketBD.Quantity > maxCountProduct)
                        {
                            basketBD.Quantity = maxCountProduct;
                        }
                        BasketDB.Update(basketBD, oldBasket.ProductID, oldBasket.SizeValueId ?? 0);
                    }
                    OnePage.redirectApp.BackToHistory();
                    return;
                }
                else
                {
                    BasketDB basketProfile;
                    if (basketBD.SizeID == 0)
                    {
                        basketProfile = BasketDB.GetItemByID(basketBD.ProductID);
                    }
                    else
                    {
                        basketProfile = BasketDB.GetItem(basketBD.ProductID, basketBD.SizeID);
                    }

                    if (basketProfile != null)
                    {
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basketBD.Quantity + basketProfile.Quantity > maxCountProduct)
                        {
                            basketBD.Quantity = maxCountProduct - basketProfile.Quantity;
                        }
                    }
                    BasketDB.AddCount(basketBD);
                }
            }
            else                 /// Если залогинен
            {
                Basket basket = new Basket {
                    ProductID   = ProductItem.ProductsID,
                    SizeValueId = selectSize.Key,
                    Quantity    = int.Parse(entCount.Text)
                };
                /// Если мы изменяем размер товара в корзине
                if (oldBasket != null)
                {
                    if (oldBasket.SizeValueId != selectSize.Key || oldBasket.Quantity != basket.Quantity)
                    {
                        /// Удаляем позицию товара из заказа
                        oldBasket.Quantity = -oldBasket.Quantity;
                        try {
                            await Basket.PushToBasketAsync(oldBasket);
                        } catch (Exception) {
                            eventRefresh  = null;
                            eventRefresh += (obj, evn) => {
                                Button content = obj as Button;
                                content.IsEnabled = false;
                                AddToBasket(maxCountProduct).Wait();
                            };
                            Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                            return;
                        }
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basket.Quantity > maxCountProduct)
                        {
                            basket.Quantity = maxCountProduct;
                        }
                        try {
                            await Basket.PushToBasketAsync(basket);
                        } catch (Exception) {
                            eventRefresh  = null;
                            eventRefresh += (obj, evn) => {
                                Button content = obj as Button;
                                content.IsEnabled = false;
                                AddToBasket(maxCountProduct).Wait();
                            };
                            Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                            return;
                        }
                    }
                    OnePage.redirectApp.BackToHistory();
                    return;
                }
                else                     /// Если перешли в товар НЕ из корзины
                {
                    List <Basket> basketProfileList;
                    try {
                        basketProfileList = await Basket.GetProductInBasketAsync();
                    } catch (Exception) {
                        eventRefresh  = null;
                        eventRefresh += (obj, evn) => {
                            Button content = obj as Button;
                            content.IsEnabled = false;
                            AddToBasket(maxCountProduct).Wait();
                        };
                        Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                        return;
                    }
                    Basket basketProfile;
                    if (basket.SizeValueId != null)
                    {
                        basketProfile = basketProfileList.SingleOrDefault(g => g.ProductID == basket.ProductID && g.SizeValueId == basket.SizeValueId);
                    }
                    else
                    {
                        basketProfile = basketProfileList.SingleOrDefault(g => g.ProductID == basket.ProductID);
                    }

                    if (basketProfile != null)
                    {
                        /// Не дает добавить товаров больше чем они есть на складе
                        if (basket.Quantity + basketProfile.Quantity > maxCountProduct)
                        {
                            basket.Quantity = maxCountProduct - basketProfile.Quantity;
                        }
                    }
                    try {
                        await Basket.PushToBasketAsync(basket);
                    } catch (Exception) {
                        eventRefresh  = null;
                        eventRefresh += (obj, evn) => {
                            Button content = obj as Button;
                            content.IsEnabled = false;
                            AddToBasket(maxCountProduct).Wait();
                        };
                        Content = OnePage.mainPage.ShowMessageError(eventRefresh);
                        return;
                    }
                }
            }
        }