Example #1
0
 //method for print in console all element of the list
 static void ShowFlight(List <Flying> flyingList, FlyingType enterType)
 {
     for (int i = 0; i < flyingList.Count; i++)
     {
         if (flyingList[i].Type == enterType)
         {
             ShowOneFlight(flyingList, i);
         }
     }
 }
Example #2
0
        //method for add new element in the list
        static void AddFlight(List <Flying> flyingList, FlyingType choise)
        {
            Console.WriteLine("Enter Time in format yyyy-MM-dd HH:mm");
            DateTime timeChoice = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("Enter Flight Number");
            string flNumberChoice = Console.ReadLine().ToUpper();

            Console.WriteLine("Enter Company");
            string companyChoice = Console.ReadLine().ToUpper();

            Terminal terminalChoise = ChooseTerminal();

            FlStatus flStatusChoise;

            Gate gateChoise = ChooseGate();

            string townChoice = "Kharkiv";

            if (FlyingType.Departures == choise)
            {
                Console.WriteLine("Enter Town");
                townChoice     = Console.ReadLine().ToUpper();
                flStatusChoise = ChooseFlStatusArrival();
            }

            else
            {
                flStatusChoise = ChooseFlStatusDepartures();
            }

            flyingList.Add(new Flying
            {
                Time     = timeChoice,
                FlNumber = flNumberChoice,
                Company  = companyChoice,
                Terminal = terminalChoise,
                FlStatus = flStatusChoise,
                Town     = townChoice,
                Gate     = gateChoise,
                Type     = choise
            });

            ShowFlight(flyingList, choise);
        }
Example #3
0
        //method for find nearest flights
        static void FindNearestFlight(List <Flying> flyingList, FlyingType enterType)
        {
            bool noFind = true;

            for (int i = 0; i < flyingList.Count; i++)
            {
                if (flyingList[i].Type == enterType)
                {
                    if (flyingList[i].Time >= DateTime.Now.Subtract(new TimeSpan(0, 1, 0, 0)) && flyingList[i].Time <= DateTime.Now.AddHours(1))
                    {
                        ShowOneFlight(flyingList, i);
                        noFind = false;
                    }
                }
            }

            if (noFind)
            {
                Console.WriteLine("No closest flights");
            }
        }
Example #4
0
        //method for choose what we do
        static void Start(List <Flying> flyingList)
        {
            while (true)
            {
                Console.WriteLine("What you need?");
                Console.WriteLine("Arrival list-enter - 1; departures list-enter - 2; exit fron console - 0");

                int enter = int.Parse(Console.ReadLine());

                if (enter == 0)
                {
                    Environment.Exit(0);
                }

                //We put swich-case in the block try-catch that would catch possible exceptions
                try
                {
                    FlyingType enterType = (FlyingType)Enum.Parse(typeof(FlyingType), enter.ToString());

                    ShowFlight(flyingList, enterType);
                }
                catch (FormatException)
                {
                    Emergency();
                }

                Console.WriteLine("Do you whant add new flight - 1 or delete flight - 2? Find a flight on the specified parameters - 3, Find the nearest flight - 4" +
                                  "change somthin in list - 5");
                try
                {
                    int enterChoise = int.Parse(Console.ReadLine());

                    switch (enterChoise)
                    {
                    case 1:
                        Console.WriteLine("Do you whant add new arrival - 1 or departures - 2");
                        FlyingType enterType = (FlyingType)Enum.Parse(typeof(FlyingType), Console.ReadLine());
                        AddFlight(flyingList, enterType);
                        break;

                    case 2:
                        Console.WriteLine("Do you whant delete  arrival - 1 or departures - 2");
                        enterType = (FlyingType)Enum.Parse(typeof(FlyingType), Console.ReadLine());
                        DeleteFlight(flyingList);
                        ShowFlight(flyingList, enterType);
                        break;

                    case 3:
                        FindFlight(flyingList);
                        break;

                    case 4:
                        Console.WriteLine("Find a nearest flight arrival - 1 or departures - 2");
                        enterType = (FlyingType)Enum.Parse(typeof(FlyingType), Console.ReadLine());
                        FindNearestFlight(flyingList, enterType);
                        break;

                    case 5:
                        Console.WriteLine("change somthin in flight");
                        ChangeFlight(flyingList);
                        break;
                    }
                }
                catch (FormatException)
                {
                    Emergency();
                }
            }
        }