Example #1
0
        /// <summary>
        /// Entery point
        /// </summary>
        /// <param name="args"></param>
        public static void Main(String[] args)
        {
            FileReadWrite.ReadContactsInCSVFile();
            // AddressBook obj = new AddressBook();//create object of AddressBook class


            Console.WriteLine("Welcome in Address book System");
            Console.WriteLine("*********************");
            //creating dictionary abDict
            Dictionary <string, AddressBook> abDict = new Dictionary <string, AddressBook>();//store Key ValuePair String is Key and AddressBook is value
            bool Result = true;

            Console.WriteLine("\nHow many address Book you want to create : ");
            int numAddressBooks = Convert.ToInt32(Console.ReadLine());//covert string into int with the help of ToInt32()

            for (int i = 1; i <= numAddressBooks; i++)
            {
                Console.WriteLine("Enter the name of address book " + i + ": ");
                string      bookName    = Console.ReadLine();
                AddressBook addressBook = new AddressBook(); //create obj
                abDict.Add(bookName, addressBook);           //Add bookName in dictionary
            }
            Console.WriteLine("\nYou have created following Address Books : ");
            foreach (var item in abDict) //var is used and it is store any data type value.
            {
                Console.WriteLine("{0}", item.Key);
            }
            while (Result)
            {
                Console.WriteLine("\nChoose option \n1.Add Contact \n2.Edit Contact \n3.Delete Contact  \n4.Display Contacts \n5.Search Person By City & State \n6.Display Contacts Same City \n7.Display Contacts Same State \n8.View number of contacts of city and state  \n9.Display Contacts in Sorted \n10.Display contact in sorted by state or by city \n11.File Operation \n12.Read Write Operation inCsv  \n13.Read Write Operation in Json file \n14.Exit");
                int choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.WriteLine("\nEnter Existing Address Book Name for adding contacts");
                    string contactName = Console.ReadLine();
                    if (abDict.ContainsKey(contactName))    //DEtermine whether the dictionary contains specified key
                    {
                        Console.WriteLine("\nEnter the number of contacts you want to add in address book");
                        int numberOfContacts = Convert.ToInt32(Console.ReadLine());    //taling i/p from user and convert into int with the help of ToInt32()
                        for (int i = 1; i <= numberOfContacts; i++)
                        {
                            addContactBook(abDict[contactName]);
                        }
                        abDict[contactName].displayPerson();
                    }
                    else
                    {
                        Console.WriteLine("No AddressBook exist with name {0}", contactName);
                    }
                    break;

                case 2:
                    Console.WriteLine("Enter Address Book Name for edit contact");
                    string editcontactName = Console.ReadLine();
                    if (abDict.ContainsKey(editcontactName))    //check whether the dictionary contains specified key
                    {
                        abDict[editcontactName].editPerson();
                        abDict[editcontactName].displayPerson();
                    }
                    else
                    {
                        Console.WriteLine("No Address book exist with name {0} ", editcontactName);
                    }
                    break;

                case 3:
                    Console.WriteLine("\nEnter Address Book Name for delete contact");
                    string deleteContact = Console.ReadLine();
                    if (abDict.ContainsKey(deleteContact))
                    {
                        abDict[deleteContact].deletePerson();
                        abDict[deleteContact].displayPerson();
                    }
                    else
                    {
                        Console.WriteLine("No Address book exist with name {0} ", deleteContact);
                    }
                    break;

                case 4:
                    Console.WriteLine("\nEnter Address Book Name for display contacts");
                    string displayContactsInAddressBook = Console.ReadLine();
                    abDict[displayContactsInAddressBook].displayPerson();
                    break;

                case 5:
                    Console.WriteLine("\n Enter address book name :");
                    string searchContacts = Console.ReadLine();
                    if (abDict.ContainsKey(searchContacts))
                    {
                        abDict[searchContacts].searchPerson();
                    }
                    else
                    {
                        Console.WriteLine("No Address book exist with name {0} ", searchContacts);
                    }
                    break;

                case 6:
                    Console.WriteLine("\n Enter address book name :");
                    string displayContacts = Console.ReadLine();
                    if (abDict.ContainsKey(displayContacts))
                    {
                        abDict[displayContacts].sameCityPerson();
                    }
                    else
                    {
                        Console.WriteLine("No Address book exist with name {0} ", displayContacts);
                    }
                    break;

                case 7:
                    Console.WriteLine("\n Enter address book name :");
                    string displayContacts2 = Console.ReadLine();
                    if (abDict.ContainsKey(displayContacts2))
                    {
                        abDict[displayContacts2].sameStatePerson();
                    }
                    else
                    {
                        Console.WriteLine("No Address book exist with name {0} ", displayContacts2);
                    }
                    break;

                case 8:
                    Console.WriteLine("\n Enter address book name :For counting same city or state");
                    string displayContacts3 = Console.ReadLine();
                    if (abDict.ContainsKey(displayContacts3))
                    {
                        abDict[displayContacts3].findCountSameStateOrCityPerson();
                    }
                    else
                    {
                        Console.WriteLine("No Address book exist with name {0} ", displayContacts3);
                    }
                    break;

                case 9:
                    Console.WriteLine("\nEnter Address Book Name for display contacts in sorted order");
                    string nameAddressBook = Console.ReadLine();
                    abDict[nameAddressBook].displayPersonInOrder();
                    break;

                case 10:
                    Console.WriteLine("\nEnter Address Book Name for Sort contacts based on City or State");
                    string nameAddressBookforSorting = Console.ReadLine();
                    Console.WriteLine("\nChoose option for sorting \n1.By City  \n2.By State \n3.By Zip");
                    int choiceSorting = Convert.ToInt32(Console.ReadLine());
                    switch (choiceSorting)
                    {
                    case 1:
                        abDict[nameAddressBookforSorting].displayPersonInOrderByCity();        //call method
                        break;

                    case 2:
                        abDict[nameAddressBookforSorting].displayPersonInOrderByState();
                        break;

                    case 3:
                        abDict[nameAddressBookforSorting].displayPersonInOrderByZip();
                        break;
                    }
                    break;

                case 11:
                    Console.WriteLine("chioce : \n1.Write Person detail in text file \n2 Read Person detail from text file");
                    int chooseOption = Convert.ToInt32(Console.ReadLine());
                    switch (chooseOption)
                    {
                    case 1:
                        Console.WriteLine("Enter Address Book name where you want to write person details");
                        string write = Console.ReadLine();
                        if (abDict.ContainsKey(write))
                        {
                            abDict[write].WritePersonDetailTextFile();
                        }
                        else
                        {
                            Console.WriteLine("No Address book exist with name {0} ", write);
                        }
                        break;

                    case 2:
                        Console.WriteLine("Enter Address Book name where you want to write person details");
                        string read = Console.ReadLine();
                        if (abDict.ContainsKey(read))
                        {
                            abDict[read].ReadPersonDetailTxtFile();
                        }
                        else
                        {
                            Console.WriteLine("No Address book exist with name {0} ", read);
                        }
                        break;

                    default:
                        Console.WriteLine("Please enter valid option only");
                        break;
                    }
                    break;


                case 12:
                    Console.WriteLine("chioce : \n1.Write Person detail in Csv file \n2 Read Person detail from Csv file");
                    int chooseOption2 = Convert.ToInt32(Console.ReadLine());
                    switch (chooseOption2)
                    {
                    case 1:
                        Console.WriteLine("Enter Address Book name where you want to write person details");
                        string write1 = Console.ReadLine();
                        if (abDict.ContainsKey(write1))
                        {
                            abDict[write1].WritePersonDetailCsvFile();
                        }
                        else
                        {
                            Console.WriteLine("No Address book exist with name {0} ", write1);
                        }
                        break;

                    case 2:
                        Console.WriteLine("Enter Address Book name where you want to write person details");
                        string read = Console.ReadLine();
                        if (abDict.ContainsKey(read))
                        {
                            abDict[read].ReadPersonDetailCsvFile();
                        }
                        else
                        {
                            Console.WriteLine("No Address book exist with name {0} ", read);
                        }
                        break;

                    default:
                        Console.WriteLine("Please enter valid option only");
                        break;
                    }
                    break;

                case 13:
                    Console.WriteLine("chioce : \n1.Write Person detail in Json file \n2 Read Person detail from Json file");
                    int chooseOption3 = Convert.ToInt32(Console.ReadLine());
                    switch (chooseOption3)
                    {
                    case 1:
                        Console.WriteLine("Enter Address Book name where you want to write person details");
                        string write1 = Console.ReadLine();
                        if (abDict.ContainsKey(write1))
                        {
                            abDict[write1].WriteContactsInJSONFile();
                        }
                        else
                        {
                            Console.WriteLine("No Address book exist with name {0} ", write1);
                        }
                        break;

                    case 2:
                        Console.WriteLine("Enter Address Book name where you want to write person details");
                        string read = Console.ReadLine();
                        if (abDict.ContainsKey(read))
                        {
                            abDict[read].ReadContactsFronJSON();
                        }
                        else
                        {
                            Console.WriteLine("No Address book exist with name {0} ", read);
                        }
                        break;

                    default:
                        Console.WriteLine("Please enter valid option");
                        break;
                    }
                    break;

                case 14:
                    Result = false;
                    break;

                default:
                    Console.WriteLine("Please enter valid option");
                    break;
                }
            }
            void addContactBook(AddressBook addressBook)
            {
                Console.WriteLine("Enter First Name : ");
                string firstName = Console.ReadLine();

                Console.WriteLine("Enter Last Name : ");
                string lastName = Console.ReadLine();

                Console.WriteLine("Enter Address : ");
                string address = Console.ReadLine();

                Console.WriteLine("Enter City : ");
                string city = Console.ReadLine();

                Console.WriteLine("Enter State : ");
                string state = Console.ReadLine();

                Console.WriteLine("Enter Phone Number : ");
                long phoneNumber = Convert.ToInt64(Console.ReadLine());

                Console.WriteLine("Enter Email id :");
                string email = Console.ReadLine();

                Console.WriteLine("Enter Zip : ");
                int zip = Convert.ToInt32(Console.ReadLine());

                addressBook.AddContact(firstName, lastName, address, city, state, phoneNumber, email, zip);
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            AddressBookBinder binder = new AddressBookBinder();

            Console.WriteLine("Welcome to Address Book Program");
            int result = 1;

            while (result == 1)
            {
                Console.WriteLine("Enter the name of the Address Book to be used");
                string      addrName = Console.ReadLine();
                AddressBook book     = new AddressBook();
                book.People = binder.AddAddrBook(addrName, book.People);
                int loop = 1;
                while (loop == 1)
                {
                    Console.WriteLine("\nSelect the option. \n1. Add new contact. \n2. Edit existing contact.\n3. Delete Contact \n4. Exit.");
                    int option = int.Parse(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                        Console.WriteLine("Enter the person details to be added in the address book");
                        Console.WriteLine("First Name");
                        string FirstName = Console.ReadLine();
                        Console.WriteLine("Last Name");
                        string LastName = Console.ReadLine();
                        Console.WriteLine("Address");
                        string Address = Console.ReadLine();
                        Console.WriteLine("City");
                        string City = Console.ReadLine();
                        Console.WriteLine("State");
                        string State = Console.ReadLine();
                        Console.WriteLine("Zip code");
                        string ZipCode = Console.ReadLine();
                        Console.WriteLine("Phone Number");
                        string PhoneNumber = Console.ReadLine();
                        Console.WriteLine("Email");
                        string Email = Console.ReadLine();
                        if (book.AddContact(FirstName, LastName, Address, City, State, ZipCode, PhoneNumber, Email))
                        {
                            Console.WriteLine("Contact added successfully");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Contact already exists");
                            break;
                        }

                    case 2:
                        Console.WriteLine("Enter the first name of the contact to be edited ");
                        string  name = Console.ReadLine();
                        Contact c    = book.FindContact(name);
                        if (c == null)
                        {
                            Console.WriteLine("Address for {0} count not be found.", name);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("New Last Name");
                            c.LastName = Console.ReadLine();
                            Console.WriteLine("New Address");
                            c.Address = Console.ReadLine();
                            Console.WriteLine("New City");
                            c.City = Console.ReadLine();
                            Console.WriteLine("New State");
                            c.State = Console.ReadLine();
                            Console.WriteLine("New Zip code");
                            c.ZipCode = Console.ReadLine();
                            Console.WriteLine("New Phone Number");
                            c.PhoneNumber = Console.ReadLine();
                            Console.WriteLine("New Email");
                            c.Email = Console.ReadLine();
                            Console.WriteLine("Details updated for " + name);
                            break;
                        }

                    case 3:
                        Console.WriteLine("Enter the first name of the contact to be deleted ");
                        string name1 = Console.ReadLine();
                        if (book.RemoveContact(name1))
                        {
                            Console.WriteLine("Contact removed successfully");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Contact not found");
                            break;
                        }

                    case 4:
                        loop = 0;
                        break;
                    }
                }
                binder.Binder[addrName] = (book.People);
                Console.WriteLine("Do you want to enter an address book. \n1. yes \n2. no");
                result = int.Parse(Console.ReadLine());
            }
            foreach (var key in binder.Binder.Keys)
            {
                Console.WriteLine(key);
                foreach (Contact c in binder.Binder[key])
                {
                    Console.WriteLine(c.FirstName + "\t" + c.LastName + "\t" + c.Address + "\t" + c.City + "\t" + c.State + "\t" + c.ZipCode + "\t" + c.PhoneNumber + "\t" + c.Email);
                }
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Address Book Program");
            AddressBook addressBook = new AddressBook();
            int         choice, choice2;
            string      bookName = "default";

            Console.WriteLine("Would You Like To \n1.Work on default AddressBook \n2.Create New AddressBook");
            choice2 = Convert.ToInt32(Console.ReadLine());
            switch (choice2)
            {
            case 1:
                addressBook.AddAddressBook(bookName);
                break;

            case 2:
                Console.WriteLine("Enter Name Of New Addressbook You want to create : ");
                bookName = Console.ReadLine();
                addressBook.AddAddressBook(bookName);
                break;

            default:
                Console.WriteLine("Invalid Input, Proceeding with default AddressBook");
                addressBook.AddAddressBook(bookName);
                break;
            }
            do
            {
                Console.WriteLine($"Working On {bookName} AddressBook\n");
                Console.WriteLine("Choose An Option \n1.Add New Contact \n2.Edit Existing Contact \n3.Delete A Contact \n4.View A Contact \n5.View All Contacts \n6.Add New AddressBook \n7.Switch AddressBook \n8.Search Contact by City/State \n9.Count by City/State \n10.Sort Entries \n11.Read/Write AddressBook to text file \n12.Read/Write AddressBook to csv file \n13.Read/Write AddressBook to JSON file \n0.Exit Application\n");
                choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter First Name :");
                    string firstName = Console.ReadLine();
                    Console.WriteLine("Enter Last Name :");
                    string  lastName = Console.ReadLine();
                    Contact temp     = new Contact()
                    {
                        FirstName = firstName,
                        LastName  = lastName
                    };
                    if (addressBook.CheckDuplicateEntry(temp, bookName))
                    {
                        break;
                    }
                    Console.WriteLine("Enter Address :");
                    string address = Console.ReadLine();
                    Console.WriteLine("Enter City :");
                    string city = Console.ReadLine();
                    Console.WriteLine("Enter State :");
                    string state = Console.ReadLine();
                    Console.WriteLine("Enter Email :");
                    string email = Console.ReadLine();
                    Console.WriteLine("Enter Zip :");
                    int zip = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Enter Phone Number :");
                    long phoneNumber = long.Parse(Console.ReadLine());
                    addressBook.AddContact(firstName, lastName, address, city, state, email, zip, phoneNumber, bookName);
                    break;

                case 2:
                    Console.WriteLine("Enter Full Name Of Contact To Edit :");
                    string nameToEdit = Console.ReadLine();
                    addressBook.EditContact(nameToEdit, bookName);
                    break;

                case 3:
                    Console.WriteLine("Enter Full Name Of Contact To Delete :");
                    string nameToDelete = Console.ReadLine();
                    addressBook.DeleteContact(nameToDelete, bookName);
                    break;

                case 4:
                    Console.WriteLine("Enter Full Name Of Contact To View :");
                    string nameToView = Console.ReadLine();
                    addressBook.ViewContact(nameToView, bookName);
                    break;

                case 5:
                    addressBook.ViewContact(bookName);
                    break;

                case 6:
                    Console.WriteLine("Enter Name For New AddressBook");
                    string newAddressBook = Console.ReadLine();
                    addressBook.AddAddressBook(newAddressBook);
                    Console.WriteLine("Would you like to Switch to " + newAddressBook);
                    Console.WriteLine("1.Yes \n2.No");
                    int c = Convert.ToInt32(Console.ReadLine());
                    if (c == 1)
                    {
                        bookName = newAddressBook;
                    }
                    break;

                case 7:
                    Console.WriteLine("Enter Name Of AddressBook From Below List");
                    foreach (KeyValuePair <string, AddressBook> item in addressBook.GetAddressBook())
                    {
                        Console.WriteLine(item.Key);
                    }
                    while (true)
                    {
                        bookName = Console.ReadLine();
                        if (addressBook.GetAddressBook().ContainsKey(bookName))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("No such AddressBook found. Try Again.");
                        }
                    }
                    break;

                case 8:
                    Console.WriteLine("Would You Like To \n1.Search by city \n2.Search by state");
                    int opt = Convert.ToInt32(Console.ReadLine());
                    switch (opt)
                    {
                    case 1:
                        Console.WriteLine("Enter name of city :");
                        addressBook.SearchPersonByCity(Console.ReadLine());
                        break;

                    case 2:
                        Console.WriteLine("Enter name of state :");
                        addressBook.SearchPersonByState(Console.ReadLine());
                        break;

                    default:
                        Console.WriteLine("Invalid Input.Enter 1 or 2");
                        break;
                    }
                    break;

                case 9:
                    addressBook.DisplayCountByCityandState();
                    break;

                case 10:
                    Console.WriteLine("\n1.Sort By Name \n2.Sort By City \n3.Sort By State \n4.Sort By Zip");
                    int ch = Convert.ToInt32(Console.ReadLine());
                    switch (ch)
                    {
                    case 1:
                        addressBook.SortByName();
                        break;

                    case 2:
                        addressBook.SortByCity();
                        break;

                    case 3:
                        addressBook.SortByState();
                        break;

                    case 4:
                        addressBook.SortByZip();
                        break;

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

                case 11:
                    FileIOOperation fileIO = new FileIOOperation();
                    fileIO.WriteToFile(addressBook.addressBookDictionary);
                    fileIO.ReadFromFile();
                    break;

                case 12:
                    CSVHandler handler = new CSVHandler();
                    handler.WriteToFile(addressBook.addressBookDictionary);
                    handler.ReadFromFile();
                    break;

                case 13:
                    JSONOperation json = new JSONOperation();
                    json.WriteToFile(addressBook.addressBookDictionary);
                    json.ReadFromFile();
                    break;

                case 0:
                    Console.WriteLine("Thank You For Using Address Book System.");
                    break;

                default:
                    Console.WriteLine("Invalid Entry. Enter value between 0 to 8");
                    break;
                }
            } while (choice != 0);
        }
