예제 #1
0
 /// <summary>
 /// Displays query results so user can view them
 /// </summary>
 /// <param name="results">Results.</param>
 public static void DisplayQueryResults(List <Contact> results)
 {
     Console.Clear();
     Display.Pause("***** SEARCH RESULTS *****");
     if (results.Count == 0)
     {
         Display.Pause("No contacts found.");
     }
     else
     {
         Display.Pause("Found "
                       + results.Count.ToString(Display.INT_DISPLAY_FORMAT)
                       + " contacts during our search...");
         Display.DisplayAllContacts(results, 1, 0, true);
     }
 }
예제 #2
0
        public static void Main(string[] args)
        {
            //Start out by loading up contacts into memory...
            Console.Write("Loading contacts.  Please wait...");
            if (File.Exists("MyContacts.dat"))
            {
                // load existing contact data file...
                contacts = Contact.LoadContacts("MyContacts.dat");
                Display.Pause("There are "
                              + contacts.Count.ToString(Display.INT_DISPLAY_FORMAT)
                              + " contacts in your list.");
            }
            else
            {
                //No .dat file exists yet.
                //Build it from csv
                contacts = BuildInitialContacList("us-50000.csv");

                Display.Pause("Built contact list from csv."
                              + "\nBe sure to SAVE YOUR NEW LIST before ending the program!");

                Display.Pause("There are "
                              + contacts.Count.ToString(Display.INT_DISPLAY_FORMAT)
                              + " contacts in your list.");
            }

            string selection = "";

            // Display menu and keep program "alive"
            // until user presses Q for quit.
            while (selection != "q")
            {
                try
                {
                    selection = Display.DisplayMainMenu
                                    (contacts.Count).Trim().ToLower();

                    switch (selection)
                    {
                    case "1":     // save current contact list.
                        Contact.SaveContacts(contacts, "MyContacts.dat");

                        Display.Pause("Successfully saved "
                                      + contacts.Count.ToString(Display.INT_DISPLAY_FORMAT)
                                      + " contacts.");

                        break;

                    case "2":     // modify contact list
                        SwitchToUserContactMenu();
                        break;

                    case "3":     // view contacts
                        Display.DisplayAllContacts(contacts);
                        break;

                    case "4":    // view specific contact
                    {
                        string id  = Display.GetUserInput("Enter contact ID: ");
                        int    val = 0;
                        if (!Validation.IsNumeric(id, ref val))
                        {
                            Display.Pause("Invalid ID; must be numeric.");
                        }
                        else
                        {
                            Contact contact = ContactQuery.FindByID(contacts, val);
                            if (contact == null)
                            {
                                Display.Pause("Contact with that ID not found.");
                            }
                            else
                            {
                                Console.Clear();
                                Display.DisplayContact(contact);
                                Display.Pause();
                            }
                        }
                    }
                    break;

                    case "5":    // query contacts
                        SwitchToUserQueryMenu();
                        break;

                    case "6":     // sort contacts
                        SwitchToSortMenu();
                        break;
                    }
                }
                catch (Exception e)
                {
                    Display.Pause("Error: " + e.Message);
                }
            }

            // save contact list before exiting...
            if (contacts.Count > 0)
            {
                Contact.SaveContacts(contacts, "MyContacts.dat");

                Display.Pause("Successfully saved "
                              + contacts.Count.ToString(Display.INT_DISPLAY_FORMAT)
                              + " contacts.\nPress any key to exit program.");
            }
        }