/// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Write the prompt needed to add an item into the database.
        /// </summary>
        private static void WriteAction_Add_To_DB_Item()
        {
            Console.WriteLine("Note that if there is duplicates within the database, then then new entry" +
                              "will replace the old one.");
            Console.Write("Enter the name of your item: ");
            string name = Console.ReadLine();

            Console.Write("Is the item priced by weight? (y/n, n default): ");
            string byWeight = Console.ReadLine();

            Console.Write("Enter the price of the item: ");
            string price = Console.ReadLine();

            bool weighted = false;

            if (byWeight.TrimStart().ToLower()[0] == 'y')
            {
                weighted = true;
            }
            float value = float.Parse(price);

            Database_API.AddItem(name, value, weighted);

            Console.WriteLine("Adding complete.");
        }
        /// <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);
        }
        /// <summary>
        /// Adds a special as a token into the list of tokens.
        /// </summary>
        /// <param name="token">The special we want tokenized.</param>
        public void AddToken(string token)
        {
            bool duplicate = HasToken(token);

            if (!duplicate)
            {
                listOfTokens.Add(new SpecialToken(Database_API.GetSpecial(token)));
            }
            else
            {
                listOfTokens[HasTokenPosition(token)].Increment();
            }
        }
Beispiel #6
0
        /// <summary>
        /// Writes a list of all specials available in the database.
        /// </summary>
        /// <returns></returns>
        private static string WriteSpecials()
        {
            StringBuilder builder = new StringBuilder();

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

            while (h < i)
            {
                Special item = Database_API.GetSpecial(h);
                builder.Append(DisplayOrganizer.AddEntry(item.itemAffected, SPACING_NAME));
                builder.AppendLine(FormatSP(item, SPACING_NAME));
                h++;
            }
            return(builder.ToString());
        }
Beispiel #7
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);
        }
Beispiel #9
0
        public static void BuildData()
        {
            if (!builtItems)
            {
                //Items that sell by weight
                Database_API.AddItem("Beef", 10, true);
                Database_API.AddItem("Chicken", 10, true);
                Database_API.AddItem("Peas", 10, true);

                //Items that sell by unit
                Database_API.AddItem("Soup", 5);
                Database_API.AddItem("Pencils", 6);
                Database_API.AddItem("Carpet", 100);
                Database_API.AddItem("Candy", 4);

                //Items that sell by weight but we actually care about it.
                Database_API.AddItem("Flour", 6, true);

                builtItems = true;
            }

            if (!builtSpecials)
            {
                Database_API.AddSpecial(new SpecialNormal("Soup", 3, Special.DISCOUNT_TYPE.REDUCE_BY_DOLLAR, 3, 3));
                Database_API.AddSpecial(new SpecialNormal("Candy", 2, Special.DISCOUNT_TYPE.REDUCE_BY_DOLLAR, 2, 2));
                Database_API.AddSpecial(new SpecialNormal("Chicken", 50, Special.DISCOUNT_TYPE.REDUCE_BY_PERCENTAGE, 2, 1));

                //Bundling Deals
                Database_API.AddSpecial(new SpecialNormal("Flour", 6, Special.DISCOUNT_TYPE.SET_TO_AMOUNT, 3, 3));

                //Deals with a limit
                Database_API.AddSpecial(new SpecialNormal("Carpet", 60, Special.DISCOUNT_TYPE.REDUCE_BY_DOLLAR, 1, 1, 1));

                //Deals that affect the next item rather than the first one.
                Database_API.AddSpecial(new SpecialDeferred("Beef", 50, Special.DISCOUNT_TYPE.REDUCE_BY_PERCENTAGE, 1));

                builtSpecials = true;
            }
        }
        /// <summary>
        /// Take an item and check to see if the amount of purchases of its type
        /// allows for a special.
        /// </summary>
        private void Consolidate(string key, TALLY_STATE state)
        {
            //TRUE when a deal is either possible or is about to be impossible.
            bool hasSpecial = Database_API.TryGetMatchingDeal(key, itemRosterTallyUsed[key]) ||
                              itemRosterTallyUsed[key] < 0;
            bool deferred = false;

            bool specialStateReset = false;

            if (hasSpecial)
            {
                Special special = Database_API.GetSpecial(key);
                if (itemRosterTallyUsed[key] >= special.itemsNeededToFire && state == TALLY_STATE.ADD)
                {
                    itemRosterTallyUsed[key] -= special.itemsNeededToFire;
                    stm.AddToken(special);
                    specialStateReset = true;
                }
                else if (itemRosterTallyUsed[key] < 0 && state == TALLY_STATE.REMOVE)
                {
                    itemRosterTallyUsed[key] += special.itemsNeededToFire;
                    stm.RemoveToken(special);
                    specialStateReset = true;
                }

                deferred = special.special_type == Special.SPECIAL_TT.DEFERRED;
            }

            //If we're removing, do a purge just in case.
            specialStateReset = state == TALLY_STATE.REMOVE;

            if (specialStateReset || deferred)
            {
                //Run if we're either removing, or else have a deferred special.
                PurgeSpecials(key);
            }
            ApplySpecials();
        }