Example #4
0
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        /// <param name="args">The arguments.</param>
        static void Main(string[] args)
        {
            ///Variables
            int    choice, choice1;
            string bookName = "default";

            Console.WriteLine("Welcome to Address Book Program");
            ///Creates reference of AdressBook.
            AddressBook addressBook = new AddressBook();

            ///Menu for AddressBook.
            Console.WriteLine("Would You Like To \n1.Work on default AddressBook \n2.Create New AddressBook");
            choice1 = Convert.ToInt32(Console.ReadLine());
            switch (choice1)
            {
            case 1:
                addressBook.AddAddressBook(bookName);
                break;

            case 2:
                Console.WriteLine("Enter Name Of New Addressbook You want to create : ");
                bookName = Console.ReadLine();
                addressBook.AddAddressBook(bookName);
                break;
            }
            do
            {
                ///Menu for Contacts.
                Console.WriteLine($"Working On {bookName} AddressBook\n");
                Console.WriteLine("Choose An Option \n1.Add New Contact \n2.Edit Existing Contact \n3.Delete A Contact \n4.View A Contact \n5.View All Contacts \n6.Add New AddressBook \n7.Switch AddressBook \n8.Search Contact by city or state\n" +
                                  "9.View Contacts by City or State.\n10. Count by city or state.\n11.Sort Entries.  \n12.Exit Application\n");
                choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter First Name :");
                    string firstName = Console.ReadLine();
                    Console.WriteLine("Enter Last Name :");
                    string lastName = Console.ReadLine();
                    Console.WriteLine("Enter Address :");
                    string address = Console.ReadLine();
                    Console.WriteLine("Enter City :");
                    string city = Console.ReadLine();
                    Console.WriteLine("Enter State :");
                    string state = Console.ReadLine();
                    Console.WriteLine("Enter Email :");
                    string email = Console.ReadLine();
                    Console.WriteLine("Enter Zip :");
                    int zip = Convert.ToInt32(Console.ReadLine());
                    Console.WriteLine("Enter Phone Number :");
                    long phoneNumber = long.Parse(Console.ReadLine());
                    addressBook.AddContact(firstName, lastName, address, city, state, email, zip, phoneNumber, bookName);
                    break;

                case 2:
                    Console.WriteLine("Enter First Name Of Contact To Edit :");
                    string nameToEdit = Console.ReadLine();
                    addressBook.EditContact(nameToEdit, bookName);
                    break;

                case 3:
                    Console.WriteLine("Enter First Name Of Contact To Delete :");
                    string nameToDelete = Console.ReadLine();
                    addressBook.DeleteContact(nameToDelete, bookName);
                    break;

                case 4:
                    Console.WriteLine("Enter First Name Of Contact To View :");
                    string nameToView = Console.ReadLine();
                    addressBook.ViewContact(nameToView, bookName);
                    break;

                case 5:
                    addressBook.ViewAllContacts(bookName);
                    break;

                case 6:
                    Console.WriteLine("Enter Name For New AddressBook");
                    string newAddressBook = Console.ReadLine();
                    addressBook.AddAddressBook(newAddressBook);
                    Console.WriteLine("Would you like to Switch to " + newAddressBook);
                    Console.WriteLine("1.Yes \n2.No");
                    int c = Convert.ToInt32(Console.ReadLine());
                    if (c == 1)
                    {
                        bookName = newAddressBook;
                    }
                    break;

                case 7:
                    Console.WriteLine("Enter Name Of AddressBook From Below List");
                    foreach (KeyValuePair <string, AddressBook> item in addressBook.GetAddressBook())
                    {
                        Console.WriteLine(item.Key);
                    }
                    while (true)
                    {
                        bookName = Console.ReadLine();
                        if (addressBook.GetAddressBook().ContainsKey(bookName))
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("No such AddressBook found. Try Again.");
                        }
                    }
                    break;

                case 8:
                    Console.WriteLine("Would You Like To \n1.Search by city \n2.Search by state");
                    int opt = Convert.ToInt32(Console.ReadLine());
                    switch (opt)
                    {
                    case 1:
                        Console.WriteLine("Enter name of city :");
                        addressBook.SearchPersonByCity(Console.ReadLine());
                        break;

                    case 2:
                        Console.WriteLine("Enter name of state :");
                        addressBook.SearchPersonByState(Console.ReadLine());
                        break;

                    default:
                        Console.WriteLine("Invalid Input.Enter 1 or 2");
                        break;
                    }
                    break;

                case 9:
                    Console.WriteLine("Would You Like To \n1.View by city \n2.View by state");
                    int option = Convert.ToInt32(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                        Console.WriteLine("Enter name of city :");
                        addressBook.ViewByCity(Console.ReadLine());
                        break;

                    case 2:
                        Console.WriteLine("Enter name of state :");
                        addressBook.ViewByState(Console.ReadLine());
                        break;

                    default:
                        Console.WriteLine("Invalid Input.Enter 1 or 2");
                        break;
                    }
                    break;

                case 10:
                    addressBook.CountPersonByCityOrState();
                    break;

                case 11:
                    Console.WriteLine("\n1.Sort By Name \n2.Sort By City \n3.Sort By State \n4.Sort By Zip");
                    int ch = Convert.ToInt32(Console.ReadLine());
                    switch (ch)
                    {
                    case 1:
                        addressBook.SortByName();
                        break;

                    case 2:
                        addressBook.SortByCity();
                        break;

                    case 3:
                        addressBook.SortByState();
                        break;

                    case 4:
                        addressBook.SortByZip();
                        break;

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

                case 12:
                    Console.WriteLine("Thank You For Using Address Book System.");
                    break;
                }
            }while (choice != 12);
            Console.WriteLine("Writing in AddressBook.txt");
            AddressBookFileIO.WriteUsingStreamWriter(addressBook.addressBookDictionary);
            AddressBookFileIO.ReadUsingStreamReader();
        }
 /// <summary>
 /// Adds the multiple address book using dictionary.
 /// </summary>
 public void AddMultipleAddressBook(string name, AddressBook addressB)
 {
     addressBookDictionary.Add(name, addressB);
 }
