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; } }
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; } }); }
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(); }
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(); }