Ejemplo n.º 1
0
 private void btnhaltestellesearch_Click(object sender, EventArgs e)
 {
     try
     {
         dgverbindungen.Rows.Clear();
         SwissTransport.Transport stationboard = new SwissTransport.Transport();
         var station = stationboard.GetStationBoard(txthaltestelle.Text);
         foreach (var stat in station.Entries)
         {
             DataGridViewRow row = (DataGridViewRow)dgverbindungen.Rows[0].Clone();
             row.Cells[0].Value      = txthaltestelle.Text;
             row.Cells[1].Value      = stat.Stop.Departure.ToShortTimeString();
             row.Cells[1].Value      = row.Cells[1].Value + " h";
             row.Cells[2].Value      = stat.Stop.Platform;
             ankunftsstation.Visible = false;
             ankunftszeit.Visible    = false;
             ankunftszone.Visible    = false;
             verspätung.Visible      = false;
             dgverbindungen.Rows.Add(row);
         }
     }
     catch
     {
         MessageBox.Show("Es ist keine gültige Haltestelle eingetragen", "Fehler!");
     }
 }
Ejemplo n.º 2
0
 private void btnsearch_Click(object sender, EventArgs e)
 {
     try
     {
         dgverbindungen.Rows.Clear();
         SwissTransport.Transport connection = new SwissTransport.Transport();
         var connect = connection.GetConnections(txtvon.Text, txtbis.Text);
         foreach (var conn in connect.ConnectionList)
         {
             abfahrtsstation.Visible = true;
             abfahrtszeit.Visible    = true;
             abfahrtszone.Visible    = true;
             ankunftsstation.Visible = true;
             ankunftszeit.Visible    = true;
             ankunftszone.Visible    = true;
             verspätung.Visible      = true;
             DataGridViewRow row = (DataGridViewRow)dgverbindungen.Rows[0].Clone();
             row.Cells[0].Value = txtvon.Text;
             row.Cells[1].Value = DateTime.Parse(conn.From.Departure).ToString("HH:mm");
             row.Cells[1].Value = row.Cells[1].Value + " h";
             row.Cells[2].Value = conn.From.Platform;
             row.Cells[3].Value = txtbis.Text;
             row.Cells[4].Value = DateTime.Parse(conn.To.Arrival).ToString("HH:mm");
             row.Cells[4].Value = row.Cells[4].Value + " h";
             row.Cells[5].Value = conn.To.Platform;
             row.Cells[6].Value = conn.To.Delay;
             dgverbindungen.Rows.Add(row);
         }
     }
     catch
     {
         MessageBox.Show("Es sind keine gültigen Haltestellen eingetragen", "Fehler!");
     }
 }
Ejemplo n.º 3
0
        private void txthaltestelle_TextChanged(object sender, EventArgs e)
        {
            lbhaltestelle.Items.Clear();
            lbhaltestelle.Visible = true;
            //lbhaltestelle.
            SwissTransport.Transport stationquery = new SwissTransport.Transport();
            var station = stationquery.GetStations(txthaltestelle.Text);

            foreach (var stat in station.StationList)
            {
                lbhaltestelle.Items.Add(stat.Name);
            }
        }
Ejemplo n.º 4
0
        //In this code section the Stations will be written down to the Comboboxes.
        private void ComboBoxStartStop_DropDown(object sender, EventArgs e)
        {
            //The stations from the API are written down to the checkbox
            ComboBox comboboxload = (ComboBox)sender;

            SwissTransport.Transport transport = new SwissTransport.Transport();
            var foundStations = transport.GetStations(comboboxload.Text);

            //Every station, that is found, is written down in the checkbox.
            foreach (var station in foundStations.StationList)
            {
                comboboxload.Items.Add(station.Name);
            }
        }
