예제 #1
0
        static void Main(string[] args)
        { /* UC6:- Refactor to add multiple Address Book to the System.
           *     Each Address Book has a unique Name
           *     - Use Console to add new Address Book
           *     - Maintain Dictionary of Address Book Name to Address Book
           */
            Console.WriteLine("**** Welcome To Address Book System ****");
            AddressBookDetails addressBookDetails = AddressBookDetails.ReadFromFile();
            bool flag = true;

            while (flag)
            {
                Console.Write("\n1.Add Address Book System" +
                              "\n2.Show Address Book System Name" +
                              "\n3.Delete Address Book" +
                              "\n4.Search Person in City or State " +
                              "\n5.Show all Record in City or State" +
                              "\n6.Count of Record City or State" +
                              "\n7.Exit\nEnter Your Choice: - ");

                int choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    addressBookDetails.AddAddressBook();     // add new Address book
                    break;

                case 2:
                    addressBookDetails.ViewAllAddressBooks();     //view all address book names
                    break;

                case 3:
                    addressBookDetails.DeleteAddressBook();     //delete an address book
                    break;

                case 4:
                    try
                    {                                                      /* UC8:- Ability to search Person in a City or State across the multiple AddressBook
                                                                            *       - Search Result can show multiple person in the city or state
                                                                            */
                        Console.Write("1.City\n2.State\nEnter Choice:-");  //print
                        int choice2 = Convert.ToInt32(Console.ReadLine()); //take input and convert int32
                        if (choice2 == 1)                                  //check condition
                        {
                            addressBookDetails.SearchInCity();             //search city
                        }
                        else if (choice2 == 2)
                        {
                            addressBookDetails.SearchInState();//search State
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case 5:
                    try
                    {                                                      /* UC8:- Ability to search Person in a City or State across the multiple AddressBook
                                                                            *        - Search Result can show multiple person in the city or state
                                                                            */
                        Console.Write("1.City\n2.State\nEnter Choice:-");  //print
                        int choice3 = Convert.ToInt32(Console.ReadLine()); //take input and convert int32
                        if (choice3 == 1)
                        {
                            addressBookDetails.ViewAllByCity();  //  view all contact in a city
                        }
                        else if (choice3 == 2)
                        {
                            addressBookDetails.ViewAllByState();  // view all contact in a State
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case 6:
                    try
                    {                                                      /* UC10:- Ability to get number of contact persons i.e. count by City or State.
                                                                            *       - Search Result will show count by city and by state.
                                                                            */
                        Console.Write("1.City\n2.State\nEnter Choice:-");  //print
                        int choice4 = Convert.ToInt32(Console.ReadLine()); //take input and convert int32
                        if (choice4 == 1)
                        {
                            addressBookDetails.CountAllByCity(); //get count of contacts in City
                        }
                        else if (choice4 == 2)
                        {
                            addressBookDetails.CountAllByState(); //get count of contacts in state
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    break;

                case 7:

                    flag = false;
                    break;

                default:
                    Console.WriteLine("Please Enter Valid Option");
                    break;
                }
            }

            // UC 13 Writing to the previously stored records.
            addressBookDetails.WriteToFile();
        }
예제 #2
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome To Address Book Program");

            // UC 13 Getting the previously stored records
            AddressBookDetails addressBookDetails = AddressBookDetails.GetFromFile();
            bool flag = true;

            while (flag)
            {
                Console.WriteLine("\nType to select address book" +
                                  "\nA      - To add or access address book" +
                                  "\nview   - To view all names of address books" +
                                  "\nDelete - To delete Address book" +
                                  "\nCity   - To search contact in a city" +
                                  "\nState  - To search contact in a state" +
                                  "\nVCity  - To view all contacts in a city" +
                                  "\nVState - To view all contacts in a state" +
                                  "\nCCity  - To get count of contacts city wise" +
                                  "\nCState - To get count of contacts state wise" +
                                  "\nE      - To exit\n\n");
                switch (Console.ReadLine().ToLower())
                {
                // To add or access new Address book
                case TO_ADD_OR_ACCESS:
                    addressBookDetails.AddOrAccessAddressBook();
                    break;

                // To view all address book names
                case TO_VIEW_ALL_ADDRESSBOOKS:
                    addressBookDetails.ViewAllAddressBooks();
                    break;

                // To delete an address book
                case TO_DELETE_ADDRESS_BOOK:
                    addressBookDetails.DeleteAddressBook();
                    break;

                // To search for a person in a city
                case SEARCH_PERSON_IN_CITY:
                    addressBookDetails.SearchInCity();
                    break;

                // To search for a person in a state
                case SEARCH_PERSON_IN_STATE:
                    addressBookDetails.SearchInState();
                    break;

                // To view all contacts in a city
                case VIEW_ALL_IN_CITY:
                    addressBookDetails.ViewAllByCity();
                    break;

                // To view all contacts in a city
                case VIEW_ALL_IN_STATE:
                    addressBookDetails.ViewAllByState();
                    break;

                // To get count of contacts in a city
                case COUNT_ALL_IN_CITY:
                    addressBookDetails.CountAllByCity();
                    break;

                // To get count of contacts in a state
                case COUNT_ALL_IN_STATE:
                    addressBookDetails.CountAllByState();
                    break;

                case EXIT:
                    Console.WriteLine("User exited application");
                    flag = false;
                    break;

                default:
                    Console.WriteLine("Invalid entry");
                    break;
                }
            }

            // UC 13 Writing to the previously stored records.
            addressBookDetails.WriteToFile();
        }