Exemplo n.º 1
0
        public StationBoardRoot GetStationBoard(string station, string id)
        {
            station = System.Uri.EscapeDataString(station);
            id      = System.Uri.EscapeDataString(id);
            WebRequest  request        = null;
            WebResponse response       = null;
            Stream      responseStream = null;

            try
            {
                request        = CreateWebRequest("http://transport.opendata.ch/v1/stationboard?station=" + station + "&id=" + id);
                response       = request.GetResponse();
                responseStream = response.GetResponseStream();
            }
            catch
            {
                MessageBox.Show("Abfahrtstafel wegen Netzwerkfehler nicht aufrufbar.");
                StationBoardRoot stationBoardRoot = new StationBoardRoot();
                return(stationBoardRoot);
            }
            if (responseStream != null)
            {
                var readToEnd    = new StreamReader(responseStream).ReadToEnd();
                var stationboard =
                    JsonConvert.DeserializeObject <StationBoardRoot>(readToEnd);
                return(stationboard);
            }
            return(null);
        }
Exemplo n.º 2
0
        //Clears all Items from the Listview
        //Changes the name of the Columnheaders
        //Gets the StationBoard from the cboxfrom station and fills it into the Listview
        //Sets the Cursor to Waitcursor until all Data is loaded into Listview
        private void btnshowtable_Click(object sender, EventArgs e)
        {
            Transport transport    = new Transport();
            DateTime  dtetimeclock = this.dtetimeclock.Value;
            DateTime  dtetimecal   = this.dtetimecal.Value;

            liview.Items.Clear();
            if (cboxfrom.Text != "")
            {
                try
                {
                    //ColumnHeaders of Listview getting renamed
                    Cursor.Current  = Cursors.WaitCursor;
                    clmankunft.Text = "Nach";
                    clmdauer.Text   = "Typ";
                    clmgleis.Text   = "Anbieter";

                    string           id  = transport.GetStations(cboxfrom.Text).StationList[0].Id;
                    StationBoardRoot sbr = transport.GetStationBoard(cboxfrom.Text, id, dtetimecal, dtetimeclock);
                    foreach (StationBoard stb in sbr.Entries)
                    {
                        String[]     item  = { stb.Stop.Departure.ToString(), stb.To, stb.Name, stb.Operator };
                        ListViewItem lview = new ListViewItem(item);
                        liview.Items.Add(lview);
                    }
                    Cursor.Current = Cursors.Default;
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"Zu viele Anfragen an den Server\nBitte kurz warten befor sie fortfahren\n\n");
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// gibt die Verbindungen von der jeweiligen Station aus
 /// </summary>
 private void stationboard()
 {
     if (comboboxstation.Text.Length > 0)
     {
         try
         {
             station = transport.GetStationBoard(comboboxstation.Text, comboboxstation.Text);
             listViewplan.Columns.Add("", 0);
             listViewplan.Columns.Add("Verbindung", 200);
             listViewplan.Columns.Add("Endstation", 200);
             listViewplan.Columns.Add("Abfahrt", 120);
             foreach (StationBoard s in station.Entries)
             {
                 ListViewItem item1 = new ListViewItem("");
                 item1.SubItems.Add(s.Name);
                 item1.SubItems.Add(s.To);
                 item1.SubItems.Add(s.Stop.Departure.ToShortTimeString());
                 listViewplan.Items.Add(item1);
                 listViewplan.View          = View.Details;
                 listViewplan.FullRowSelect = true;
             }
         }
         catch
         {
             MessageBox.Show("zu viele Serverrequests");
         }
         lblstation.Text = comboboxstation.Text;
     }
     else
     {
         MessageBox.Show("Geben Sie ihre Station ein");
     }
 }
Exemplo n.º 4
0
 private new void Update()
 {
     dgrhide.DataSource = null;
     if (SelectedStartStation.Name != null && SelectedDestinationStation.Name != null)
     {
         Connections = Transport.GetConnections(SelectedStartStation.Name, SelectedDestinationStation.Name, DateTime.Now, DateTime.Now);
         if (Connections != null)
         {
             dgrhide.DataSource = Connections.ConnectionList;
         }
         else
         {
             MessageBox.Show("Keine Verbindungen gefunden");
             return;
         }
         try
         {
             dgrhide.Columns.Remove("Von");
             dgrhide.Columns.Remove("Nach");
         }
         catch
         {
             MessageBox.Show("Es wurde ein Fehler gefunden");
         }
     }
     else
     {
         if (SelectedStartStation.Name != null)
         {
             StationBoard = Transport.GetStationBoard(SelectedStartStation.Name, SelectedStartStation.Id);
         }
         else
         {
             StationBoard = Transport.GetStationBoard(SelectedDestinationStation.Name, SelectedDestinationStation.Id);
         }
         if (StationBoard != null)
         {
             dgrhide.DataSource = StationBoard.Entries;
         }
         else
         {
             MessageBox.Show("Keinen Fahrplan gefunden");
             return;
         }
         try
         {
             dgrhide.Columns.Remove("Name");
             dgrhide.Columns.Remove("Category");
             dgrhide.Columns.Remove("Operator");
         }
         catch
         {
             MessageBox.Show("Es wurde ein Fehler gefunden");
         }
     }
 }
Exemplo n.º 5
0
        public void transport_searchStationboards_stationBoardRoot()
        {
            testee = new Transport();
            string   station     = "Sursee";
            DateTime dateAndTime = DateTime.Now;

            StationBoardRoot stationBoards = testee.searchStationboards(station, dateAndTime);

            Assert.AreEqual("Sursee", stationBoards.Station.Name);
        }
Exemplo n.º 6
0
        private void stationboard()
        {
            listBoxPlan1.Items.Clear();
            station = transport.GetStationBoard(comboBoxStation.Text, comboBoxStation.Text);

            foreach (StationBoard s in station.Entries)
            {
                char[]   sep       = { ' ' };
                string[] departure = formatter.Splitter(Convert.ToString(s.Stop.Departure.Date), sep);
                listBoxPlan1.Items.Add(" " + s.Name + "\t" + s.To + "\t" + s.Stop.Departure.ToShortTimeString());
            }
        }
Exemplo n.º 7
0
        //With this Button, the Connections from one Station will be showed to the user.
        private void btnTimetable_Click(object sender, EventArgs e)
        {
            try
            {
                //Again the items and de colums are getting cleared, and new Columns are getting created.
                ListViewResult.Items.Clear();
                ListViewResult.Columns.Clear();
                ListViewResult.Columns.Add("Verkehrsmittel");
                ListViewResult.Columns.Add("Nach");
                ListViewResult.Columns.Add("Abfahrt");
                ListViewResult.Columns.Add("Betreiber");
                DateTime dtDate = this.DateTimeDate.Value;
                DateTime dtTime = this.DateTimeClock.Value;

                //In this section the Departures from one selected station will be calculated.
                DateTime         DtDate     = this.DateTimeDate.Value;
                DateTime         DtTime     = this.DateTimeClock.Value;
                string           strAbfahrt = ComboBoxStart.SelectedItem.ToString();
                string           id         = mainTransport.GetStations(strAbfahrt).StationList[0].Id;
                StationBoardRoot sbRoot     = mainTransport.GetStationBoard(strAbfahrt, id, dtDate, dtTime);
                //In this loop, the Results for the Departures are getting calculated, and the Items will be wirtten down,
                //to a string, then, a new ListViewItem is created and will be written down in the ListView.
                foreach (StationBoard sb in sbRoot.Entries)
                {
                    String[]     result = { sb.Name, sb.To, sb.Stop.Departure.ToString(), sb.Operator };
                    ListViewItem lvItem = new ListViewItem(result);
                    ListViewResult.Items.Add(lvItem);
                }
                //In the end the Colums are getting auto resized again, for a better view.
                ListViewResult.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                ListViewResult.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
            }
            catch
            {
            }
        }
        public void StationBoard()
        {
            StationBoardRoot stationBoard = this.testee.GetStationBoard("Sursee", "8502007");

            stationBoard.Should().NotBeNull();
        }