Ejemplo n.º 5
0
 private void txtbis_TextChanged(object sender, EventArgs e)
 {
     if (changed == true)
     {
         lbankunft.Items.Clear();
         lbankunft.Visible = true;
         SwissTransport.Transport stationquery = new SwissTransport.Transport();
         var station = stationquery.GetStations(txtbis.Text);
         foreach (var stat in station.StationList)
         {
             lbankunft.Items.Add(stat.Name);
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// returns the station with the most similarity to the text
        /// </summary>
        /// <param name="station"></param>
        public SwissTransport.Station GetStation(string station)
        {
            SwissTransport.Transport      transport = new SwissTransport.Transport();
            List <SwissTransport.Station> stations  = new List <SwissTransport.Station>();

            stations = transport.GetStations(station).StationList;

            if (stations.Count() > 0)
            {
                return(stations.First());
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// returns List of strings which you can print afterwards.
        /// The list contains stations name which are similare to the parameter string
        /// </summary>
        /// <param name="station"></param>
        /// <returns></returns>
        public List <string> GetStationNameSuggestion(string station)
        {
            List <string> output = new List <string>();

            SwissTransport.Transport      transport         = new SwissTransport.Transport();
            List <SwissTransport.Station> transportStations = new List <SwissTransport.Station>();

            transportStations = transport.GetStations(station).StationList;
            foreach (SwissTransport.Station transportStation in transportStations)
            {
                string stationname = transportStation.Name;
                output.Add(stationname);
            }

            return(output);
        }
Ejemplo n.º 8
0
        //When using the Dropdown event the Stations are getting Loaded in the Dropdown$
        private void cboxload_DropDown(object sender, EventArgs e)
        {
            ComboBox cboxload = (ComboBox)sender;

            SwissTransport.Transport transport = new SwissTransport.Transport();
            var foundStations = transport.GetStations(cboxload.Text);

            try
            {
                foreach (var station in foundStations.StationList)
                {
                    cboxload.Items.Add(station.Name);
                }
            }
            catch (WebException ex)
            {
                MessageBox.Show($"Zu viele Anfragen an den Server\nBitte kurz warten befor sie fortfahren\n\n{ex}");
            }
        }
Ejemplo n.º 9
0
        private void BtnSearchStation_Click(object sender, EventArgs e)
        {
            string station = txtStation.Text;

            SwissTransport.Transport StationConnetions = new SwissTransport.Transport();
            try
            {
                List <SwissTransport.Station> stationList = StationConnetions.GetStations(station).StationList;
                if (stationList.Count != 0)
                {
                    //Enthält das erste Objekt der Klasse Station von der Liste stationList
                    SwissTransport.Station UsedStation = stationList[0];

                    //Erstellt eine Liste welche Objekte der Klasse StationBoard beinhaltet, welche mit dem Namen und der Id der UsedStation übereinstimmen
                    List <SwissTransport.StationBoard> EntriesConnections = StationConnetions.GetStationBoard(UsedStation.Name, UsedStation.Id).Entries;

                    //Enthält das Objekt der Klasse Station, welches mit dem Namen und der Id der UsedStation übereinstimmt
                    SwissTransport.Station EntriesStation = StationConnetions.GetStationBoard(UsedStation.Name, UsedStation.Id).Station;

                    dgvOutputStation.Rows.Clear();

                    if (EntriesConnections.Count != 0)
                    {
                        foreach (SwissTransport.StationBoard stationBoard in EntriesConnections)
                        {
                            dgvOutputStation.Rows.Add(EntriesStation.Name, stationBoard.To, stationBoard.Stop.Departure.ToShortTimeString(), stationBoard.Category, stationBoard.Number);
                        }
                    }
                    else
                    {
                        MessageError();
                    }
                }
                else
                {
                    MessageError();
                }
            }
            catch
            {
                MessageConnectionError();
            }
        }
Ejemplo n.º 10
0
        //This event controls the actions, if the Button "Verbindung suchen" is clicked.
        private void BtnConnections_Click(object sender, EventArgs e)
        {
            //The items and columns in the ListView will be cleared if the button is clicked. Also 4 new Colums are getting created.
            //The Event .Items.Clear and .Colums.Clear, deletes eery item and every Column in the ListView.
            //.Columns.Add ist responsible for creating new Colums. These colums are used to view the Details for the Route.
            ListViewResult.Items.Clear();
            ListViewResult.Columns.Clear();
            ListViewResult.Columns.Add("Gleis");
            ListViewResult.Columns.Add("Abfahrt");
            ListViewResult.Columns.Add("Dauer");
            ListViewResult.Columns.Add("Ankunft");

            //In this section of the Code the Connections are geting calculated.
            //The object "transport" ist geting created from the class "SwissTransoport.Transport"
            //The variable "foundConnections" is geting defined. Now the Values from the two Comboboxes are written to the variable.
            //The ListView gets again cleared from the Items. If the user wants to search for another connection between two new Stations,
            //The Items will be cleared if the user clicks the button again.
            //Now the foreach loop calculates the connections between the two stations, which are selected by the user.

            SwissTransport.Transport transport = new SwissTransport.Transport();
            DateTime dtDate = this.DateTimeDate.Value;
            DateTime dtTime = this.DateTimeClock.Value;

            //var foundConnections = transport.GetConnections(ComboBoxStart.Text, ComboBoxEnd.Text, dtDate, dtTime);
            ListViewResult.Items.Clear();
            foreach (Connection conn in transport.GetConnections(ComboBoxStart.Text, ComboBoxEnd.Text, dtDate, dtTime).ConnectionList)

            {
                //The Date and the Time is geting parsed from the Depature and Arrival time.
                //After this step, the string for the ListView is getting created. the Values for the connection are saved in the string now.
                //Then, the String is added to the Listview with the .Items.Add(lvitem)
                //In the end the Colums are getting auto resized, for a better view.
                DateTime     dtDeparture = DateTime.Parse(conn.From.Departure);
                DateTime     dtArrival   = DateTime.Parse(conn.To.Arrival);
                String[]     item        = { conn.From.Platform, dtDeparture.ToString(), conn.Duration, dtArrival.ToString() };
                ListViewItem lvitem      = new ListViewItem(item);
                ListViewResult.Items.Add(lvitem);
                ListViewResult.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                ListViewResult.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
        }
Ejemplo n.º 11
0
        private void BtnSearch_Click(object sender, EventArgs e)
        {
            //Speichert den in string convertierten Inhalt der Eingabe in Variablen ab
            string startStation = txtStartstation.Text;
            string endStation   = txtEndstation.Text;
            string date         = dtpDate.Value.ToString("yyyy-MM-dd");

            //Die Zeitzone wird im Moment noch manuell mit +1 angepasst
            string time = (nbrHour.Value + 1) + ":" + nbrMinute.Value;

            //Erstellte ein Objekt der Klasse Transport nach Vorgaben der Struktur ITransport
            SwissTransport.Transport StationConnetions = new SwissTransport.Transport();
            try
            {
                //Erstellt eine Liste welche Objekte der Klasse Station beinhaltet, welche das Wort (Parameter) im Namen der Station enthält
                List <SwissTransport.Station> start = StationConnetions.GetStations(startStation).StationList;
                List <SwissTransport.Station> end   = StationConnetions.GetStations(endStation).StationList;

                //Erstellt eine Liste welche Objekte der Klasse Connection beinhaltet, welche die Verbindungen zwischen zwei Stationen darstellt
                List <SwissTransport.Connection> startEndConnection = StationConnetions.GetConnectionsByDateTime(startStation, endStation, date, time).ConnectionList;

                dgvOutput.Rows.Clear();

                if (startEndConnection.Count != 0)
                {
                    foreach (SwissTransport.Connection connection in startEndConnection)
                    {
                        dgvOutput.Rows.Add(connection.From.Station.Name, TimeStampToTime(connection.From.DepartureTimestamp),
                                           connection.From.Platform, TimeStampToTime(connection.To.ArrivalTimestamp), connection.To.Station.Name);
                    }
                }
                else
                {
                    MessageBox.Show("Keine Verbindung gefunden.\nÜberprüfen Sie Ihre Eingabe.");
                }
            }
            catch
            {
                MessageConnectionError();
            }
        }
Ejemplo n.º 12
0
        private void txtElementText_SelectedIndexChanged(object sender, EventArgs e)
        {
            string startStation = txtStartstation.Text;
            string endStation   = txtEndstation.Text;

            SwissTransport.Transport StationConnetions = new SwissTransport.Transport();

            //Bestimmt von welcher Textbox aus ich die Daten eingebe, um Performace zu sparen
            if (sender == txtStartstation)
            {
                try
                {
                    List <SwissTransport.Station> start = StationConnetions.GetStations(startStation).StationList;

                    lstStartstation.Items.Clear();

                    foreach (SwissTransport.Station station in start)
                    {
                        if (station.Name != null)
                        {
                            lstStartstation.Items.Add(station.Name);
                        }
                    }
                }
                catch
                {
                    MessageConnectionError();
                }
            }
            else if (sender == txtStation)
            {
                string station = txtStation.Text;

                SwissTransport.Transport stationConnetions = new SwissTransport.Transport();
                try
                {
                    List <SwissTransport.Station> stationList = stationConnetions.GetStations(station).StationList;

                    lstSuggestionsStation.Items.Clear();

                    foreach (SwissTransport.Station oneStation in stationList)
                    {
                        if (oneStation.Name != null)
                        {
                            lstSuggestionsStation.Items.Add(oneStation.Name);
                        }
                    }
                }
                catch
                {
                    MessageConnectionError();
                }
            }
            else
            {
                try
                {
                    List <SwissTransport.Station> end = StationConnetions.GetStations(endStation).StationList;

                    lstEndstation.Items.Clear();

                    foreach (SwissTransport.Station station in end)
                    {
                        if (station.Name != null)
                        {
                            lstEndstation.Items.Add(station.Name);
                        }
                    }
                }
                catch
                {
                    MessageConnectionError();
                }
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// returns List of strings which you can print afterwards.
        /// The list contains connections between start and end station by specified date and time
        /// </summary>
        /// <param name="startStation"></param>
        /// <param name="endStation"></param>
        /// <param name="date"></param>
        /// <param name="time"></param>
        /// <returns></returns>
        public List <string> GetConnections(string startStation, string endStation, string date, string time)
        {
            List <string> output = new List <string>();
            Station       s      = new Station();

            //check if the Station is valid
            if (s.CheckStation(startStation) && s.CheckStation(endStation))
            {
                try
                {
                    SwissTransport.Transport         transport   = new SwissTransport.Transport();
                    List <SwissTransport.Connection> connections = new List <SwissTransport.Connection>();

                    //could return null!
                    connections = transport.GetConnections(startStation, endStation, date, time).ConnectionList;

                    //When Time is to far back, the API won't send items
                    if (connections.Count() == 0)
                    {
                        /*Will be shown as Information in the box,
                         * two elements because it will be shown on two lines*/
                        output.Add("Zu diesem Datum konnten keine");
                        output.Add("Informationen gefunden werden.");
                    }
                    else
                    {
                        //shwos in list box first which connection it is
                        output.Add("Von: " + startStation);
                        output.Add("Bis: " + endStation);

                        foreach (SwissTransport.Connection connection in connections)
                        {
                            //Substrings the String so, that only hh:mm will be shown
                            string departureTime = connection.From.Departure.Substring(11, 5);
                            string arrivalTime   = connection.To.Arrival.Substring(11, 5);

                            //platform could be null !!!
                            string platform;
                            if (connection.From.Platform == null)
                            {
                                platform = "Keine Angaben";
                            }
                            else
                            {
                                platform = "Gleis " + connection.From.Platform;
                            }

                            output.Add(departureTime + "-" + arrivalTime + " " + platform);
                        }
                    }
                }
                catch (NullReferenceException)
                {
                    /*Will be shown as Information in the box,
                     * two elements because it will be shown on two lines*/
                    output.Add("Eine Station existiert nicht");
                    output.Add("oder hat keine Verbindungen.");
                }
            }
            else
            {
                /*Will be shown as Information in the box,
                 * two elements because it will be shown on two lines*/
                output.Add("Eine ihrer eingegebenen");
                output.Add("Station existiert nicht.");
            }
            return(output);
        }