Пример #1
0
        private void LineListView_ItemClick(object sender, ItemClickEventArgs e)
        {
            BusStopLineTime lineTime = (BusStopLineTime)e.ClickedItem;

            if (lineTime != null)
            {
                BusStopName stopName = new BusStopName()
                {
                    Direction = uint.Parse(lineTime.Direction),
                    Line      = lineTime.Line,
                    StopName  = stop
                };

                Frame root = Window.Current.Content as Frame;
                root.Navigate(typeof(BusDetail), stopName);
            }
        }
Пример #2
0
        async private Task GetStopBusTimesAsync(int id, int limit = 3)
        {
            // http://66.42.32.248/wechat/api/stop_all.php

            if (!isLoading)
            {
                isLoading           = true;
                lineRing.Visibility = Visibility.Visible;

                StopLine.Clear();

                //Create an HTTP client object
                HttpClient httpClient = new HttpClient();

                //Add a user-agent header to the GET request.
                var headers = httpClient.DefaultRequestHeaders;

                Uri requestUri = new Uri("http://66.42.32.248/wechat/api/stop_all.php");


                List <KeyValuePair <string, string> > formData = new List <KeyValuePair <string, string> >();
                formData.Add(new KeyValuePair <string, string>("id", id + ""));
                HttpFormUrlEncodedContent content = new HttpFormUrlEncodedContent(formData);

                try
                {
                    //Send the GET request asynchronously and retrieve the response as a string.
                    HttpResponseMessage httpResponse = new HttpResponseMessage();
                    string httpResponseBody          = "";
                    // Send the POST request
                    httpResponse = await httpClient.PostAsync(requestUri, content);

                    httpResponse.EnsureSuccessStatusCode();

                    httpResponseBody = await httpResponse.Content.ReadAsStringAsync();

                    Debug.WriteLine(httpResponseBody);

                    JsonObject jsonObject = JsonObject.Parse(httpResponseBody);
                    // Parse state

                    // Parse datas
                    JsonArray data = jsonObject["data"].GetArray();

                    for (uint i = 0; i < data.Count; i++)
                    {
                        // Parse stop
                        JsonObject lineDirectionObject = data.GetObjectAt(i);

                        string line      = lineDirectionObject["line"].GetString();
                        string direction = lineDirectionObject["direction"].GetString();

                        JsonArray times = lineDirectionObject["times"].GetArray();

                        if (times != null && line != null && direction != null)
                        {
                            BusStopLineTime busStopLineTime = new BusStopLineTime();
                            busStopLineTime.Line          = line;
                            busStopLineTime.DirectionName = Line.NAME[(int.Parse(line) - 1) * 2 + int.Parse(direction) - 1];
                            busStopLineTime.Direction     = direction;

                            /*for (uint j = 0; j < times.Count; j++)
                             * {
                             *  string time = times.GetStringAt(j);
                             *  Debug.WriteLine(time);
                             * }*/
                            // Not Display
                            StopLine.Add(busStopLineTime);
                        }
                    }
                }
                catch (Exception ex)
                {
                    // Refresh error
                }

                isLoading           = false;
                lineRing.Visibility = Visibility.Collapsed;
            }
        }