Example #1
0
        static void Main(string[] args)
        {
            PhoneBookManager manager = PhoneBookManager.CreateManagerInstance(); //폰북매니저에 생성자를 만들어놓지않아 기본생성자를 호출하는것이였음

            //manager.ReadToFile();
            while (true)
            {
                try
                {
                    int choice;
                    while (true)
                    {
                        manager.ShowMenu();
                        if (int.TryParse(Console.ReadLine(), out choice))
                        {
                            if (choice < 1 || choice > 6)
                            {
                                throw new MenuChoiceException(choice);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    switch (choice)
                    {
                    case 1: manager.InputData(); break;

                    case 2: manager.ListData(); break;

                    case 3: manager.SearchData(); break;

                    case 4: manager.SortData(); break;

                    case 5: manager.DeleteData(); break;

                    case 6: manager.WriteToFile();
                        Console.WriteLine("프로그램을 종료합니다"); return;
                    }
                }
                catch (MenuChoiceException err)
                {
                    err.ShowWrongChoice();
                }
                catch (Exception err)
                {
                    Console.WriteLine(err.Message);
                }
            }
        }