Example #6
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Address Book!");
            Console.WriteLine("Enter Default Address Book Name");
            string addressBookName = Console.ReadLine();
            AddressBookCollection addressBookCollection = new AddressBookCollection();
            AddressBook           addressBook           = new AddressBook();

            addressBookCollection.addressBookDictionary.Add(addressBookName, addressBook);
            int choice;

            do
            {
                PrintOptions();
                choice = Convert.ToInt32(Console.ReadLine());
                switch (choice)
                {
                case 1:
                    addressBookCollection.addressBookDictionary[addressBookName].DisplayNamesInAddresBook();
                    break;

                case 2:
                    addressBookCollection.addressBookDictionary[addressBookName].AddAddressBookEntry(addressBookCollection);
                    break;

                case 3:
                    Console.WriteLine("Enter First Name");
                    string firstName = Console.ReadLine();
                    Console.WriteLine("Enter Last Name");
                    string lastName = Console.ReadLine();
                    addressBookCollection.addressBookDictionary[addressBookName].EditContact(firstName, lastName);
                    break;

                case 4:
                    Console.WriteLine("Enter First Name");
                    firstName = Console.ReadLine();
                    Console.WriteLine("Enter Last Name");
                    lastName = Console.ReadLine();
                    addressBookCollection.addressBookDictionary[addressBookName].DeleteContact(firstName, lastName);
                    break;

                case 5:
                    Console.WriteLine("Enter New Address Book Name");
                    addressBookName = Console.ReadLine();
                    addressBookCollection.addressBookDictionary.Add(addressBookName, new AddressBook());
                    Console.WriteLine($"Address Book {addressBookName} selected!");
                    break;

                case 6:
                    Console.WriteLine("Listing all Address Books");
                    foreach (var addressBookEntry in addressBookCollection.addressBookDictionary)
                    {
                        Console.WriteLine(addressBookEntry.Key);
                    }
                    Console.WriteLine("Select an Address Book");
                    addressBookName = Console.ReadLine();
                    break;

                case 7:
                    Console.WriteLine("Enter First Name");
                    firstName = Console.ReadLine();
                    Console.WriteLine("Enter Last Name");
                    lastName = Console.ReadLine();
                    addressBookCollection.SearchPersonInCityOrState(firstName, lastName);
                    break;

                case 8:
                    Console.WriteLine("Enter City Name");
                    string cityName = Console.ReadLine();
                    Console.WriteLine("Enter State Name");
                    string stateName = Console.ReadLine();
                    addressBookCollection.ViewPersonsByCityOrState(cityName, stateName);
                    break;

                case 9:
                    Console.WriteLine("Enter City Name");
                    cityName = Console.ReadLine();
                    Console.WriteLine("Enter State Name");
                    stateName = Console.ReadLine();
                    addressBookCollection.ViewCountByCityOrState(cityName, stateName);
                    break;

                case 10:
                    addressBookCollection.addressBookDictionary[addressBookName].SortByFirstName();
                    break;

                case 11:
                    SortByCityStateorZip(addressBookCollection, addressBookName);
                    break;

                case 12:
                    ReadFromFile(addressBookCollection);
                    break;

                case 13:
                    WriteToFile(addressBookCollection);
                    break;

                case 14:
                    addressBookName = AddDefaultValues(addressBookCollection);
                    break;

                default:
                    Console.WriteLine("Enter Proper Choice!");
                    break;
                }
            } while (choice != 15);
        }
        //Main Method

        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Address Book");                                      //Welcome Message
            Console.WriteLine("========================");

            AddressBook addressBook = new AddressBook();

            addressBook.Name = "General";                                                     // Default value of AddressBook

            bool checkAddressBook    = true;                                                  //For initializing the AddressBook
            bool checkContactDetails = true;;                                                 //For initializing the contact Details in AddressBook


            //AddressBook

            while (checkAddressBook)
            {
                Console.WriteLine("Enter\n" +
                                  "1 : To Add a new Address Book\n" +
                                  "2 : To use current address books ( " + addressBook.Name + " )\n" +
                                  "3 : Switch Address Book\n" +
                                  "4. Search by State in AddressBook\n" +
                                  "5. Search by City in AddressBook\n" +
                                  "6. Count by State in AddressBook\n" +
                                  "7. Count by City in AddressBook\n" +
                                  "0 : Exit");;

                int userChoice;

                try
                {
                    userChoice = Int32.Parse(Console.ReadLine());                                  //Exception to ensure only Numbers are entered
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    userChoice = 0;
                }



                switch (userChoice)
                {
                case 1:
                    checkContactDetails = true;
                    Console.WriteLine("Add Name of the new Address Book");                           //Creating the AddressBook
                    addressBook.Name = Console.ReadLine();

                    break;


                case 2:
                    checkContactDetails = true;

                    break;


                case 3:
                    checkContactDetails = true;
                    Console.WriteLine("Enter Name of the Address Book you want to switch");                 //Switch the AddressBook
                    addressBook.Name = Console.ReadLine();

                    break;

                case 4:
                    addressBook.SearchinAddressBooksByState();                                    //Search for state in Across AddressBook
                    break;

                case 5:
                    addressBook.SearchinAddressBooksByCity();                                      //Search for city in Across AddressBook
                    break;

                case 6:
                    addressBook.DisplayPersonCountByState();                                      //Display Count by state in Across AddressBook
                    break;

                case 7:
                    addressBook.DisplayPersonCountByCity();                                      //Display Count by city in Across AddressBook
                    break;

                case 0:
                    checkAddressBook    = false;
                    checkContactDetails = false;                                                        //Exit the AddressBookSystem
                    break;

                default:
                    Console.WriteLine("Wrong Option Entered");
                    break;
                }



                while (checkContactDetails)
                {
                    int choice;

                    Console.WriteLine("You are in " + addressBook.Name);                //Name of AddressBook


                    Console.WriteLine("Enter\n" +
                                      "1 : Add Contact Details to " + addressBook.Name + " Address Book\n" +
                                      "2 : Edit a Contact Detail\n" +
                                      "3 : Delete a Contact Detail\n" +
                                      "4: Display the contents of the AddresBook\n" +
                                      "5. Display Content by State\n" +
                                      "6. Display Content by City\n" +
                                      "7. Sort By Name\n" +
                                      "8. Store AddressBook in File\n" +
                                      "9. Implement CSV Implementation\n" +
                                      "0 : Exit");

                    try
                    {
                        choice = Int32.Parse(Console.ReadLine());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        choice = 0;
                    }

                    switch (choice)
                    {
                    case 1:
                        addressBook.AddNewContactToAddressBook();                          //Function to add Contact in AddressBook
                        break;

                    case 2:
                        addressBook.EditDetailsInAddressBook();                            //Function to Edit Details in AddressBook
                        break;

                    case 3:
                        addressBook.DeletetheContactDetail();                               //Function to Delete the Contact Details in AddressBook
                        break;

                    case 4:
                        addressBook.DisplayContactsInCurrentAddressBook();                   //Display the Contact in the AddressBook
                        break;

                    case 5:
                        addressBook.SearchByState();                                     //To Search by State in AddressBook
                        break;

                    case 6:
                        addressBook.SearchByCity();                                     //To Search by City in AddressBook
                        break;

                    case 7:
                        addressBook.SortPersonsByName();                                   //Sort By Name in AddressBook
                        break;

                    case 8:
                        addressBook.DoIO();                                                //InputOuput File of AddressBook
                        break;

                    case 9:
                        addressBook.ImplementCSVDataHandling();
                        break;

                    case 0:
                        checkContactDetails = false;                                  //Exist the present AddressBook
                        break;

                    default:
                        Console.WriteLine("Please Enter Correct Option");
                        break;
                    }
                }
            }
        }
