public void RemoveRout(Rout rout) { //Gdy trasa jest stworzona i ustalona if (rout.IsSetUp()) { //Lista psażerów do usunięcia List <Customer> cusToRemove = new List <Customer>(); rout.GetSchedules().ForEach(s => { s.GetPassengersList().ForEach(p => { cusToRemove.Add(p); //p.SetFlightSchedule(null); }); }); //Usuń loty dla każdego pasażera cusToRemove.ForEach(c => c.SetFlightSchedule(null)); } Routs.Remove(rout); //Ustaw status samolotu na wolny i sprawdź czy jest wykorzystywany w innych lotach, //Jak tak to zmień jego status ponownie rout.Plane.Unassign(); Routs.ForEach(r => { if (r.Plane == rout.Plane) { rout.Plane.Assign(); return; } }); }
public void AddRoutButtonClick(object sender, RoutedEventArgs e) { Rout rout = new Rout(DateTime.Now, FlightFrequency.ONE_FLIGHT); central.AddRout(rout); RefreshTreeView(); }
private void RoutsItemClick(object sender, object e) { Rout routs = (Rout)GetSelectedItem(routsTreeView); if (routs == null) { return; } ShowGroupBox(routGroup); flighFreqBox.SelectedItem = routs.FlightFrequency; toAirportBox.SelectedItem = routs.ToAirport; fromAirportBox.SelectedItem = routs.FromAirport; planeBox.SelectedItem = routs.Plane; routDatePicker.SelectedDate = routs.FirstDeparturTime; schedulesComboBox.ItemsSource = routs.GetSchedules(); routTimerLabel.Text = routs.FirstDeparturTime.ToString("HH:mm:ss"); passengersTreeView.ItemsSource = null; schedulesComboBox.SelectedItem = null; seatsAndSeatsLimitLabel.Content = "--/--"; flightArriveTime.Content = "--"; if (routs.IsSetUp()) { generateRout.IsEnabled = false; } else { generateRout.IsEnabled = true; } }
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(); }
public void AddRout(Rout route) { if (Routs.Contains(route)) { throw new ApplicationException("Rout already exist"); } Routs.Add(route); }
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); }
private void GenerateRoutButtonUnchecked(object sender, RoutedEventArgs e) { routsCheckBox.IsEnabled = true; fromAirportBox.IsEnabled = false; toAirportBox.IsEnabled = false; flighFreqBox.IsEnabled = false; seatsLimitLabel.IsEnabled = false; routDatePicker.IsEnabled = false; routTimerLabel.IsEnabled = false; Rout rout = (Rout)GetSelectedItem(routsTreeView); Airport fromAirport = (Airport)fromAirportBox.SelectedItem; Airport toAirport = (Airport)toAirportBox.SelectedItem; DateTime date = (DateTime)routDatePicker.SelectedDate; int numberOfSeats; DateTime time; try { if (!fromAirport.IsSetUp) { throw new Exception("Lotnisko wylotowe nie jest skonfigurowane"); } if (!toAirport.IsSetUp) { throw new Exception("Lotnisko docelowe nie jest skonfigurowane"); } if (!Int32.TryParse(seatsLimitLabel.Text, out numberOfSeats)) { throw new Exception("Nieprawidłowa liczba miejsc"); } if (DateTime.TryParse(routTimerLabel.Text, out time)) { date = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second); } else { throw new Exception("Podana data jest nieodpowiednia"); } central.GenerateRout(rout, date, fromAirport, toAirport, numberOfSeats, (FlightFrequency)flighFreqBox.SelectedItem); generateRout.IsEnabled = false; RoutsItemClick(sender, null); } catch (NullReferenceException) { PushError("Ustaw poprawne wartości"); } catch (Exception ex) { PushError(ex.Message); } RefreshTreeView(); }
private void RoutsButtonChecked(object sender, RoutedEventArgs e) { Rout rout = (Rout)GetSelectedItem(routsTreeView); if (!rout.IsSetUp()) { fromAirportBox.IsEnabled = true; toAirportBox.IsEnabled = true; } generateRout.IsEnabled = false; routDatePicker.IsEnabled = true; planeBox.IsEnabled = true; flighFreqBox.IsEnabled = true; routTimerLabel.IsEnabled = true; }
private void ShowPreviousFlightSchedule(object sender, RoutedEventArgs e) { Rout rout = (Rout)customerFlighBox.SelectedItem; if (rout == null || !rout.IsSetUp()) { return; } try { Schedule schedule = rout.PreviousSchedule((Schedule)customerFlightScheduleLabel.DataContext); SetTextBoxDataContextAndText(customerFlightScheduleLabel, schedule); customerFlightArriveTime.Content = schedule.GetArrivalTimeAsString(); } catch (FlightFrequencyException ex) { PushError(ex.Message); } }
private void CustomerFlightChangedEvent(object sender, SelectionChangedEventArgs e) { Rout rout = (Rout)((ComboBox)sender).SelectedItem; if (rout == null) { return; } if (!rout.IsSetUp()) { customerFlightScheduleLabel.Text = ""; ((ComboBox)sender).SelectedItem = null; PushError("Wybrany lot nie jest skonfigurowany!"); return; } Schedule schedule = rout.GetSchedules().ElementAt <Schedule>(0); SetTextBoxDataContextAndText(customerFlightScheduleLabel, schedule); customerFlightArriveTime.Content = schedule.GetArrivalTimeAsString(); }
public Schedule(DateTime Departuretime, DateTime Arrivaltime, Rout rout) { this.Departuretime = Departuretime; this.Arrivaltime = Arrivaltime; this.Rout = rout; }