Exemplo n.º 1
0
        public static void SortList()
        {
            Console.WriteLine("What criteria would you like to sort the list by?");
            Console.WriteLine("Choose one of the following: model (0), printer (1), price (2), material (3).");
            ComputerTable.Key key = GetKey();

            Console.WriteLine("Would you like to reverse the sort?");
            bool reverse = GetConfirmation();

            _list.Sort(_sortFuncs[key], reverse);
        }
Exemplo n.º 2
0
        public static void SearchList()
        {
            _matched = false;
            Console.WriteLine("What field would you like to search the list by?");
            Console.WriteLine("Choose one of the following: model (0), printer (1), price (2), material (3).");
            ComputerTable.Key key = GetKey();

            Console.WriteLine("Enter search data:");
            // Get and set query data for searching
            switch (key)
            {
            case ComputerTable.Key.Model:
                Console.Write(">>> ");
                _modelSample = Console.ReadLine();
                break;

            case ComputerTable.Key.Printer:
                _printerSample = GetConfirmation();
                break;

            case ComputerTable.Key.Price:
                Console.Write(">>> ");
                while (!Decimal.TryParse(Console.ReadLine(), out _priceSample))
                {
                    Console.WriteLine("Failed to read input, try again.");
                    Console.Write(">>> ");
                }
                break;

            case ComputerTable.Key.Material:
                Console.Write(">>> ");
                _materialSample = Console.ReadLine();
                break;
            }

            // Apply func to each item
            _list.Iter(_searchFuncs[key]);
            if (!_matched)
            {
                Console.WriteLine("No matches found!");
            }
        }