Пример #1
0
        /// <summary>
        /// reverts the last additions
        /// keep imaginary "history"-product with properties WhereTo(to the Basket or back from the basket) Quantity Name
        /// well, since the controls inside of a panel are generated based on the array they should share the same indexes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUndo_Click(object sender, EventArgs e)
        {
            // keep imaginary "history"-product with properties WhereTo(to the Basket or back from the basket) Quantity Name
            // well, since the controls inside of a panel are generated based on the array they should share the same indexes
            if (actions.Count > 0)
            {
                HistoryProduct temp = this.actions.Pop();
                this.ModifyControlQuantity(temp.Name, temp.Quantity);
                // done adjusting

                // make it objects
                Product prodInBasket = this.chosenShop.getProductByName(temp.Name, this.chosenShop.Basket);
                if (prodInBasket != null)
                {
                    prodInBasket.LowerQuantityBy(temp.Quantity);
                    if (prodInBasket.Quantity == 0)
                    {
                        this.chosenShop.Basket.Remove(prodInBasket);
                    }
                }


                temp.ChangeStack(undoneActions);
                // very bad to do - since will a lot of time, but for now - it's okay
                this.UpdateBasket();
            }
            else
            {
                this.LogMessage("Nothing to undo.");
            }
        }
Пример #2
0
 public Product(HistoryProduct hp)
 {
     this.Id       = hp.Id;
     this.Name     = hp.Name;
     this.Price    = hp.Price;
     this.Quantity = hp.Quantity;
 }
Пример #3
0
        /// <summary>
        /// Generally we undo the undone actions
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRedo_Click(object sender, EventArgs e)
        {
            // keep imaginary "history"-product with properties WhereTo(to the Basket or back from the basket) Quantity Name
            // well, since the controls inside of a panel are generated based on the array they should share the same indexes
            if (undoneActions.Count > 0)
            {
                HistoryProduct historyProd      = this.undoneActions.Pop();
                int            prodAndControlId = this.chosenShop.Stock.FindIndex(p => p.Name == historyProd.Name);
                // managing the quantity in the display
                this.ModifyControlQuantity(historyProd.Name, -(historyProd.Quantity));
                // done adjusting

                chosenShop.AddToBasket(new Product(historyProd));


                historyProd.ChangeStack(actions);
                // very bad to do - since will a lot of time, but for now - it's okay
                this.UpdateBasket();
            }
            else
            {
                this.LogMessage("Nothing to redo.");
            }
        }