コード例 #1
0
        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\nE - To exit\n ");

                switch (Console.ReadLine().ToLower())
                {
                case ADD_CONTACT:

                    addressBook.AddContact();
                    break;

                case UPDATE_CONTACT:

                    addressBook.UpdateContact();
                    break;

                case SEARCH_CONTACT:

                    addressBook.DisplayContactDetails();
                    break;

                case REMOVE_CONTACT:

                    addressBook.RemoveContact();
                    break;

                case GET_ALL_CONTACTS:

                    addressBook.GetAllContacts();
                    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;
                }
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
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);
                }
            }
        }
コード例 #4
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());
            }
        }
コード例 #5
0
        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);
                }
            }
        }