Beispiel #1
0
        private void PlusBtn_Click(object sender, EventArgs e)
        {
            //Finding the required parent controls
            Button          btnSender = (Button)sender;
            GroupBox        gbSender  = (GroupBox)btnSender.Parent;
            BasketGBControl endParent = (BasketGBControl)gbSender.Parent;
            Product         prod      = endParent.paramProd;

            //Looping through the available products o find the right one
            //Decreasing its quantity, increasing the quantity in the basket
            //Or showing the error message if no more items can be added to the basket
            foreach (Product productAv in ShopForm.AvailableProducts)
            {
                if (productAv.Equals(prod))
                {
                    if (productAv.Quantity > 0)
                    {
                        prod.Quantity++;
                        endParent.TrueQtyLbl.Text = prod.Quantity.ToString();
                        productAv.Quantity--;
                        ShopGBControl.QtyChange(endParent, productAv);
                        ShopForm.ChangePriceWeightLbls(endParent, Basket.BasketList);
                        return;
                    }
                    else
                    {
                        MessageBox.Show($"Sorry, {prod.Name.ToLower()} is out of stock.");
                        return;
                    }
                }
            }
        }
Beispiel #2
0
        public static void QtyChange(Object obj, Product prod)
        {
            //Changes the quantity shown in the ShopGBControl (Available products section)
            //Reveives BasketGBControl as sender
            BasketGBControl bgbcSender = (BasketGBControl)obj;
            FlowLayoutPanel flpSender  = (FlowLayoutPanel)bgbcSender.Parent;
            Form            endParent  = (Form)flpSender.Parent;
            var             flpList    = endParent.Controls.OfType <FlowLayoutPanel>();

            //Loops through the FlowLayoutPanels in the ShoForm
            //Selects the necessary, then loops through the ShopGBControls in it
            //Upon finding the required Control, changes its Quantity label
            foreach (FlowLayoutPanel flp in flpList)
            {
                if (flp.Name == "ProductsPanel")
                {
                    var sgbcList = flp.Controls.OfType <ShopGBControl>();
                    foreach (ShopGBControl sgbc in sgbcList)
                    {
                        if (sgbc.Name == prod.Name)
                        {
                            sgbc.TrueQtyLbl.Text = prod.Quantity.ToString();
                        }
                    }
                }
            }
        }
Beispiel #3
0
        private void MinusBtn_Click(object sender, EventArgs e)
        {
            //Finding the required parent controls
            Button          btnSender = (Button)sender;
            GroupBox        gbSender  = (GroupBox)btnSender.Parent;
            BasketGBControl endParent = (BasketGBControl)gbSender.Parent;
            FlowLayoutPanel flpParent = (FlowLayoutPanel)endParent.Parent;
            Product         prod      = endParent.paramProd;

            //Checking the quantity of item in the basket and performing necessary actions accordingly
            //Decreasing quantity in basket, increasing quantity in available products, rerendering the labels
            //And, if necessary, removing the item from the basket
            if (prod.Quantity > 1)
            {
                prod.Quantity--;
                endParent.TrueQtyLbl.Text = prod.Quantity.ToString();
                foreach (Product productAv in ShopForm.AvailableProducts)
                {
                    if (productAv.Equals(prod))
                    {
                        productAv.Quantity++;
                        ShopGBControl.QtyChange(endParent, productAv);
                        ShopForm.ChangePriceWeightLbls(endParent, Basket.BasketList);
                        return;
                    }
                }
            }
            else if (prod.Quantity == 1)
            {
                foreach (Product productAv in ShopForm.AvailableProducts)
                {
                    if (productAv.Equals(prod))
                    {
                        productAv.Quantity++;
                        ShopGBControl.QtyChange(endParent, productAv);
                        ShopForm.ChangePriceWeightLbls(endParent, Basket.BasketList);
                        Basket.BasketList.Remove(prod);
                        flpParent.Controls.Remove(endParent);
                        return;
                    }
                }
            }
        }