Exemple #1
0
        static void Main(string[] args)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Welcome to family tree creator!");
            Console.ResetColor();

            List <Person> People = new List <Person>();
            Person        person = new GrandParents();

            People.Add(person);

            Console.WriteLine("Please input the main person");
            person.InputPersonInformation();
            Console.Clear();

            Person currentPerson = person;

            bool isGrandParent = false;
            bool isParent      = false;

            do
            {
                Console.WriteLine("Current person: ");
                currentPerson.ShowPersonIdAndName();

                ShowMenu();
                MenuPoints menuPoint = InputMenu();

                if (menuPoint == MenuPoints.Exit)
                {
                    break;
                }

                if (menuPoint == MenuPoints.SelectMainPerson)
                {
                    currentPerson = person;
                }

                isGrandParent = (currentPerson is GrandParents);
                isParent      = (currentPerson is Parents);

                switch (menuPoint)
                {
                case MenuPoints.ShowPerson:
                {
                    currentPerson.ShowAllPersonInformation();
                    break;
                }

                case MenuPoints.SelectPerson:
                {
                    int condition = 0;
                    Console.Write("ID: ");
                    currentPerson = SelectPerson(People, ref condition);

                    if (condition == 1)
                    {
                        Console.WriteLine("Selection failed!");
                        goto case MenuPoints.SelectMainPerson;
                    }
                    else
                    {
                        Console.WriteLine("Selection complete!");
                        break;
                    }
                }

                case MenuPoints.AddWife_Husband:
                {
                    if (currentPerson.Partner != null)
                    {
                        Console.WriteLine($"{currentPerson.Name} can have one partner only!");
                        break;
                    }

                    AddPartner(People, currentPerson, isGrandParent, isParent);
                    break;
                }

                case MenuPoints.AddChildren:
                {
                    AddChild(People, currentPerson, isGrandParent, isParent);
                    break;
                }

                case MenuPoints.ShowTree:
                {
                    currentPerson = person;
                    ShowTree(currentPerson);
                    break;
                }

                case MenuPoints.SelectMainPerson:
                {
                    currentPerson = person;
                    break;
                }

                default:
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unknown command!");
                    Console.ResetColor();
                    break;
                }
                }

                Console.WriteLine("Input any key to continue the program...");
                Console.ReadKey();
                Console.Clear();
            } while (true);
        }