Пример #1
0
        }//constructor

        /// <summary>
        /// This button event is what kicks off the train
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnGo_Click(object sender, EventArgs e)
        {
            btnAddStop.Enabled = false;                             //Disable addstop for duration of journey
            Stop Ttracker;

            if (testString(txtName.Text))                                  //Tests if the ID is valid
            {
                train = new Train(Convert.ToInt32(txtName.Text));          //Instatiate the train
                String res = "";                                           //String that holds the result of the update

                if (journey != null || journey.FirstStop.NextStop == null) //Tests if the journey is not null or if the first stop has no other stops
                {
                    Ttracker      = journey.FirstStop;                     //Set temporary stop to the first stop in the journey
                    lblStops.Text = "Stops:";                              //Set the text for the stops overview label
                    do
                    {
                        //The next stop is null
                        if (Ttracker.NextStop == null)
                        {
                            MessageBox.Show("Detected " + Ttracker.Name + " as last stop"); //Alert the user it detected the current stop as the last
                            lblStops.Text += Ttracker.getLastStopDetails();                 //Provide alternate details text for last stop
                        }
                        else
                        {
                            lblStops.Text += Ttracker.getStopDetails();       //Else provide regular details text
                        }
                        Ttracker = Ttracker.NextStop;                         //Incremenet the stop to the next
                    } while (Ttracker != null);                               //Do while

                    Ttracker       = journey.FirstStop;                       //Set the Tracker back to first stop
                    lblOutput.Text = "First Stop: " + journey.FirstStop.Name; //Change the output text to the first stop
                    do
                    {
                        Ttracker = Ttracker.NextStop;                           //Set the tracker to the next stop
                        res      = await train.StartTrain(journey);             //Start the journey to the next stop and await the response

                        lblOutput.Text += "\n" + res;                           //Output the update response
                    } while (Ttracker.NextStop != null);                        //While the next stop is not null
                }
                else
                {
                    MessageBox.Show("Journey is not Set!");                     //if no journey is found - meaning no stops
                }//if else
            }
            else
            {
                MessageBox.Show("Train ID invalid! (Must be integer)"); //If the Train ID is invalid
            }//else
            btnAddStop.Enabled = true;                                  //Re-enable add stop button
        }//btnGo_Click
Пример #2
0
        }     //testString

        /// <summary>
        /// This method is what does the processing for the journey and displaying the output
        /// </summary>
        /// <param name="train"></param>
        /// <returns></returns>
        private async Task <string> begin(Train train)
        {
            Journey journey = train.TrainJourney;

            btnAddStop.Enabled = false;                                //Disable addstop for duration of journey
            Stop Ttracker;                                             //Tracks what stop the train is at
            //Tests if the ID is valid
            String res = "";                                           //String that holds the result of the update

            if (journey != null && journey.FirstStop.NextStop != null) //Tests if the journey is not null or if the first stop has no other stops
            {
                Ttracker      = journey.FirstStop;                     //Set temporary stop to the first stop in the journey
                lblStops.Text = "Stops:";                              //Set the text for the stops overview label
                do
                {
                    //The next stop is null
                    if (Ttracker.NextStop == null)
                    {
                        lblStops.Text += Ttracker.getLastStopDetails();                 //Provide alternate details text for last stop
                        MessageBox.Show("Detected " + Ttracker.Name + " as last stop"); //Alert the user it detected the current stop as the last
                    }
                    else
                    {
                        lblStops.Text += Ttracker.getStopDetails();       //Else provide regular details text
                    }
                    Ttracker = Ttracker.NextStop;                         //Incremenet the stop to the next
                } while (Ttracker != null);                               //Do while

                Ttracker       = journey.FirstStop;                       //Set the Tracker back to first stop
                lblOutput.Text = "First Stop: " + journey.FirstStop.Name; //Change the output text to the first stop
                do
                {
                    Ttracker = Ttracker.NextStop;                           //Set the tracker to the next stop
                    res      = await train.StartTrain(journey);             //Start the journey to the next stop and await the response

                    lblOutput.Text += "\n" + res;                           //Return the result
                } while (Ttracker.NextStop != null);                        //While the next stop is not null
            }
            else
            {
                MessageBox.Show("Journey is not Set!");                     //if no journey is found - meaning no stops
                return("");
            }//if else
            return("Journey complete");
        }//begin