Exemplo n.º 1
0
        public async void AddBasket(long ProductID, decimal Amount)
        {
            InterfaceToDataBaseBasketMethods Methods = new InterfaceToDataBaseBasketMethods();

            if (!(await(Methods.MoveProductToBasket(loggedUserData.UserID, ProductID, Amount))))
            {
                throw new ArgumentException();
            }
            basketSizeLabel.Text = Methods.CountBaskets(loggedUserData.UserID).Result.ToString();
        }
Exemplo n.º 2
0
        private async void ForceBasketRefresh()
        {
            InterfaceToDataBaseBasketMethods BasketMethods = new InterfaceToDataBaseBasketMethods();

            basketSizeLabel.Text = (await BasketMethods.CountBaskets(loggedUserData.UserID)).ToString();
            BasketUserControl newUserControl = new BasketUserControl(ref loggedUserData);

            newUserControl.Dock = DockStyle.Fill;
            userControlPanel.Controls.Clear();
            userControlPanel.Controls.Add(newUserControl);
        }
Exemplo n.º 3
0
        public async Task <decimal> GetBasketAmount(long ProductID)
        {
            InterfaceToDataBaseBasketMethods Methods = new InterfaceToDataBaseBasketMethods();

            return(await Methods.AmountOfProductInUserBaskets(loggedUserData.UserID, ProductID));

            //Basket found = loggedUserBasket.Find(x => x.ProductID == ProductID);
            //if (found != null)
            //    return found.Amount;
            //return 0;
        }
Exemplo n.º 4
0
        public async void CommitSale()
        {
            InterfaceToDataBaseSaleMethods Methods = new InterfaceToDataBaseSaleMethods();
            await Methods.CreateSale(loggedUserData.UserID);

            //loggedUserBasket.Clear();
            //basketSizeLabel.Text = loggedUserBasket.Count.ToString();
            InterfaceToDataBaseBasketMethods BasketMethods = new InterfaceToDataBaseBasketMethods();

            basketSizeLabel.Text = BasketMethods.CountBaskets(loggedUserData.UserID).Result.ToString();
            SetHomeUserControl();
        }
Exemplo n.º 5
0
        //private List<Basket> loggedUserBasket;
        public MainWindowForm(User loggedUserData)
        {
            InitializeComponent();
            this.loggedUserData = loggedUserData;
            profileButton.Text  = this.loggedUserData.UserName;
            if (this.loggedUserData.Type == 1)
            {
                adminButton.Visible = true;
            }
            InterfaceToDataBaseBasketMethods Methods = new InterfaceToDataBaseBasketMethods();

            //loggedUserBasket = Methods.RetrieveBaskets(loggedUserData.UserID).Result;
            //bool deleted = Methods.DeleteBaskets(loggedUserData.UserID).Result;
            //basketSizeLabel.Text = loggedUserBasket.Count.ToString();
            basketSizeLabel.Text = Methods.CountBaskets(loggedUserData.UserID).Result.ToString();
            SetHomeUserControl();
        }
Exemplo n.º 6
0
        public async void RemoveBasket(Basket basketDataObject, Product modifiedProduct = null)
        {
            //InterfaceToDataBaseProductMethods Methods = new InterfaceToDataBaseProductMethods();
            //if (modifiedProduct == null)
            //    modifiedProduct = await Methods.GetProductData(basketDataObject.ProductID);
            //await Methods.ProductModification(basketDataObject.ProductID, null, null, null, null, basketDataObject.Amount + modifiedProduct.Amount);
            ////loggedUserBasket.Remove(basketDataObject);
            ////basketSizeLabel.Text = loggedUserBasket.Count.ToString();
            //InterfaceToDataBaseBasketMethods BasketMethods = new InterfaceToDataBaseBasketMethods();
            //await BasketMethods.DeleteBasket(basketDataObject.BasketID);

            InterfaceToDataBaseBasketMethods Methods = new InterfaceToDataBaseBasketMethods();

            if (!(await(Methods.MoveProductFromBasket(loggedUserData.UserID, basketDataObject.ProductID, basketDataObject.Amount))))
            {
                throw new ArgumentException();
            }
            ForceBasketRefresh();
        }
Exemplo n.º 7
0
        //public async void ModifyBasket(Basket basketDataObject, decimal newAmount, Product modifiedProduct = null)
        //{
        //    InterfaceToDataBaseProductMethods Methods = new InterfaceToDataBaseProductMethods();
        //    if (modifiedProduct == null)
        //        modifiedProduct = await Methods.GetProductData(basketDataObject.ProductID);
        //    await Methods.ProductModification(basketDataObject.ProductID, null, null, null, null, modifiedProduct.Amount + basketDataObject.Amount - newAmount);
        //    //int index = loggedUserBasket.FindIndex(x => x.BasketID == basketDataObject.BasketID);
        //    //loggedUserBasket[index].Amount = newAmount;
        //    //loggedUserBasket[index].Date = DateTime.Now;
        //    InterfaceToDataBaseBasketMethods BasketMethods = new InterfaceToDataBaseBasketMethods();
        //    await BasketMethods.ModifyBasket(basketDataObject.BasketID, newAmount);
        //    ForceBasketRefresh();
        //}
        public async void MoveProductsToFromBasket(long ProductID, decimal Amount)
        {
            InterfaceToDataBaseBasketMethods BasketMethods = new InterfaceToDataBaseBasketMethods();
            bool result = false;

            if (Amount < 0)
            {
                result = await BasketMethods.MoveProductFromBasket(loggedUserData.UserID, ProductID, -Amount);
            }
            else if (Amount > 0)
            {
                result = await BasketMethods.MoveProductToBasket(loggedUserData.UserID, ProductID, Amount);
            }
            if (!result)
            {
                throw new ArgumentException();
            }
            ForceBasketRefresh();
        }
Exemplo n.º 8
0
        public BasketUserControl(ref User loggedUserData)
        {
            InitializeComponent();
            basketsFlowPanel.Controls.Add(new BasketDataUserControl());
            InterfaceToDataBaseBasketMethods Methods = new InterfaceToDataBaseBasketMethods();

            loggedUserBasket = Methods.RetrieveBaskets(loggedUserData.UserID).Result;
            if (loggedUserBasket.Count != 0)
            {
                foreach (Basket basket in loggedUserBasket)
                {
                    BasketDataUserControl newBasket = new BasketDataUserControl(basket);
                    basketsFlowPanel.Controls.Add(newBasket);
                    sum += newBasket.sum;
                }
                sumPriceLabel.Text = "Łączny koszt transakcji: " + sum + "zł";
            }
            else
            {
                sumPriceLabel.Visible           = false;
                finishTransactionButton.Text    = "Koszyk pusty";
                finishTransactionButton.Enabled = false;
            }
        }