Esempio n. 1
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;
            }
        }
Esempio n. 2
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.");
            }
        }