Esempio n. 1
0
        //DatePicker_SelectedDateChanged: Filters trains by date selected and displays them
        private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            List <Train> filtered = new List <Train>();

            foreach (Train t in MainWindow.Trains)
            {
                if (t.DepartureDay == datePicker.SelectedDate.Value.Date)
                {
                    filtered.Add(t);
                }
            }

            TrainShow window = new TrainShow(filtered);

            window.Show();
            Close();
        }
        //Button_Click: Searches for trains that run between given stations and displays them
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(station1Combo.Text) || string.IsNullOrEmpty(station2Combo.Text))
            {
                MessageBox.Show("Need a selection for both comboboxes!");
                return;
            }
            else if (station1Combo.Text == station2Combo.Text)
            {
                MessageBox.Show("Cannot both be the same!");
                return;
            }

            List <Train> filtered = new List <Train>();

            foreach (Train t in MainWindow.Trains)
            {
                //If the comboboxes are Edinburgh/London then any train suffices
                string[] initial = { "Edinburgh (Waverley)", "London (Kings Cross)" };
                if (initial.Contains(station1Combo.Text) && initial.Contains(station2Combo.Text))
                {
                    filtered.Add(t);
                }
                else if (t is IIntermediate)
                {
                    //Searches for any intermediates that match
                    List <string> full = new List <string>(initial);
                    full.AddRange(((IIntermediate)t).Intermediates);
                    if (full.Contains(station1Combo.Text) && full.Contains(station2Combo.Text))
                    {
                        filtered.Add(t);
                    }
                }
            }

            TrainShow window = new TrainShow(filtered);

            window.Show();
            Close();
        }
        //ShowTrainsBtn_Click: Opens up a window that displays all the Trains
        private void ShowTrainsBtn_Click(object sender, RoutedEventArgs e)
        {
            TrainShow window = new TrainShow(Trains);

            window.Show();
        }