Example #1
0
        private void RoutsButtonUnchecked(object sender, RoutedEventArgs e)
        {
            toAirportBox.IsEnabled   = false;
            fromAirportBox.IsEnabled = false;
            planeBox.IsEnabled       = false;
            flighFreqBox.IsEnabled   = false;
            routDatePicker.IsEnabled = false;
            routTimerLabel.IsEnabled = false;
            generateRout.IsEnabled   = true;

            Rout     rout        = (Rout)GetSelectedItem(routsTreeView);
            Plane    plane       = (Plane)planeBox.SelectedItem;
            Airport  fromAirport = (Airport)fromAirportBox.SelectedItem;
            Airport  toAirport   = (Airport)toAirportBox.SelectedItem;
            DateTime date        = (DateTime)routDatePicker.SelectedDate;

            try
            {
                float    distance;
                DateTime time;

                if (!fromAirport.IsSetUp)
                {
                    throw new Exception("Lotnisko wylotowe nie jest skonfigurowane");
                }
                if (!toAirport.IsSetUp)
                {
                    throw new Exception("Lotnisko docelowe nie jest skonfigurowane");
                }
                if (!plane.IsSetUp)
                {
                    throw new Exception("Samolot nie jest skonfigurowany");
                }
                if (!IsInPlaneRange(plane, fromAirport, toAirport, out distance))
                {
                    throw new Exception("Samolot posiada za mały zasięg! Zasięg samolotu = " + plane.Range + " Odległość: " + distance);
                }
                if (!DateTime.TryParse(routTimerLabel.Text, out time))
                {
                    throw new Exception("Podana data jest nieodpowiednia");
                }

                date = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second);

                rout.SetPlain(plane);
                rout.SetToAirport(toAirport);
                rout.SetFromAirport(fromAirport);
                rout.ChangeDepartureTime(date);
                rout.SetFlightFrequency((FlightFrequency)flighFreqBox.SelectedItem);

                if (!rout.IsSetUp())
                {
                    rout.SetUpFlight();
                }
            }
            catch (NullReferenceException) { PushError("Ustaw poprawne wartości"); }
            catch (Exception ex) { PushError(ex.Message); }
            RefreshTreeView();
        }
Example #2
0
        public void GenerateRout(Rout rout, DateTime date, Airport fromAirport, Airport toAirport, int seats, FlightFrequency flightFrequency)
        {
            float distance = fromAirport.GetDistance(toAirport);
            Plane plane    = FindPlane(distance, seats);

            if (plane == null)
            {
                throw new Exception("Brak samolotu spełniającego kryteria :(");
            }

            rout.SetUpFlight(date, fromAirport, toAirport, plane, flightFrequency);
        }