示例#1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            using (ServiceReference1.ScheduleServiceClient client = new ServiceReference1.ScheduleServiceClient())
            {
                //populate list of possible starting points in alphabetic order
                var stations = client.GetStations();
                List<string> namesInOrder = new List<String>();
                foreach (var a in stations)
                {
                    namesInOrder.Add(a.name);
                }
                namesInOrder.Sort();
                foreach (var stName in namesInOrder)
                    startStationBox.Items.Add(stName);

                //try to preselect Tallinn as starting point
                //if it works, we'll exclude Tallinn from destinations for the moment
                string chosenOne = "";
                startStationBox.SelectedIndex = startStationBox.FindStringExact("tallinn");
                if (startStationBox.SelectedValue != null)
                    chosenOne = startStationBox.SelectedItem.ToString();

                foreach (var stName in namesInOrder)
                {
                    if (stName != chosenOne)
                        endStationBox.Items.Add(stName);
                }
            }
        }
示例#2
0
        private void returnButton_Click(object sender, EventArgs e)
        {
            using (ServiceReference1.ScheduleServiceClient client = new ServiceReference1.ScheduleServiceClient())
            {
                if (startStationBox.SelectedItem != null && endStationBox.SelectedItem != null)
                {
                    resultsListBox.Items.Clear();

                    //switch starting point and destination
                    string tempStation = currentStart;
                    currentStart = currentEnd;
                    currentEnd = tempStation;

                    string startIndex = "";
                    string endIndex = "";

                    //identify the right start and end stations
                    var stations = client.GetStations();
                    foreach (var a in stations)
                    {
                        if (a.name == currentStart)
                            startIndex = a.id;
                        else if (a.name == currentEnd)
                            endIndex = a.id;
                    }

                    //if we found the stations, let's find some times
                    DateTime timeNow = DateTime.Now;

                    if (startIndex != "" && endIndex != "")
                    {
                        var startSchedule = client.GetStationSchedule(startIndex);
                        var endSchedule = client.GetStationSchedule(endIndex);

                        //add the departures of next 24h in order of time
                        //first the ones within the same date
                        foreach (var dept in startSchedule.departures)
                        {
                            if (DateTime.Parse(dept.Key).TimeOfDay > timeNow.TimeOfDay)
                            {
                                //check if destination is available for this departure
                                //e.g on the same line and arrival time greater than departure time
                                foreach (var arrival in endSchedule.departures)
                                {
                                    if (dept.Value.id == arrival.Value.id &&
                                        DateTime.Parse(arrival.Key).TimeOfDay > DateTime.Parse(dept.Key).TimeOfDay)
                                    {
                                        resultsListBox.Items.Add(dept.Key + "  ->  " + arrival.Key);
                                    }
                                }
                            }
                        }
                        //then the ones in the next date
                        foreach (var dept in startSchedule.departures)
                        {
                            //check if departure already listed
                            Boolean placed = false;
                            foreach (var item in resultsListBox.Items)
                            {
                                string algus = item.ToString().Substring(0, 5);
                                if (item.ToString().Substring(0, 5) == dept.Key)
                                    placed = true;
                            }
                            //if not listed, then let's list it
                            if (!placed)
                            {
                                //check if destination is available for this departure
                                //e.g on the same line and arrival time greater than departure time
                                foreach (var arrival in endSchedule.departures)
                                {
                                    if (dept.Value.id == arrival.Value.id &&
                                        DateTime.Parse(arrival.Key).TimeOfDay > DateTime.Parse(dept.Key).TimeOfDay)
                                    {
                                        resultsListBox.Items.Add(dept.Key + "  ->  " + arrival.Key + "  homme");
                                    }
                                }
                            }
                        }
                        labelResults.Text = "Järgmised väljumis- ja saabumisajad (" + currentStart + "-" + currentEnd + "):";
                    }
                }
            }
        }
示例#3
0
        //when starting point changes, available destinations will be recalculated
        private void startStationBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            using (ServiceReference1.ScheduleServiceClient client = new ServiceReference1.ScheduleServiceClient())
            {
                //get all the stations; put them in alphabetic order
                var stations = client.GetStations();
                List<string> namesInOrder = new List<String>();
                foreach (var a in stations)
                {
                    namesInOrder.Add(a.name);
                }
                namesInOrder.Sort();

                //if a starting point is successfully chosen, it is excluded from destinations for the moment
                string selStart = startStationBox.SelectedItem.ToString();
                if (selStart != null)
                {
                    while (endStationBox.Items.Count > 0)
                        endStationBox.Items.RemoveAt(0);

                    foreach (var stName in namesInOrder)
                    {
                        if (stName != selStart)
                            endStationBox.Items.Add(stName);
                    }
                }
            }
        }