コード例 #1
0
        // Writes a seires of menus to the console, guiding the
        // user through which category they would like to access
        private void displayCategories()
        {
            ToolCollection category = null;

            Console.Write("Select a category: " +
                          "\n\t1. Gardening Tools" +
                          "\n\t2. Flooring Tools" +
                          "\n\t3. Fencing Tools" +
                          "\n\t4. Measuring Tools" +
                          "\n\t5. Cleaning Tools" +
                          "\n\t6. Painting Tools" +
                          "\n\t7. Electronic Tools" +
                          "\n\t8. Elecricity Tools" +
                          "\n\t9. Automotive Tools\n");
            Console.Write("Enter the number corresponding to the category: ");
            int selection1 = Convert.ToInt16(Console.ReadLine());
            int selection2;

            switch (selection1)
            {
            case 1:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Line Trimmers" +
                              "\n\t2. Lawn Mowers" +
                              "\n\t3. Hand Tools" +
                              "\n\t4. Wheelbarrows" +
                              "\n\t5. Garden Power Tools\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                gardeningTools.TryGetValue(selection2, out category);
                break;

            case 2:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Scrapers" +
                              "\n\t2. Floor Lasers" +
                              "\n\t3. Floor Levelling Tools" +
                              "\n\t4. Floor Levelling Materials" +
                              "\n\t5. Floor Hand Tools" +
                              "\n\t6. Tiling Tools\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                flooringTools.TryGetValue(selection2, out category);
                break;

            case 3:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Hand Tools" +
                              "\n\t2. Electric Fencing" +
                              "\n\t3. Steel Fencing Tools" +
                              "\n\t4. Power Tools" +
                              "\n\t5. Fencing Accessories\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                fencingTools.TryGetValue(selection2, out category);
                break;

            case 4:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Distance Tools" +
                              "\n\t2. Laser Measurer" +
                              "\n\t3. Measuring Jugs" +
                              "\n\t4. Temperature & Humidity Tools" +
                              "\n\t5. Levelling Tools" +
                              "\n\t6. Markers\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                measuringTools.TryGetValue(selection2, out category);
                break;

            case 5:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Draining" +
                              "\n\t2. Car Cleaning" +
                              "\n\t3. Vacuum" +
                              "\n\t4. Pressure Cleaners" +
                              "\n\t5. Pool Cleaning" +
                              "\n\t6. Floor Cleaning\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                cleaningTools.TryGetValue(selection2, out category);
                break;

            case 6:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Sanding Tools" +
                              "\n\t2. Brushes" +
                              "\n\t3. Rollers" +
                              "\n\t4. Paint Removal Tools" +
                              "\n\t5. Paint Scrapers" +
                              "\n\t6. Sprayers\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                paintingTools.TryGetValue(selection2, out category);
                break;

            case 7:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Voltage Tester" +
                              "\n\t2. Oscilloscopes" +
                              "\n\t3. Thermal Imaging" +
                              "\n\t4. Data Test Tool" +
                              "\n\t5. Insulation Testers\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                electronicTools.TryGetValue(selection2, out category);
                break;

            case 8:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Test Equipment" +
                              "\n\t2. Safety Equipment" +
                              "\n\t3. Basic Equipment" +
                              "\n\t4. Circuit Protection" +
                              "\n\t5. Cable Tools\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                electricityTools.TryGetValue(selection2, out category);
                break;

            case 9:
                Console.Write("\nSelect a sub-category: " +
                              "\n\t1. Jacks" +
                              "\n\t2. Air Compressors" +
                              "\n\t3. Battery Chargers" +
                              "\n\t4. Socket Tools" +
                              "\n\t5. Braking" +
                              "\n\t6. Drivetrain\n");
                Console.Write("Enter the number corresponding to the category: ");
                selection2 = Convert.ToInt16(Console.ReadLine());
                automotiveTools.TryGetValue(selection2, out category);
                break;
            }
            if (category == null)
            {
                throw new NullReferenceException();
            }
            else
            {
                currentCollection = category;
            }
        }