Пример #1
0
        /// <summary>
        /// Load the already existing address books records from files
        /// </summary>
        /// <param name="multipleAddressBooks"></param>
        public void LoadExistingAddressBooks(MultipleAddressBooks multipleAddressBooks)
        {
            if (filePaths.Length == 0)
            {
                Console.WriteLine("No address books present");
                return;
            }
            Console.WriteLine("Address Books Present");
            int count = 1;

            foreach (string paths in filePaths)
            {
                string addressBookName = Path.GetFileNameWithoutExtension(paths);
                Console.WriteLine(count++ + "." + addressBookName);

                multipleAddressBooks.AddAddressBook(addressBookName);

                Address_Book    addressBook = multipleAddressBooks.GetAddressBook(addressBookName);
                List <Contacts> contactList = GetAddressBookRecords(paths);

                foreach (var contacts in contactList)
                {
                    addressBook.contactList.Add(contacts);
                }
            }
        }
 /// <summary>
 /// Add a new address book
 /// </summary>
 /// <param name="name"></param>
 public void AddAddressBook(string name)
 {
     if (addressBooksCollection.ContainsKey(name) == false)
     {
         Address_Book addressBook = new Address_Book();
         addressBooksCollection.Add(name, addressBook);
     }
     else
     {
         Console.WriteLine("Address Book Already Exist");
     }
 }
Пример #3
0
        public void EditAddOrDeleteContact(Address_Book addressBook, string addressBookName)
        {
            string[] name;
            int      choice = 0;

            string[]          details;
            bool              flag = true;
            ReadOrWriteToFile rw   = new ReadOrWriteToFile();

            while (flag)
            {
                Console.WriteLine("------------------------------------------------------------------------");
                Console.WriteLine("1.Add Contact\n2.Edit Contact\n3.Remove a contact\n4.Sort By Name\n5.Sort By City\n6.Sort By State\n7.Sort By ZipCode\n8.Write To File\n9.Read from File\n10.Exit");
                Console.WriteLine("------------------------------------------------------------------------");
                choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter the details separated by comma");
                    Console.WriteLine("First Name, Last Name, Address, City, State, ZipCode,Phone No Email");
                    details = Console.ReadLine().Split(",");

                    string message = addressBook.AddContact(details[0], details[1], details[2], details[3], details[4], details[5], details[6], details[7]);

                    Console.WriteLine(message);

                    break;

                case 2:
                    Console.WriteLine("Enter the name to edit");
                    name = Console.ReadLine().Split(" ");

                    if (addressBook.CheckName(name[0], name[1]) == true)
                    {
                        Console.WriteLine("Enter the following details separated by comma");
                        Console.WriteLine("FirstName,LastName,Address, City, State, ZipCode,Phone No Email");
                        details = Console.ReadLine().Split(",");
                        addressBook.EditContact(details[0], details[1], details[2], details[3], details[4], details[5], details[6], details[7]);
                        Console.WriteLine("Details editted successfully");
                    }
                    else
                    {
                        Console.WriteLine("No such contact found");
                    }
                    break;

                case 3:
                    Console.WriteLine("Enter the name to be removed");
                    name = Console.ReadLine().Split(" ");
                    if (addressBook.CheckName(name[0], name[1]) == true)
                    {
                        addressBook.RemoveContact(name[0], name[1]);
                        Console.WriteLine("Contact Removed Successfully");
                    }
                    else
                    {
                        Console.WriteLine("No such contact found");
                    }
                    break;

                case 4:
                    addressBook.SortByName();
                    break;

                case 5:
                    addressBook.SortByCity();
                    break;

                case 6:
                    addressBook.SortByState();
                    break;

                case 7:
                    addressBook.SortByZipCode();
                    break;

                case 8:
                    rw.ClearFile();
                    rw.WriteToFile(addressBookName, addressBook.contactList);
                    rw.WriteToCSV(addressBook.contactList);
                    rw.WriteToJsonFile(addressBook.contactList);
                    Console.WriteLine("Written to file successfully");
                    break;

                case 9:
                    Console.WriteLine("From text file :");
                    rw.ReadFromFile();
                    Console.WriteLine("From csv file :");
                    rw.ReadFromCSV();
                    Console.WriteLine("From json file :");
                    rw.ReadFromJsonFile();
                    break;

                case 10:
                    flag = false;
                    break;

                default:
                    Console.WriteLine("Invalid choice");
                    break;
                }
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            int    choice;
            string addBookName = "";

            MultipleAddressBooks   multipleAddressBooks = new MultipleAddressBooks();
            OperationOnAddressBook operation            = new OperationOnAddressBook();
            Address_Book           addressBook          = null;

            Console.WriteLine("Welcome to Address Book Program");
            while (true)
            {
                Console.WriteLine("------------------------------------------------------------------------");
                Console.WriteLine("1.Add Address Book\n2.Edit Or Add Contact in Address Book\n3.View Persons By City\n4.View Persons By State\n5.Count By City\n6.Count By State\n7.Exit");
                Console.WriteLine("------------------------------------------------------------------------");
                choice = Convert.ToInt32(Console.ReadLine());

                switch (choice)
                {
                case 1:
                    Console.WriteLine("Enter name of Address Book");
                    addBookName = Console.ReadLine();
                    multipleAddressBooks.AddAddressBook(addBookName);

                    break;

                case 2:
                    Console.WriteLine("Enter name of Address Book");
                    addBookName = Console.ReadLine();
                    addressBook = multipleAddressBooks.GetAddressBook(addBookName);

                    if (addressBook != null)
                    {
                        operation.EditAddOrDeleteContact(addressBook, addBookName);
                    }
                    else
                    {
                        Console.WriteLine("No such Adress Book");
                    }
                    break;

                case 3:
                    Console.WriteLine("Enter City");
                    string city = Console.ReadLine();
                    multipleAddressBooks.SetContactByCityDictionary();

                    multipleAddressBooks.ViewPersonsByCity(city);
                    break;

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

                    multipleAddressBooks.SetContactByStateDictionary();
                    multipleAddressBooks.ViewPersonsByState(state);
                    break;

                case 5:
                    multipleAddressBooks.SetContactByCityDictionary();
                    foreach (var contactByCity in multipleAddressBooks.ContactByCity)
                    {
                        Console.WriteLine("City :" + contactByCity.Key + "   Count :" + contactByCity.Value.Count);
                    }
                    break;

                case 6:
                    multipleAddressBooks.SetContactByStateDictionary();
                    foreach (var contactByState in multipleAddressBooks.ContactByState)
                    {
                        Console.WriteLine("State :" + contactByState.Key + "   Count :" + contactByState.Value.Count);
                    }

                    break;

                case 7:
                    Environment.Exit(0);
                    break;

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