示例#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;
                    }
                }
            }
        }
示例#2
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;
                    }
                }
            }
        }