示例#1
0
        private void BtnSearchConnection_Click(object sender, EventArgs e)
        {
            // catches WebException if no connection to the internet is available
            try
            {
                Stations stationsOfFromLocation = transport.GetStations(txtFromLocation.Text);
                Stations stationsOfToLocation   = transport.GetStations(txtToLocation.Text);

                bool hasErrors = SearchConnectionErrors(stationsOfFromLocation, stationsOfToLocation);

                if (!hasErrors)
                {
                    /* StationList[0] is alway the most likely location or if you already have a valid location it will be that
                     * this way if you for example have a to location with value "lu" it will automatically be turned into "Luzern"
                     * if you already have "Luzern" it will stay "Luzern" */
                    string fromLocation = stationsOfFromLocation.StationList[0].Name;
                    string toLocation   = stationsOfToLocation.StationList[0].Name;
                    // catches JsonSerializableException if no coordinates were found for a given location
                    try
                    {
                        GUIResults formConnections = new GUIResults(fromLocation, toLocation, dateTimePicker.Text);
                        formConnections.ShowDialog();
                    }
                    catch (JsonSerializationException)
                    {
                        MessageBox.Show("Von der SBB Schnittstelle wurden keine Koordinaten zu diesem Ort gefunden.");
                    }
                }
            }
            catch (WebException)
            {
                MessageBox.Show("Sie benötigen eine funktionierende Internetverbindung.");
            }
        }
示例#2
0
        private void BtnCreateTimetable_Click(object sender, EventArgs e)
        {
            try
            {
                Stations stationsOfTimetableLocation = transport.GetStations(txtTimetableLocation.Text);
                bool     hasErrors = SearchTimetableErrors(stationsOfTimetableLocation);

                if (!hasErrors)
                {
                    try
                    {
                        string     timetableLocation = stationsOfTimetableLocation.StationList[0].Name;
                        GUIResults formTimetable     = new GUIResults(timetableLocation);
                        formTimetable.ShowDialog();
                    }
                    catch (JsonSerializationException)
                    {
                        MessageBox.Show("Von der SBB Schnittstelle wurden keine Koordinaten zu diesem Ort gefunden.");
                    }
                }
            }
            catch (WebException)
            {
                MessageBox.Show("Sie benötigen eine funktionierende Internetverbindung.");
            }
        }