Example #8
0
        public static void Main(string[] args)
        {
            Dictionary <String, List <Contacts> > sorted = new Dictionary <String, List <Contacts> >();
            int c1 = 0;

            while (c1 != 11)
            {
                string bname = "";
                Console.WriteLine("Welcome to Address Book Program");
                List <Contacts> gcontacts = new List <Contacts>();   //stores contacts list for different address books

                Console.WriteLine("1. Add Address Book: ");
                Console.WriteLine("2. Edit a Particular Address Book: ");
                Console.WriteLine("3. Display Address Book: ");
                Console.WriteLine("4. View Person's Details By City: ");
                Console.WriteLine("5. View Person's Details By State: ");
                Console.WriteLine("6. Write Address Book into a File: ");
                Console.WriteLine("7. Read Address Book from a File: ");
                Console.WriteLine("8. Write and Read Address Book(CSV File): ");
                Console.WriteLine("9. Write and Read Address Book(JSON File): ");
                Console.WriteLine("10. Clear Address Book Details from all Files(Txt, CSV, JSON): ");
                Console.WriteLine("11. Exit");

                Console.WriteLine("Enter your choice: ");
                c1 = Convert.ToInt32(Console.ReadLine());
                switch (c1)
                {
                case 1:
                    Console.WriteLine("Enter the name of Address Book: ");
                    bname = Console.ReadLine();
                    List <Contacts> contacts = new List <Contacts>();    //stores contacts list for a particular book

                    AddressBook.edit_data(contacts);

                    gcontacts.AddRange(contacts);
                    sorted.Add(bname, gcontacts);
                    break;

                case 2:
                    Console.WriteLine("Enter the name of Address Book: ");
                    string bname1 = Console.ReadLine();
                    if (sorted.ContainsKey(bname1))
                    {
                        List <Contacts> edit = sorted[bname1];
                        AddressBook.edit_data(edit);
                    }
                    else
                    {
                        Console.WriteLine("Mentioned Address Book is not there");
                    }
                    break;

                case 3:
                    foreach (KeyValuePair <String, List <Contacts> > kv in sorted)
                    {
                        string          a     = kv.Key;
                        List <Contacts> list1 = (List <Contacts>)kv.Value;
                        Console.WriteLine("Address Book Name: " + a);
                        foreach (Contacts c in list1)
                        {
                            Console.WriteLine(c);
                        }
                    }
                    break;

                case 4:
                    Console.WriteLine("Enter the City Name: ");
                    string city = Console.ReadLine();
                    int    fg   = 0;

                    Dictionary <string, List <Contacts> > cty = new Dictionary <string, List <Contacts> >();
                    List <Contacts> gtemp = new List <Contacts>();

                    foreach (KeyValuePair <string, List <Contacts> > kv in sorted)
                    {
                        List <Contacts> list1 = kv.Value;    //gives list details per address book
                        List <Contacts> temp  = new List <Contacts>();
                        foreach (Contacts c in list1)
                        {
                            if (c.city.ToLower().Equals(city.ToLower()))
                            {
                                temp.Add(c);
                                fg++;
                            }
                        }
                        gtemp.AddRange(temp);                //Appends person's details per book by city
                    }
                    cty.Add(city, gtemp);

                    if (fg == 0)
                    {
                        Console.WriteLine("Mentioned City Name isn't present in Address Book");
                    }
                    else
                    {
                        Console.WriteLine("Total records for City Name " + city + ": " + fg);
                        foreach (KeyValuePair <string, List <Contacts> > kv in cty)
                        {
                            string          a   = kv.Key;
                            List <Contacts> lst = kv.Value;
                            Console.WriteLine("City Name: " + a);
                            foreach (Contacts c in lst)
                            {
                                Console.WriteLine(c);
                            }
                        }
                    }
                    break;

                case 5:
                    Console.WriteLine("Enter the State Name: ");
                    string state = Console.ReadLine();
                    int    fg1   = 0;

                    Dictionary <string, List <Contacts> > st = new Dictionary <string, List <Contacts> >();
                    List <Contacts> gtemp1 = new List <Contacts>();

                    foreach (KeyValuePair <string, List <Contacts> > kv in sorted)
                    {
                        List <Contacts> list1 = kv.Value;    //gives list details per address book
                        List <Contacts> temp  = new List <Contacts>();
                        foreach (Contacts c in list1)
                        {
                            if (c.state.ToLower().Equals(state.ToLower()))
                            {
                                temp.Add(c);
                                fg1++;
                            }
                        }
                        gtemp1.AddRange(temp);                //Appends person's details per book by state
                    }
                    st.Add(state, gtemp1);

                    if (fg1 == 0)
                    {
                        Console.WriteLine("Mentioned State Name isn't present in Address Book");
                    }
                    else
                    {
                        Console.WriteLine("Total records for State Name " + state + ": " + fg1);
                        foreach (KeyValuePair <string, List <Contacts> > kv in st)
                        {
                            string          a   = kv.Key;
                            List <Contacts> lst = kv.Value;
                            Console.WriteLine("City Name: " + a);
                            foreach (Contacts c in lst)
                            {
                                Console.WriteLine(c);
                            }
                        }
                    }

                    break;

                case 6:
                    if (File.Exists(filePath))
                    {
                        using (StreamWriter stw = File.CreateText(filePath))
                        {
                            foreach (KeyValuePair <String, List <Contacts> > kv in sorted)
                            {
                                string          a     = kv.Key;
                                List <Contacts> list1 = (List <Contacts>)kv.Value;
                                stw.WriteLine("Address Book Name: " + a);
                                foreach (Contacts c in list1)
                                {
                                    stw.WriteLine(c);
                                }
                            }
                            Console.WriteLine("Address Book written into the file successfully!!!");
                        }
                    }
                    else
                    {
                        Console.WriteLine("File doesn't exist!!!");
                    }
                    break;

                case 7:
                    if (File.Exists(filePath))
                    {
                        using (StreamReader str = File.OpenText(filePath))
                        {
                            string s = "";
                            while ((s = str.ReadLine()) != null)
                            {
                                Console.WriteLine(s);
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("File doesn't exist!!!");
                    }
                    break;

                case 8:
                    Console.WriteLine("Enter the Address Book Name:");
                    string nameCSV = Console.ReadLine();
                    if (sorted.ContainsKey(nameCSV))
                    {
                        CsvHandler.WriteIntoCSVFile(sorted, nameCSV);
                        Console.WriteLine("Data inserted successfully");
                        CsvHandler.ReadFromCSVFile();
                        Console.WriteLine("Data read successfully");
                    }
                    else
                    {
                        Console.WriteLine("Book Name Not Found");
                    }
                    break;

                case 9:
                    Console.WriteLine("Enter the Address Book Name:");
                    string nameJSON = Console.ReadLine();
                    if (sorted.ContainsKey(nameJSON))
                    {
                        JsonHandler.WriteIntoJSONFile(sorted, nameJSON);
                        Console.WriteLine("Data inserted successfully");
                        JsonHandler.ReadFromJSONFile();
                        Console.WriteLine("Data read successfully");
                    }
                    else
                    {
                        Console.WriteLine("Book Name Not Found");
                    }
                    break;

                case 10:
                    File.WriteAllText(filePath, string.Empty);
                    CsvHandler.ClearData();
                    JsonHandler.ClearData();
                    Console.WriteLine("All Files cleared successfully!!!");
                    break;
                }
            }
        }
 public AddressBookMain()
 {
     book = new AddressBook();
 }
Example #10
0
        static void Main(string[] args)
        {
            AddressBookBinder binder = new AddressBookBinder();

            Console.WriteLine("Welcome to Address Book Program");
            int result = 1;

            while (result == 1)
            {
                Console.WriteLine("Enter the name of the Address Book to be used");
                string      addrName = Console.ReadLine();
                AddressBook book     = new AddressBook();
                book.People = binder.AddAddrBook(addrName, book.People);
                int loop = 1;
                while (loop == 1)
                {
                    Console.WriteLine("\nSelect the option. \n1. Add new contact. \n2. Edit existing contact.\n3. Delete Contact \n4. Search By City \n5. Count citywise contacts \n6. Display Alphabetically \n7. Sort By Zipcode \n8. Sort By City \n9. Sort By State \n10. Read the contacts from txt file \n11. Write the contacts in txt file \n12. Read the contacts from csv file \n13. Write the contacts in csv file \n14. Read the contacts from json file \n15. Write the contacts in json file \n16. Exit. ");
                    int option = int.Parse(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                        Console.WriteLine("Enter the person details to be added in the address book");
                        Console.WriteLine("First Name");
                        string FirstName = Console.ReadLine();
                        Console.WriteLine("Last Name");
                        string LastName = Console.ReadLine();
                        Console.WriteLine("Address");
                        string Address = Console.ReadLine();
                        Console.WriteLine("City");
                        string City = Console.ReadLine();
                        Console.WriteLine("State");
                        string State = Console.ReadLine();
                        Console.WriteLine("Zip code");
                        string ZipCode = Console.ReadLine();
                        Console.WriteLine("Phone Number");
                        string PhoneNumber = Console.ReadLine();
                        Console.WriteLine("Email");
                        string Email = Console.ReadLine();
                        book.AddContact(FirstName, LastName, Address, City, State, ZipCode, PhoneNumber, Email);
                        break;

                    case 2:
                        Console.WriteLine("Enter the first name of the contact to be edited ");
                        string name = Console.ReadLine();
                        book.EditContact(name);
                        break;

                    case 3:
                        Console.WriteLine("Enter the first name of the contact to be deleted ");
                        string name1 = Console.ReadLine();
                        if (book.RemoveContact(name1))
                        {
                            Console.WriteLine("Contact removed successfully");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Contact not found");
                            break;
                        }

                    case 4:
                        binder.CreateCityDictionary();
                        Console.WriteLine("Enter city whose contacts need to be searched");
                        string city = Console.ReadLine();
                        foreach (Contact contact in binder.CityDictionary[city])
                        {
                            Console.WriteLine(contact.FirstName + "\t" + contact.LastName + "\t" + contact.Address + "\t" + contact.City + "\t" + contact.State + "\t" + contact.ZipCode + "\t" + contact.PhoneNumber + "\t" + contact.Email);
                        }
                        break;

                    case 5:
                        binder.CreateCityDictionary();
                        foreach (var key in binder.CityDictionary.Keys)
                        {
                            Console.WriteLine(key + "\t" + binder.CityDictionary[key].Count);
                        }
                        break;

                    case 6:
                        book.AlphabeticallyArrange();
                        break;

                    case 7:
                        book.SortByPincode();
                        break;

                    case 8:
                        book.SortByCity();
                        break;

                    case 9:
                        book.SortByState();
                        break;

                    case 10:
                        Console.WriteLine("Reading contacts from txt file");
                        ReadWrite.ReadFromStreamReader();
                        break;

                    case 11:
                        Console.WriteLine("Writing contacts in txt file");
                        ReadWrite.WriteUsingStreamWriter(book.People);
                        break;

                    case 12:
                        Console.WriteLine("Reading contacts from csv file");
                        ReadWrite.ReadCSVFile();
                        break;

                    case 13:
                        Console.WriteLine("Writing contacts in csv file");
                        ReadWrite.WriteCSVFile(book.People);
                        break;

                    case 14:
                        Console.WriteLine("Reading contacts from json file");
                        ReadWrite.ReadJsonFile();
                        break;

                    case 15:
                        Console.WriteLine("Writing contacts in json file");
                        ReadWrite.WriteToJsonFile(book.People);
                        break;

                    case 16:
                        loop = 0;
                        break;
                    }
                    binder.Binder[addrName] = (book.People);
                }
                Console.WriteLine("Do you want to enter an address book. \n1. yes \n2. no");
                result = int.Parse(Console.ReadLine());
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Address Book Program");

            Dictionary <string, AddressBook> addressBookMap = new Dictionary <string, AddressBook>();

            int         addressBookChoice = 1;
            AddressBook addressBook       = null;

            while (addressBookChoice != 4)
            {
                Console.WriteLine("\n1. Create new Address Book");
                Console.WriteLine("2. Update existing Address Book");
                Console.WriteLine("3. Search Person in a City or State");
                Console.WriteLine("4. Exit");
                Console.WriteLine("Enter your choice");
                try
                {
                    addressBookChoice = Convert.ToInt32(Console.ReadLine());
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                    break;
                }
                switch (addressBookChoice)
                {
                case 1:
                    Console.WriteLine("\nEnter the name of address book");
                    string bookName = Console.ReadLine();
                    addressBookMap.Add(bookName, new AddressBook(bookName));
                    break;

                case 2:
                    if (addressBookMap.Count != 0)
                    {
                        bool addressBookExist = false;
                        while (!addressBookExist)
                        {
                            try
                            {
                                Console.WriteLine("\nEnter the Address Book Name");
                                string name = Console.ReadLine();
                                addressBook      = addressBookMap[name];
                                addressBookExist = true;
                            }
                            catch (KeyNotFoundException e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }

                        int choice = 1;

                        while (choice != 9)
                        {
                            Console.WriteLine("\n1. Add a Contact");
                            Console.WriteLine("2. View Address Book");
                            Console.WriteLine("3. Edit Contact");
                            Console.WriteLine("4. Delete Contact");
                            Console.WriteLine("5. View person by city/state");
                            Console.WriteLine("6. Read Contact from CSV");
                            Console.WriteLine("7. Write Contact to CSV");
                            Console.WriteLine("8. Retrieve Contact from database");
                            Console.WriteLine("9. Back to main menu\n");
                            Console.WriteLine("Enter your choice");
                            try
                            {
                                choice = Convert.ToInt32(Console.ReadLine());
                            }
                            catch (FormatException e)
                            {
                                Console.WriteLine(e.Message);
                                break;
                            }

                            switch (choice)
                            {
                            case 1:
                                addressBook.AddContact();
                                break;

                            case 2:
                                addressBook.viewContacts();
                                break;

                            case 3:
                                addressBook.editContact();
                                break;

                            case 4:
                                addressBook.DeleteContact();
                                break;

                            case 5:
                                Console.WriteLine("1. City\n2. State ");
                                Console.Write("Select : ");
                                int option = Convert.ToInt32(Console.ReadLine());
                                if (option == 1)
                                {
                                    addressBook.groupByCityOrState("city");
                                }
                                else if (option == 2)
                                {
                                    addressBook.groupByCityOrState("state");
                                }
                                else
                                {
                                    Console.WriteLine("Invalid input.");
                                    break;
                                }

                                break;

                            case 6:
                                addressBook.ReadJSON();
                                break;

                            case 7:
                                addressBook.WriteJSON();
                                break;

                            case 8:
                                Console.WriteLine("\n1. Get All Contacts in DB");
                                Console.WriteLine("2. Get By City/State");
                                int x = Convert.ToInt32(Console.ReadLine());
                                addressBook.RetrieveDataFromDB(x);
                                break;

                            case 9:
                                Console.WriteLine("Back to main menu\n");
                                break;

                            default:
                                break;
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("\nNo Address Book Available");
                    }
                    break;

                case 3:
                    Console.WriteLine("\nEnter the place needed to be searched : ");
                    string place = Console.ReadLine();
                    Console.WriteLine("\nPerson found at {0} are : ", place);
                    foreach (KeyValuePair <string, AddressBook> entry in addressBookMap)
                    {
                        addressBook = entry.Value;
                        List <ContactPerson> persons = addressBook.searchPersonByPlace(place);
                        foreach (ContactPerson person in persons)
                        {
                            Console.WriteLine(person.toString());
                        }
                    }
                    break;

                case 4:
                    Console.WriteLine("\nThank you for using the application");
                    break;

                default:
                    break;
                }
            }
        }
Example #12
0
        static void Main(string[] args)

        {
            Console.WriteLine("Welcome to Multiple Address Book ");
            MultipleAddressBook multipleAddressBook = new MultipleAddressBook();

            while (true)
            {
                Console.WriteLine("enter the name of Addressbook");
                string name = Console.ReadLine();
                if (name == "")
                {
                    break;
                }
                AddressBook addressBook = new AddressBook();


                bool flag = true;

                while (flag)
                {
                    Console.WriteLine("Please enter your firstname, last name, address, city, state, zip, phone no, email ");
                    string firstName = Console.ReadLine();
                    if (firstName == "")
                    {
                        //flag = false;
                        break;
                    }
                    string lastName = Console.ReadLine();
                    string address  = Console.ReadLine();
                    string city     = Console.ReadLine();
                    string state    = Console.ReadLine();
                    int    zip      = Convert.ToInt32(Console.ReadLine());
                    double phoneNo  = Convert.ToDouble(Console.ReadLine());
                    string email    = Console.ReadLine();

                    addressBook.AddDetailsOfPersons(firstName, lastName, address, city, state, zip, phoneNo, email);
                }



                addressBook.DisplayContactPersonDetails();
                Console.WriteLine("To update  details Enter 'YES' or else 'NO' ");
                string updateCheck = Console.ReadLine();
                if (updateCheck == "YES")
                {
                    Console.WriteLine("enter the first name & last name of the person to be updated");
                    string newFirstName = Console.ReadLine();
                    string newLastName  = Console.ReadLine();
                    addressBook.UpdateContactPersonDetails(newFirstName, newLastName);
                }
                Console.WriteLine("To delete Details enter 'Y' else enter 'N' ");
                char deleteCheck = Convert.ToChar(Console.ReadLine());
                if (deleteCheck == 'Y')
                {
                    Console.WriteLine("enter the first name & last name of the person contact to be delete  ");
                    string fName = Console.ReadLine();
                    string lName = Console.ReadLine();
                    addressBook.DeleteContactPersonDetails(fName, lName);
                }

                multipleAddressBook.AddMultipleAddressBook(name, addressBook);
            }

            Console.WriteLine("enter the name of Addressbook which you want to display:");
            string nameCheck = Console.ReadLine();

            multipleAddressBook.display(nameCheck);
        }
        static void Main(string[] args)
        {
            AddressBookBinder binder = new AddressBookBinder();

            Console.WriteLine("Enter the name of the address book ............");
            int AnotherBook = 1;

            while (AnotherBook == 1)
            {
                string      BookName = Console.ReadLine();
                AddressBook book     = new AddressBook();
                book.contactBook = binder.AddAddressBook(BookName, book.contactBook);

                Console.WriteLine("Welcome to Address Book Program");
                int flag = 1;

                while (flag == 1)
                {
                    Console.WriteLine("Select the option. \n1. for adding new contact. \n2. To edit existing contact. \n3. Delete Contact. \n4 Search by city. \n5.Count by City. \n6 exit");

                    int option = int.Parse(Console.ReadLine());

                    switch (option)
                    {
                    case 1:
                        Console.WriteLine("Enter the person details to be added ...........");
                        Console.WriteLine("First Name");
                        string firstName = Console.ReadLine();
                        Console.WriteLine("Last Name");
                        string lastName = Console.ReadLine();
                        Console.WriteLine("Address");
                        string address = Console.ReadLine();
                        Console.WriteLine("City");
                        string city = Console.ReadLine();
                        Console.WriteLine("State");
                        string state = Console.ReadLine();
                        Console.WriteLine("Zip code");
                        string zip = Console.ReadLine();
                        Console.WriteLine("Phone Number");
                        string phoneNumber = Console.ReadLine();
                        Console.WriteLine("Email");
                        string email = Console.ReadLine();
                        if (book.AddContact(firstName, lastName, address, city, state, zip, phoneNumber, email))
                        {
                            Console.WriteLine("Contact added successfully");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Contact already exists");
                            break;
                        }

                    case 2:
                        Console.WriteLine("Enter the first name of the contact to be edited ");
                        string  name = Console.ReadLine();
                        Contact c    = book.FindContact(name);
                        if (c == null)
                        {
                            Console.WriteLine("Address for {0} couldn't be found.", name);
                            break;
                        }
                        else
                        {
                            Console.WriteLine("New Last Name");
                            c.lastName = Console.ReadLine();
                            Console.WriteLine("New Address");
                            c.address = Console.ReadLine();
                            Console.WriteLine("New City");
                            c.city = Console.ReadLine();
                            Console.WriteLine("New State");
                            c.state = Console.ReadLine();
                            Console.WriteLine("New Zip code");
                            c.zip = Console.ReadLine();
                            Console.WriteLine("New Phone Number");
                            c.phoneNumber = Console.ReadLine();
                            Console.WriteLine("New Email");
                            c.email = Console.ReadLine();
                            Console.WriteLine("Details updated for " + name);
                            break;
                        }

                    case 3:
                        Console.WriteLine("Enter the first name of the contact to be deleted ");
                        string name1 = Console.ReadLine();
                        if (book.RemoveContact(name1))
                        {
                            Console.WriteLine("Contact removed successfully");
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Contact not found");
                            break;
                        }

                    case 4:
                        Console.WriteLine("Enter the city whose contact list is needed.");
                        string City = Console.ReadLine();
                        foreach (Contact co in binder.CityDictionary[City])
                        {
                            Console.WriteLine(co.firstName + "\t" + co.lastName + "\t" + co.city + "\t" + co.state + "\t" + co.zip + "\t" + co.phoneNumber);
                        }
                        break;

                    case 5:
                        foreach (var key in binder.CityDictionary.Keys)
                        {
                            Console.WriteLine(key + "\t" + binder.CityDictionary[key].Count);
                        }
                        break;

                    case 6:
                        flag = 0;
                        break;
                    }
                }
                Console.WriteLine("enter 1 to insert another book and 0 otherwise...");
                AnotherBook = Convert.ToInt32(Console.ReadLine());
                if (AnotherBook == 1)
                {
                    Console.WriteLine("Enter the name of the address book..........");
                }
            }

            foreach (var k in binder.Binder.Keys)
            {
                Console.WriteLine(k);
                foreach (Contact c in binder.Binder[k])
                {
                    Console.WriteLine(c.firstName + "\t" + c.lastName + "\t" + c.city + "\t" + c.state + "\t" + c.zip + "\t" + c.phoneNumber);
                }
            }
        }
Example #14
0
        /// <summary>
        /// Adds the or access address book.
        /// </summary>
        public void AddOrAccessAddressBook()
        {
            // To get the name of the addressbook
            AddressBook addressBook = GetAddressBook();

            // Returns no record found if address book is empty
            if (addressBook == null)
            {
                Console.WriteLine("Action aborted");
                return;
            }

            // select the action to be performed in address book
            while (true)
            {
                Console.WriteLine("\nSelect from below to work on Address book {0}", addressBook.nameOfAddressBook);
                Console.WriteLine("\nType\n\nAdd - To add a contact" +
                                  "\nUpdate- To update a contact" +
                                  "\nView - To view all contacts" +
                                  "\nRemove - To remove a contact and " +
                                  "\nSearch- To search to get contact deatails\nWrite - To write addressbook to file" +
                                  "\nfRead - To read from file" +
                                  "\ncread - To read from CSV" +
                                  "\njread - To read from JSON" +
                                  "\nE - To exit\n ");
                switch (Console.ReadLine().ToLower())
                {
                case ADD_CONTACT:
                    addressBook.AddContact();
                    break;

                case UPDATE_CONTACT:
                    addressBook.UpdateContact();
                    break;

                case SEARCH_CONTACT:
                    addressBook.SearchContactDetails();
                    break;

                case REMOVE_CONTACT:
                    addressBook.RemoveContact();
                    break;

                case GET_ALL_CONTACTS:
                    addressBook.GetAllContacts();
                    break;

                case WRITE:
                    addressBook.WriteAddressBookToFile();
                    break;

                case READFILE:
                    addressBook.ReadAddressBookFromFile();
                    break;

                case READCSV:
                    addressBook.ReadAddressBookFromCSV();
                    break;

                case READJSON:
                    addressBook.ReadAddressBookFromJSON();
                    break;

                default:
                    Console.WriteLine("\nInvalid option. Exiting address book");
                    return;
                }

                // Ask the user to continue in same address book or to exit
                Console.WriteLine("\nType y to continue in same address Book or any other key to exit");

                // If not equal to y  then exit
                if (!(Console.ReadLine().ToLower() == "y"))
                {
                    logger.Debug("User exited the address book " + nameOfAddressBook);
                    return;
                }
            }
        }
Example #15
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Address Book Program in AddressBookMain class on START Master Branch.");
            Dictionary <string, AddressBook> addressBookDict = new Dictionary <string, AddressBook>();

            Console.WriteLine("How many address Book you want to add");
            int numAddressBook = Convert.ToInt32(Console.ReadLine());

            for (int i = 1; i <= numAddressBook; i++)
            {
                Console.WriteLine("Enter the name of address book " + i + ": ");
                string      addressBookName = Console.ReadLine();
                AddressBook addressBook     = new AddressBook();
                addressBookDict.Add(addressBookName, addressBook);
            }
            foreach (var element in addressBookDict)
            {
                Console.WriteLine("Enter how many contacts you want to add in address book " + element.Key);
                int number = Convert.ToInt32(Console.ReadLine());
                for (int i = 1; i <= number; i++)
                {
                    takeInputAndAddToContacts(element.Value);
                }
                element.Value.print();
            }
            Console.WriteLine("Enter Address Book name where you want to edit contact");
            string editContactInAddressBook = Console.ReadLine();

            Console.WriteLine("Enter FirstName of Contact to be edited");
            string firstNameOfContactToBeEdited = Console.ReadLine();

            Console.WriteLine("Enter LastName of Contact to be edited");
            string lastNameOfContactToBeEdited = Console.ReadLine();

            addressBookDict[editContactInAddressBook].edit(firstNameOfContactToBeEdited, lastNameOfContactToBeEdited);
            addressBookDict[editContactInAddressBook].print();
            Console.WriteLine("Enter Address Book name where you want to delete contact");
            string deleteContactInAddressBook = Console.ReadLine();

            Console.WriteLine("Enter FirstName of Contact to be deleted");
            string firstNameOfContactToBeDeleted = Console.ReadLine();

            Console.WriteLine("Enter LastName of Contact to be deleted");
            string lastNameOfContactToBeDeleted = Console.ReadLine();

            addressBookDict[deleteContactInAddressBook].delete(firstNameOfContactToBeDeleted, lastNameOfContactToBeDeleted);
            addressBookDict[deleteContactInAddressBook].print();
            Console.WriteLine("Press c for city or s for state");
            string place = Console.ReadLine();

            place = place.ToLower();
            Console.WriteLine("Enter name of place");
            String findPlace = Console.ReadLine();
            Dictionary <string, List <string> > dictionaryCity  = new Dictionary <string, List <string> >();
            Dictionary <string, List <string> > dictionaryState = new Dictionary <string, List <string> >();
            int countOfPersonsInCity  = 0;
            int countOfPersonsInState = 0;

            foreach (var element in addressBookDict)
            {
                List <String> listOfPersonsinPlace = new List <string>();
                if (place.Equals("c"))
                {
                    listOfPersonsinPlace  = element.Value.findPersonsInCity(findPlace);
                    countOfPersonsInCity += element.Value.findNumberOfPersonsInCity(findPlace);
                    foreach (var name in listOfPersonsinPlace)
                    {
                        if (!dictionaryCity.ContainsKey(findPlace))
                        {
                            List <string> list = new List <string>();
                            list.Add(name);
                            dictionaryCity.Add(findPlace, list);
                        }
                        else
                        {
                            dictionaryCity[findPlace].Add(name);
                        }
                    }
                }
                else
                {
                    listOfPersonsinPlace   = element.Value.findPersonsInState(findPlace);
                    countOfPersonsInState += element.Value.findNumberOfPersonsInState(findPlace);
                    foreach (var name in listOfPersonsinPlace)
                    {
                        if (!dictionaryState.ContainsKey(findPlace))
                        {
                            List <string> list = new List <string>();
                            list.Add(name);
                            dictionaryState.Add(findPlace, list);
                        }
                        else
                        {
                            dictionaryState[findPlace].Add(name);
                        }
                    }
                }
            }
            if (dictionaryCity.Count != 0)
            {
                Console.WriteLine("Number of persons in the city = " + countOfPersonsInCity);
                Console.WriteLine("Persons in the city :-");
                foreach (var mapElement in dictionaryCity)
                {
                    foreach (var listElement in mapElement.Value)
                    {
                        Console.WriteLine(listElement);
                    }
                }
            }
            else
            {
                Console.WriteLine("Number of persons in the state = " + countOfPersonsInState);
                Console.WriteLine("Persons in the state :-");
                foreach (var mapElement in dictionaryState)
                {
                    foreach (var listElement in mapElement.Value)
                    {
                        Console.WriteLine(listElement);
                    }
                }
            }
            Console.WriteLine("Enter the name of address book ");
            string addressBName = Console.ReadLine();

            addressBookDict[addressBName].AlphabeticallyArrange();;
        }
        public void AddAddressBook()
        {
            try
            {
                AddressBook addressBook = GetAddressBook(); //get the name of the addressbook

                if (addressBook == null)                    //address book is empty
                {
                    Console.WriteLine("Address Book Empty");
                    return;
                }

                while (true)
                {
                    Console.WriteLine($"\n**** Welcome To {addressBook.nameOfAddressBook} Address Book System ****");

                    Console.Write("\n1.Add New contact" +
                                  "\n2.Display all contacts" +
                                  "\n3.Edit Record" +
                                  "\n4.Delete Records" +
                                  "\n5.Search Contact Records" +
                                  "\n6.Write Address Book System to txt File" +
                                  "\n7.Write Address Book System to CSV File" +
                                  "\n8.Write Address Book System to JSON File" +
                                  "\n9.Read Txt File" +
                                  "\n10.Read CSV File " +
                                  "\n11.Read JSON File " +
                                  "\n0.Exit\n " +
                                  "\nEnter Your Choice:- ");
                    int choice4 = Convert.ToInt32(Console.ReadLine());

                    switch (choice4)
                    {
                    case 1:
                        addressBook.AddContact();
                        break;

                    case 2:
                        addressBook.GetAllContacts();
                        break;

                    case 3:
                        addressBook.EditContact();
                        break;

                    case 4:
                        addressBook.RemoveContact();
                        break;

                    case 5:
                        addressBook.SearchContactDetails();
                        break;

                    case 6:
                        addressBook.WriteAddressBookToFile();
                        break;

                    case 7:
                        addressBook.WriteAddressBookToCsv();
                        break;

                    case 8:
                        addressBook.WriteAddressBookToJson();
                        break;

                    case 9:
                        addressBook.ReadAddressBookFromFile();
                        break;

                    case 10:
                        addressBook.ReadAddressBookFromCSV();
                        break;

                    case 11:
                        addressBook.ReadAddressBookFromJSON();
                        break;

                    case 0:
                        Console.WriteLine("Exiting Address Book");
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Example #17
0
        public static void AddressBookOptions()
        {
            try
            {
                /// creating instance of Multiple Address Book
                MultipleAddressBook multipleAddressBook = new MultipleAddressBook();
                AddressBook         addressBook1        = new AddressBook();

                //Accepting details for name of addressbook and contact details in addressBook
                //While loop will break if the user enters empty string
                while (true)
                {
                    Console.WriteLine("enter the name of  new Addressbook");
                    string name = Console.ReadLine();
                    if (name == "")
                    {
                        break;            //while loop will break when the if statement is true
                    }
                    AddressBook addressBook = new AddressBook();
                    bool        flag        = true;
                    while (flag)
                    {
                        Console.WriteLine("Please enter your firstname");
                        string firstName = Console.ReadLine();
                        if (firstName == "")
                        {
                            break;
                            //while loop will break when the if statement is true
                        }
                        Console.WriteLine("Please enter your lastname");
                        string lastName = Console.ReadLine();
                        Console.WriteLine("Please enter your Address");
                        string address = Console.ReadLine();
                        Console.WriteLine("Please enter your city");
                        string city = Console.ReadLine();
                        Console.WriteLine("Please enter your state");
                        string state = Console.ReadLine();
                        Console.WriteLine("Please enter your zip");
                        int zip = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Please enter your phone no");
                        double phoneNo = Convert.ToDouble(Console.ReadLine());
                        Console.WriteLine("Please enter your email");
                        string email = Console.ReadLine();
                        addressBook.AddDetailsOfPersons(firstName, lastName, address, city, state, zip, phoneNo, email);
                    }
                    /// calling function to display contact details
                    addressBook.DisplayContactPersonDetails();
                    Console.WriteLine("enter an option ");
                    Console.WriteLine("1. To update the contact details");
                    Console.WriteLine("2. To delete the contact details");
                    int option = Convert.ToInt32(Console.ReadLine());
                    switch (option)
                    {
                    case 1:
                        Console.WriteLine("enter the first name & last name of the person to be updated");
                        string newFirstName = Console.ReadLine();
                        string newLastName  = Console.ReadLine();
                        addressBook1.UpdateContactPersonDetails(newFirstName, newLastName);
                        break;

                    case 2:
                        Console.WriteLine("enter the first name & last name of the person contact to be delete  ");
                        string fName = Console.ReadLine();
                        string lName = Console.ReadLine();
                        addressBook.DeleteContactPersonDetails(fName, lName);
                        break;

                    default:
                        break;
                    }
                    /// adding details in multiple address book using name enter and AddressBook instance created
                    multipleAddressBook.AddMultipleAddressBook(name, addressBook);
                    dictionaryformultiplerecords.Add(name, addressBook.addressBookList);
                    bool flag1 = true;
                    while (flag1)
                    {
                        Console.WriteLine("Press 0 to display all contacts");
                        Console.WriteLine("Press 1 To search by state ");
                        Console.WriteLine("Press 2 To search by city");
                        Console.WriteLine("Press 3 To Write using Stream Reader ");
                        Console.WriteLine("Press 4 To Read all the contacts from file using stream Reader");
                        Console.WriteLine("Press 5 To Write Contacts to a Csv File ");
                        Console.WriteLine("Press 6 To Read all the contacts from Csv file ");
                        Console.WriteLine("Press 7 to exit");
                        int checkOption = Convert.ToInt32(Console.ReadLine());
                        switch (checkOption)
                        {
                        case 0:
                            multipleAddressBook.display();
                            break;

                        case 1:
                            addressBook1.SearchingByState();

                            break;

                        case 2:
                            addressBook1.SearchingByCity();
                            break;

                        case 3:
                            AddressBook.WriteUsingStreamReader();
                            break;

                        case 4:
                            AddressBook.ReadFromStreamReader();
                            break;

                        case 5:
                            Console.WriteLine("Write name of the address Book you which you want to write");
                            string nameOfAddressBook = Console.ReadLine();
                            if (Program.dictionaryformultiplerecords.ContainsKey(nameOfAddressBook))
                            {
                                AddressBook.WritingContactsinCsvFile(dictionaryformultiplerecords, nameOfAddressBook);
                            }
                            else
                            {
                                Console.WriteLine("addressBook Name not Found");
                            }
                            break;

                        case 6:
                            AddressBook.ReadingContactsFromCsvFile();
                            break;

                        case 7:
                            flag1 = false;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(("Invalid entry"));
                Console.WriteLine(ex.Message);
                AddressBookOptions();
            }
        }