/// <summary>
        /// Removes the most recent entry with the matching name from the item roster.
        /// </summary>
        /// <param name="itemName"></param>
        public void RemoveLast(string itemName)
        {
            int    i    = listOfItems.Count;
            string name = "";

            while (i > 0)
            {
                i--;

                bool match = listOfItems[i].Match(itemName);

                if (match)
                {
                    name = listOfItems[i].GetName();

                    listOfItems.RemoveAt(i);

                    break;
                }
            }

            itemRosterTally[name]--;
            itemRosterTallyUsed[name]--;

            Consolidate(Database_API.GetItem(itemName).name, TALLY_STATE.REMOVE);
        }
        /// <summary>
        /// Gets the price of the purchase.
        /// </summary>
        /// <returns></returns>
        public float GetPrice()
        {
            Item  itemdb = Database_API.GetItem(itemRef);
            float total  = itemdb.price;

            if (itemdb.priceByWeight)
            {
                total *= quantity;
            }

            if (isDiscounted && !isDeferHeader)
            {
                switch (special_ID.discount_type)
                {
                case Special.DISCOUNT_TYPE.REDUCE_BY_DOLLAR:
                    total -= special_ID.itemCostChange;
                    break;

                case Special.DISCOUNT_TYPE.REDUCE_BY_PERCENTAGE:
                    total *= (100 - special_ID.itemCostChange) * 0.01f;
                    break;

                case Special.DISCOUNT_TYPE.SET_TO_AMOUNT:
                    total = special_ID.itemCostChange;
                    break;
                }
            }
            return(total);
        }
        public float GetOriginalPrice()
        {
            Item  itemdb = Database_API.GetItem(itemRef);
            float total  = itemdb.price;

            if (itemdb.priceByWeight)
            {
                total *= quantity;
            }

            return(total);
        }
Exemple #4
0
        /// <summary>
        /// Writes a list of all items available in the database.
        /// </summary>
        /// <returns>A string of all items in the database.</returns>
        private static string WriteItems()
        {
            StringBuilder builder = new StringBuilder();

            int h = 0;
            int i = Database_API.GetItemCount();

            while (h < i)
            {
                Item item = Database_API.GetItem(h);
                builder.Append(DisplayOrganizer.AddEntry(item.name, SPACING_NAME));
                builder.Append(DisplayOrganizer.AddEntry(item.price.ToString(), SPACING_VALUE));
                builder.AppendLine(DisplayOrganizer.AddMark(item.priceByWeight));
                h++;
            }
            return(builder.ToString());
        }
        /// <summary>
        /// Adds an item into the cart of the given number (of items).
        /// </summary>
        /// <param name="itemName">The item being purchased.</param>
        /// <param name="itemNumber">How many is being purchased.</param>
        public void Add(string itemName, float itemNumber = 1)
        {
            ItemInCart newItem       = new ItemInCart(Database_API.GetItem(itemName), itemNumber);
            string     itemNameClean = newItem.GetName();

            listOfItems.Add(newItem);

            if (itemRosterTally.ContainsKey(itemNameClean))
            {
                itemRosterTally[itemNameClean]++;
                itemRosterTallyUsed[itemNameClean]++;
            }
            else
            {
                itemRosterTally.Add(itemNameClean, 1);
                itemRosterTallyUsed.Add(itemNameClean, 1);
            }

            Consolidate(itemNameClean, TALLY_STATE.ADD);
        }
Exemple #6
0
        /// <summary>
        /// Buy an item.
        /// </summary>
        private static void WriteAction_PlaceOrder()
        {
            Console.Write("Enter the name of the item being purchased: ");
            string itemName = Console.ReadLine().Trim();


            bool hasItem = Database_API.TryGetItem(itemName);

            if (!hasItem)
            {
                Console.WriteLine("No such item exists in the database.");
            }
            else
            {
                if (Database_API.GetItem(itemName).priceByWeight)
                {
                    Console.Write("enter the weight of the purchase: ");
                    float quantity = float.Parse(Console.ReadLine());
                    pim.Add(itemName, quantity);
                }
                else
                {
                    Console.Write("enter how many items are being purchased. ");
                    int quantity = int.Parse(Console.ReadLine());

                    while (quantity > 0)
                    {
                        pim.Add(itemName);
                        quantity--;
                    }
                }
            }

            Console.WriteLine("Purchases added. Please review the receipt for specifics.");
            WriteAction_Total();
        }