private void ButtonStop_Click(object sender, RoutedEventArgs e) { if (MyTimer != null) { MyTimer.Stop(); } Label_time.Content = ""; ButtonStart.IsEnabled = true; ButtonStop.IsEnabled = false; ButtonPause.IsEnabled = false; MySimFlights.Clear(); Stack_sim.Visibility = Visibility.Collapsed; Stack_ScheduledFlights.Visibility = Visibility.Visible; }
private void ButtonStart_Click(object sender, RoutedEventArgs e) { if (MyScheduledFlights.Count == 0) { MessageBox.Show("No flight !", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if (Datepicker_flight.Text.Length == 0) { MessageBox.Show("No date !", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { //Je remet tout a SCHEDULED foreach (ClassScheduledFlight item in MyScheduledFlights) { item.Flight.Status = ClassGenericFlight.SCHEDULED; } //J'ajoute Les vols programmé foreach (ClassScheduledFlight item in MyScheduledFlights) { if (item.Date.Equals(Convert.ToDateTime(Datepicker_flight.Text))) { MySimFlights.Add(item); } } if (MySimFlights.Count == 0) { MessageBox.Show("No flight for this date !", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else { ButtonStart.IsEnabled = false; ButtonPause.IsEnabled = true; ButtonStop.IsEnabled = true; ButtonFaster.IsEnabled = true; ButtonSlower.IsEnabled = true; Vitesse = 700; Stack_ScheduledFlights.Visibility = Visibility.Collapsed; Stack_sim.Visibility = Visibility.Visible; var t = new ObservableCollection <ClassScheduledFlight>(); SortSim(); DateTime tmp = Convert.ToDateTime(Datepicker_flight.Text); DateTime Aujourdhui = new DateTime(tmp.Year, tmp.Month, tmp.Day, 0, 0, 0, DateTimeKind.Local); MyTimer = new System.Windows.Forms.Timer(); MyTimer.Stop(); MyTimer.Tick += (Sender, eventArgs) => { if (!Pause) { //Définir le status foreach (ClassScheduledFlight item in MySimFlights) { item.Flight.UpdateFlightStatus(Aujourdhui); } t.Clear(); foreach (ClassScheduledFlight item in MySimFlights) { if (item.Flight.Status.Equals(ClassGenericFlight.FLYING)) { t.Add(item); } } foreach (ClassScheduledFlight item in t) { MySimFlights.Remove(item); } Datagrid_sim.DataContext = MySimFlights; Datagrid_sim.Items.Refresh(); Label_time.Content = String.Format("{0:d/MM/yyyy HH:mm:ss}", Aujourdhui); Aujourdhui = Aujourdhui.AddMinutes(5); MyTimer.Interval = Vitesse; if (MySimFlights.Count == 0) { ButtonFaster.IsEnabled = false; ButtonSlower.IsEnabled = false; ButtonStop.IsEnabled = true; Label_time.Content = "Simulation ended"; t.Clear(); MySimFlights.Clear(); ButtonStart.IsEnabled = true; ButtonPause.IsEnabled = false; MyTimer.Stop(); } } }; MyTimer.Interval = Vitesse; MyTimer.Start(); } } }