static void Main(string[] args)
        {
            int       flag      = 0;
            PhoneBook phoneBook = new PhoneBook();

            PhoneNumber phoneNumber1 = new PhoneNumber("Trung", "123456");
            PhoneNumber phoneNumber2 = new PhoneNumber("Truong", "223456");
            PhoneNumber phoneNumber3 = new PhoneNumber("Thanh", "323456");

            phoneBook.AddPhoneList(phoneNumber1);
            phoneBook.AddPhoneList(phoneNumber2);
            phoneBook.AddPhoneList(phoneNumber3);

            do
            {
                Console.WriteLine("PHONEBOOK MANAGEMENT SYSTEM");
                Console.WriteLine("1. Insert phone");
                Console.WriteLine("2. Remove phone");
                Console.WriteLine("3. Update phone");
                Console.WriteLine("4. Search phone");
                Console.WriteLine("5. Exit");
                Console.WriteLine("6. Show all");
                Console.WriteLine("Please choose an option");
                int choice = Convert.ToInt32(Console.ReadLine());
                if (choice < 7 && choice > 0)
                {
                    switch (choice)
                    {
                    case 1:
                        Console.WriteLine("Name: ");
                        String name = Console.ReadLine();
                        Console.WriteLine("Phone: ");
                        String phone = Console.ReadLine();
                        phoneBook.insertPhone(name, phone);
                        break;

                    case 2:
                        Console.WriteLine("Name: ");
                        String name1 = Console.ReadLine();
                        phoneBook.removePhone(name1);
                        break;

                    case 3:
                        Console.WriteLine("Name: ");
                        String name3 = Console.ReadLine();
                        Console.WriteLine("Phone: ");
                        String phone3 = Console.ReadLine();
                        phoneBook.updatePhone(name3, phone3);
                        break;

                    case 4:
                        Console.WriteLine("Name: ");
                        String name4 = Console.ReadLine();
                        phoneBook.searchPhone(name4);
                        break;

                    case 5:
                        flag = 1;
                        break;

                    case 6:
                        for (int i = 0; i < phoneBook.PhoneList.Count; i++)
                        {
                            Console.WriteLine();
                            Console.Write("Name: ");
                            Console.Write(phoneBook.PhoneList[i].Name);
                            Console.Write("\t\t");
                            Console.Write("Phone: ");
                            Console.Write(phoneBook.PhoneList[i].Phone);
                        }
                        Console.WriteLine();
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("Your choice is from 1 to 5");
                }
            } while (flag == 0);

            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            String         choice, name, phone, exit;
            List <Contact> arrContact = new List <Contact>();
            PhoneBook      phoneBook  = new PhoneBook(arrContact);

            while (true)
            {
                Console.WriteLine("PHONEBOOK MANAGEMENT SYSTEM:" + "\n"
                                  + "1. Insert Phone" + "\n"
                                  + "2. Remove Phone" + "\n"
                                  + "3. Update Phone" + "\n"
                                  + "4. Search Phone" + "\n"
                                  + "0. Exit" + "\n"
                                  + "Your choice: "
                                  );
                choice = Console.ReadLine().Trim();
                switch (choice)
                {
                case ("1"):    //================Insert Phone==============
                    Console.WriteLine("Please input Name and Phone to Insert: ");
                    Console.WriteLine("Name: ");
                    name = Console.ReadLine();
                    Console.WriteLine("Phone: ");
                    phone = Console.ReadLine();
                    phoneBook.insertPhone(name, phone);

                    break;

                case ("2"):    //================Remove Phone==============
                    Console.WriteLine("Please input Name to Remove: ");
                    name = Console.ReadLine();
                    phoneBook.removePhone(name);

                    break;

                case ("3"):    //================Update Phone==============
                    Console.WriteLine("Please input Name to Update: ");
                    Console.WriteLine("Name: ");
                    name = Console.ReadLine();
                    Console.WriteLine("New Phone: ");
                    phone = Console.ReadLine();
                    phoneBook.updatePhone(name, phone);
                    break;

                case ("4"):    //================Search Phone==============
                    Console.WriteLine("Please input Name to Search: ");
                    Console.WriteLine("Name: ");
                    name = Console.ReadLine();
                    phoneBook.searchPhone(name);
                    break;

                case ("0"):    //================EXIT==============
                    return;

                default:    //=============Wrong Choice==============
                    Console.WriteLine("Wrong Choice!");
                    break;
                }
            }
            Console.ReadKey();
        }