Exemplo n.º 1
0
        /// <summary>
        /// Updates the state and performs actions based on it.
        /// </summary>
        public void update()
        {
            CashierState state = _cashierModel.State;

            switch (state)
            {
            case CashierState.Success:
                Receipt r = new Receipt(_cashierModel.GetCurrentSale());
                r.Show();

                uxCart.Items.Clear();
                uxTotalCost.Text    = "Total Cost: $0.00";
                _cashierModel.State = CashierState.Initial;
                break;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds items to a sale and adds the sale to the sales database
        /// </summary>
        public void AddItem()
        {
            _cHan(_date);
            Dictionary <string, double> items = _cm.GetItemsForSale();

            Console.Write("Enter the item and quantity seperated by a comma(,): ");
            string[] item = Console.ReadLine().Split(',');
            if (items.ContainsKey(item[0]))
            {
                int quantity = 0;
                int.TryParse(item[1], out quantity);
                _aHan(item[0], quantity);
            }
            Sale        curSale  = _cm.GetCurrentSale();
            List <Item> curItems = null;

            while (item[0][0] != 'C')
            {
                try
                {
                    curItems = curSale.GetItems();
                    Console.Write("\nName\tQuantity\tPrice");
                    foreach (Item i in curItems)
                    {
                        Console.Write("\n{0}\t{1}\t{2}", i.Name, i.Quantity, i.Price.ToString("C"));
                    }
                    Console.Write("\nEnter the next item and quantity, ");
                    Console.Write("\nenter 'R' to remove a item, ");
                    Console.Write("\nenter 'C' to checkout: ");
                    item = Console.ReadLine().Split(',');
                    switch (item[0])
                    {
                    case "C":
                        _cmHan();
                        curItems = curSale.GetItems();
                        Console.Write("\nName\tQuantity\tPrice");
                        foreach (Item i in curItems)
                        {
                            Console.Write("\n{0}\t{1}\t{2}", i.Name, i.Quantity, i.Price.ToString("C"));
                        }
                        Console.WriteLine("\nSales ID: {0}", curSale.ID);
                        Console.WriteLine("\nTotal: {0}", curSale.Total().ToString("C"));
                        break;

                    case "R":
                        Console.Write("\nEnter the item and quantity to remove seperated by a comma(,): ");
                        item = Console.ReadLine().Split(',');
                        _rHan(item[0], Convert.ToInt32(item[1]));
                        break;

                    default:
                        if (items.ContainsKey(item[0]))
                        {
                            int quantity = 0;
                            int.TryParse(item[1], out quantity);
                            _aHan(item[0], quantity);
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Invalid Entry");
                }
            }
        }