Exemplo n.º 1
0
        // Nach Stationen suchen und der Autocompletesource hinzufügen.
        public void LoadStations(TextBox textBox)
        {
            try
            {
                // Internet Verbindung Prüfen
                if (!transport.CheckForInternetConnection())
                {
                    mainForm.LoadNoConnectionPanel();
                    return;
                }

                // Fehler abfangen, falls keine Stationen gefunden werden
                if (!transport.GetStations(textBox.Text).StationList.Any())
                {
                    MessageBox.Show("Es konnten keine Stationen mit den von Ihnen eingegebenen Suchkriterien gefunden werden", "Keine Treffer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Stationen in Liste abfüllen
                Stations stations = new Stations
                {
                    StationList = transport.GetStations(textBox.Text).StationList
                };

                // Namen der Stationen in Liste abfüllen
                List <string> stationNames = new List <string>();
                foreach (Station station in stations.StationList)
                {
                    if (station.Name != null)
                    {
                        stationNames.Add(station.Name);
                    }
                }

                // Namen der Stationen allen drei Textboxen hinzufügen
                tbxVon.AutoCompleteCustomSource.AddRange(stationNames.ToArray());
                tbxNach.AutoCompleteCustomSource.AddRange(stationNames.ToArray());
                tbxAb.AutoCompleteCustomSource.AddRange(stationNames.ToArray());

                // Text aus der Textbox über Sendkeys neu einspielen, damit das Dropdown aktiviert wird.
                string text = textBox.Text;
                textBox.Text = "";
                textBox.Focus();
                SendKeys.Send(text);
            }
            catch (Exception exeption)
            {
                throw new System.InvalidOperationException("\nThere was an exeption in Strecke LoadStations() \nMessage: " + exeption.Message);
            }
        }
Exemplo n.º 2
0
        // Die nächsten 5 Verbindungen einer bestimmten Strecke in einer Tabelle anzeigen.
        public bool LoadTimeTable(string from, string to, DateTime date, DateTime time)
        {
            try
            {
                // Internet Verbindung Prüfen
                if (!transport.CheckForInternetConnection())
                {
                    mainForm.LoadNoConnectionPanel();
                    return(false);
                }

                DateTime departureTime = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second);

                // Überprüfen ob eine gültige Verbindung zwischen Start und Ziel existiert.
                Connections connectionsToCheck = transport.GetConnections(from, to, 5, departureTime, isArivalTime);
                bool        validConnections   = false;
                if (connectionsToCheck != null)
                {
                    if (connectionsToCheck.ConnectionList.Any())
                    {
                        validConnections = true;
                    }
                }
                if (!validConnections)
                {
                    MessageBox.Show("Es konnten keine Stationen mit den von Ihnen eingegebenen Suchkriterien gefunden werden", "Keine Treffer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return(false);
                }

                List <Connection> connections = new List <Connection>();
                connections = connectionsToCheck.ConnectionList;

                // Die ausgelesenen Verbindungen in der Tabelle anzeigen
                int pointer = 0;
                foreach (Connection connection in connections)
                {
                    // Daten aus den Verbindungen in angenehm zu lesendes Format umwandeln
                    string   departure = Convert.ToDateTime(connection.From.Departure).ToString("HH:mm");
                    string   arival    = Convert.ToDateTime(connection.To.Arrival).ToString("HH:mm");
                    string   duration;
                    string   durationUnformatted = connection.Duration.Substring(connection.Duration.IndexOf('d') + 1);
                    DateTime dtDuration          = Convert.ToDateTime(durationUnformatted);
                    if (dtDuration.Hour == 0)
                    {
                        duration = String.Format("{0} Min", dtDuration.Minute.ToString());
                    }
                    else
                    {
                        duration = String.Format("{0} Std, {1} Min", dtDuration.Hour.ToString(), dtDuration.Minute.ToString());
                    }

                    // Daten der Tabelle hinzufügen
                    lbTimeTable[pointer].Text = departure;
                    pointer++;
                    lbTimeTable[pointer].Text = String.IsNullOrEmpty(connection.From.Platform) ? "-" : connection.From.Platform;
                    pointer++;
                    lbTimeTable[pointer].Text = arival;
                    pointer++;
                    lbTimeTable[pointer].Text = duration;
                    pointer++;
                }

                // Text aus den übrigen Feldern löschen
                for (int i = pointer; i < lbTimeTable.Length; i++)
                {
                    lbTimeTable[i].Text = "";
                }

                // Start und Ziel für die Ansicht im UI zusammensetzen
                Connection firstConnection = connections.First();
                lbGleisKante.Text = int.TryParse(firstConnection.From.Platform, out _) ? "Gleis" : "Kante";
                lbFromTo.Text     = String.Format("{0}  🡺  {1}", firstConnection.From.Station.Name, firstConnection.To.Station.Name);

                // Tabelle Anzeigen und Button Verbergen
                tlpConnectionTable.Visible       = true;
                tlpConnectionTableHeader.Visible = true;
                btnStreckeEingeben.Visible       = false;
                LoadPanel();

                return(true);
            }
            catch (Exception exeption)
            {
                throw new System.InvalidOperationException("\nThere was an exeption in Fahrplan LoadTimeTable() \nMessage: " + exeption.Message);
            }
        }
Exemplo n.º 3
0
        // Von einer Station aus zu erreichende Ziele auflisten
        public void LoadConnections(TextBox textBox)
        {
            try
            {
                // Internet Verbindung Prüfen
                if (!transport.CheckForInternetConnection())
                {
                    mainForm.LoadNoConnectionPanel();
                    return;
                }

                // Fehler abfangen, falls keine Stationen gefunden werden
                if (!transport.GetStations(textBox.Text).StationList.Any())
                {
                    MessageBox.Show("Es konnten keine Stationen mit den von Ihnen eingegebenen Suchkriterien gefunden werden", "Keine Treffer", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Stationen Laden und UI Ansicht zurücksetzen
                Station station = transport.GetStations(textBox.Text).StationList.First();
                connectionFrom = station.Name;
                textBox.Text   = connectionFrom;
                tlpConnectionsHeader.Visible = true;
                tlpConnectionsTable.Controls.Clear();

                // Fehler abfangen, falls die Adresse keine Haltestelle ist
                if (station.Id == null)
                {
                    tlpConnectionsHeader.Visible = false;
                    MessageBox.Show("Die ausgewählte Adresse ist keine Haltestelle", "Keine Haltestelle", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                // Eine Liste mit Verbindungen erstellen in der jede nur einmal vorkommt.
                List <StationBoard> allStationBoards    = transport.GetStationBoard(station.Name, station.Id).Entries;
                List <StationBoard> uniqueStationBoards = new List <StationBoard>();
                foreach (StationBoard stationBoard in allStationBoards)
                {
                    if (!uniqueStationBoards.Any(unique => unique.Number == stationBoard.Number && unique.To == stationBoard.To))
                    {
                        uniqueStationBoards.Add(stationBoard);
                    }
                }

                // Liste sortieren nach Zug / Bus Nr
                uniqueStationBoards = uniqueStationBoards.OrderBy(o => o.Number).ToList();

                // Verbindungen der Tabelle hinzufügen
                for (int i = 0; i < uniqueStationBoards.Count(); i++)
                {
                    // Elemente für eine Reihe definieren
                    string tag    = string.Format("{0};{1}", connectionFrom, uniqueStationBoards.ElementAt(i).To);
                    Label  number = new LabelTemplate {
                        Text = uniqueStationBoards.ElementAt(i).Number
                    };
                    Label destination = new LabelTemplate {
                        Text = uniqueStationBoards.ElementAt(i).To
                    };
                    Button route = new ButtonTemplate(mainForm)
                    {
                        Tag = tag
                    };

                    // Eine weitere Reihe in der Tabelle hinzufügen, falls zu wenig Platz ist.
                    if (tlpConnectionsTable.RowStyles.Count <= i)
                    {
                        tlpConnectionsTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 45F));
                    }

                    // Elemente der Tabelle hinzufügen
                    tlpConnectionsTable.Controls.Add(number, 0, i);
                    tlpConnectionsTable.Controls.Add(destination, 1, i);
                    tlpConnectionsTable.Controls.Add(route, 2, i);
                }
                // Platzhalter aus Darstellungsgründen hinzufügen
                tlpConnectionsTable.Controls.Add(new Label(), 0, uniqueStationBoards.Count());
            }
            catch (Exception exeption)
            {
                throw new System.InvalidOperationException("\nThere was an exeption in Verbindungen LoadConnections() \nMessage: " + exeption.Message);
            }
        }