Ejemplo n.º 1
0
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (!isLoaded)
            {
                Constant.Loader(this.resourceLoader.GetString("GlobalLoading"), true);
                param = JsonConvert.DeserializeObject <DirectionSQL>(e.NavigationParameter.ToString());
                this.DefaultViewModel["Number"]      = param.number;
                this.DefaultViewModel["Direction"]   = param.name;
                this.DefaultViewModel["BorderColor"] = Constant.TransportColors[param.type];
                await Task.Run(() => LoadRoutes(param));

                Constant.Loader(this.resourceLoader.GetString("GlobalLoadingSuccess"), false);
                isLoaded = true;

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
                                                                                                            async() =>
                {
                    while (true)
                    {
                        await Task.Delay(10000);
                        foreach (var item in Stops)
                        {
                            Stops.Where(d => d.n_id == item.n_id).First().Next_Bus = time.getNextBusTime(item.schedule, item.days);
                        }
                    }
                }
                                                                                                            );
            }
        }
Ejemplo n.º 2
0
        private async Task LoadRoutes(DirectionSQL param)
        {
            SQLiteConnection connection = new SQLiteConnection(dbPath);

            Stops = new ObservableCollection <DirectionStopSQL>();
            var items = connection.Query <DirectionStopSQL>(
                "SELECT s.id as s_id, s.r_id as r_id, s.n_id as n_id, s.d_id as d_id,s.favorite as favorite, REPLACE(sn.name,'ул. ','') as name, s.schedule as schedule, s.days as days " +
                "FROM stop AS s " +
                "LEFT JOIN stopname as sn ON n_id = sn.id " +
                "WHERE d_id=" + param.d_id + " AND r_id=" + param.r_id + " " +
                "GROUP BY name " +
                "ORDER BY s_id");

            foreach (var item in items)
            {
                Stops.Add(new DirectionStopSQL()
                {
                    width    = param.width,
                    name     = item.name,
                    r_id     = item.r_id,
                    d_id     = item.d_id,
                    n_id     = item.n_id,
                    days     = item.days,
                    next_bus = time.getNextBusTime(item.schedule, item.days),
                    favorite = Int32.Parse(item.favorite) == 1 ? Constant.FavoriteStar : Constant.UnFavoriteStar,
                    schedule = item.schedule
                });
            }

            this.DefaultViewModel["Stops"] = Stops.Count != 0 ? Stops : null;
        }