Beispiel #11
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();
        }
Beispiel #12
0
        /// <summary>
        /// Write the prompt needed to add an item into the database.
        /// </summary>
        private static void WriteAction_Add_To_DB_Special()
        {
            bool hasItem = false;

            Console.WriteLine("If a special is added to the database that already affects an item, then the new" +
                              "special will replace the old one.");
            Console.Write("Enter the name of the item being affected: ");
            string name = Console.ReadLine().Trim();

            hasItem = Database_API.TryGetItem(name);

            string isDeferred;
            string disType;
            string disValue;
            int    fireCount   = 0;
            int    affectCount = 0;
            int    fireLimit   = 0;
            bool   defer       = false;

            if (hasItem)
            {
                Console.WriteLine("Is the special deferred? (As in, 'buy x get y FREE') (y/n): ");
                isDeferred = Console.ReadLine();
                defer      = isDeferred.TrimStart().ToLower()[0] == 'y';

                Console.WriteLine("How does the special calculate its discount? " +
                                  "(1: flat (2 dollars off per item), 2: by percentage, 3: set price (as in, 3 for 5) (1/2/3): ");
                disType = Console.ReadLine();
                int type = int.Parse(disType);
                Special.DISCOUNT_TYPE typeAdd = Special.DISCOUNT_TYPE.SET_TO_AMOUNT;
                switch (type)
                {
                case 1: typeAdd = Special.DISCOUNT_TYPE.SET_TO_AMOUNT; break;

                case 2: typeAdd = Special.DISCOUNT_TYPE.REDUCE_BY_PERCENTAGE; break;

                case 3: typeAdd = Special.DISCOUNT_TYPE.REDUCE_BY_DOLLAR; break;
                }

                Console.Write("What is the value of the discount? (If it's a percentage," +
                              "enter the desired value without percentage sign: ");
                disValue = Console.ReadLine();
                int value = int.Parse(disValue);

                if (!defer)
                {
                    Console.Write("How many items does this special need to fire? ");
                    fireCount = int.Parse(Console.ReadLine());

                    Console.Write("How many items does this special affect when fired? ");
                    affectCount = int.Parse(Console.ReadLine());
                }

                Console.Write("How many times can a customer use this special? ");
                fireLimit = int.Parse(Console.ReadLine());

                if (defer)
                {
                    Database_API.AddSpecial(new SpecialDeferred(name, value, typeAdd, fireLimit));
                }
                else
                {
                    Database_API.AddSpecial(new SpecialNormal(name, value,
                                                              typeAdd, fireCount, affectCount, fireLimit));
                }

                Console.WriteLine("Special added successfully.");
            }
            else
            {
                Console.WriteLine("No such item exists in the database. Make sure it's spelled correctly.");
            }
        }