Beispiel #1
0
        /// <summary>
        /// on send button click Flight Window is created and subscribers defined
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            var          flightNumber    = txtFlightNumber.Text;           //
            FlightWindow flightWindowObj = new FlightWindow(flightNumber); // declare and create Flight Window object (publisher)

            flightWindowObj.Show();
            flightWindowObj.ChangesHandler += OnChangesHandler;                  // add subscriber
            flightWindowObj.LandedHandler  += OnChangesHandler;                  // add subscriber
            flightWindowObj.LandedHandler  += arrivalWindowObj.OnArrivalHandler; // add subscriber
        }
        /// <summary>
        /// Called when the Send button is clicked.
        /// Create a subwindow for the given flight, and add listeners for its events.
        /// </summary>
        private void Button_Send_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("Du klickade Sänd plan till starten");
            var flightName = txtFlightCode.Text;

            if (string.IsNullOrEmpty(flightName))
            {
                throw new InvalidOperationException("flight code must not be empty when the Send button is clicked.");
            }
            var flightWindow = new FlightWindow(flightName);

            flightWindow.FlightChanged_handlers   += OnFlightChanged_handler;
            flightWindow.StartedOrLanded_handlers += OnFlightChanged_handler;
            flightWindow.StartedOrLanded_handlers += OnStartedOrLanded_handler;
        }
 /// <summary>
 /// Click event for "Start new flight" button
 /// </summary>
 /// <param name="sender">the object sending the event</param>
 /// <param name="e">event arguments</param>
 private void StartNewFlightBtn_Click(object sender, RoutedEventArgs e)
 {
     if (!string.IsNullOrEmpty(CheckFormatOfFlightCode(FlightCodeTextBox.Text)))
     {
         FlightWindow flight = new FlightWindow(FlightCodeTextBox.Text);
         flight.Show();
         SubscribeToTheEventsOfFlightWindow(flight);
     }
     else if (!string.IsNullOrEmpty(FlightCodeTextBox.Text) && string.IsNullOrEmpty(CheckFormatOfFlightCode(FlightCodeTextBox.Text)))
     {
         MessageBox.Show("Please supply a flight code in the form ABC AB123 (in the case of SAS: SAS, American Airlines: AAL, Lufthansa: DLH))", "Take note");
     }
     else
     {
         MessageBox.Show("Please supply a flight code", "Take note");
     }
 }
 /// <summary>
 /// Subscribes the the events of the FlightWindow
 /// </summary>
 /// <param name="flightWindow">The flightWindow object containing the events</param>
 private void SubscribeToTheEventsOfFlightWindow(FlightWindow flightWindow)
 {
     flightWindow.takeOffEvent     += TakeOffHandler;
     flightWindow.landEvent        += NewLandingHandler;
     flightWindow.changeRouteEvent += ChangeRouteHandler;
 }