private async void ApplicationBarMenuItem_Click_1(object sender, EventArgs e) { if (addFavePressed == false) { addFavePressed = true; OCDirection direction = OCDirection.newOCDirection(int.Parse(routeNumber.Text), routeName.Text, "", "", 0); direction.FromStopNumber = stopID; direction.FromStopName = fromStopName; direction.DirectionalName = "TO " + this.direction.ToUpper(); int result = await OCTranspoStopsData.addFavouriteStop(direction); if (result > 0) { MessageBox.Show("Your favourite stop was succesfully added."); ApplicationBarIconButton button = (ApplicationBarIconButton)sender; button.IsEnabled = false; favourite = true; } else { MessageBox.Show("There was an error adding your favourite stop, please try again."); addFavePressed = favourite = false; } } }
protected override async void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); OCSettings settings = await OCTranspoStopsData.getSettings(); nearbyDistanceSlider.Value = settings.nearbyDistance; }
//Nearby List Methods***********************************************************************************************************************************************************// private async void getNearbyStops() { if (refreshingNearby == false) { refreshingNearby = true; try { Geocoordinate myCoordinate = await GeoLocator.getMyLocation(); if (myCoordinate != null) { nearbyStops = await OCTranspoStopsData.getCloseStops(myCoordinate.Latitude, myCoordinate.Longitude, currentLocation.ZoomLevel); this.nearbyList.ItemsSource = nearbyStops; setNearbyErrorMessage(true, nearbyStops.Count > 0); } else { nearbySorry.Visibility = nearbyStops.Count == 0 ? Visibility.Visible : Visibility.Collapsed; nearbyFrown.Visibility = nearbyStops.Count == 0 ? Visibility.Visible : Visibility.Collapsed; setNearbyErrorMessage(true, false); } } catch { setNearbyErrorMessage(false, false); } refreshingNearby = false; } }
public async Task <OCApiRoute> fetchTimes(String stopID) { String times = ""; String fourTimes = ""; DateTime now = DateTime.Now; String originalDate = ""; List <OCSchedule> schedules = await OCTranspoStopsData.getScheduleForDayAndStop(now.DayOfWeek.ToString(), stopID, this.RouteNumber); int idx = 0; foreach (OCSchedule schedule in schedules) { try { int hour = int.Parse(schedule.arrival_time.Substring(0, 2)); if (hour >= 24) { hour = hour - 24; originalDate = " 0" + hour + ":" + schedule.arrival_time.Substring(3); schedule.arrival_time = DateTime.Now.AddDays(1).ToShortDateString() + " 0" + hour + ":" + schedule.arrival_time.Substring(3); } DateTime date = DateTime.Parse(schedule.arrival_time); if (date.CompareTo(now) > 0) { if (originalDate.Length > 0) { schedule.arrival_time = originalDate; } if (idx < 3) { times = times + " " + schedule.arrival_time.Substring(0, schedule.arrival_time.Length - 3); } else { fourTimes = fourTimes + " " + schedule.arrival_time.Substring(0, schedule.arrival_time.Length - 3); } idx++; if (idx > 6) { break; } } } catch (Exception e) { Console.Write(e); } } fourTimes = fourTimes.Length > 0 ? fourTimes.Substring(1) : fourTimes; times = times.Length > 0 ? times.Substring(1) : times; if (times.Length == 0) { times = "There are no more stops today."; } this.fourArrivalTimes = fourTimes; this.nextTimes = times; return(this); }
// Constructor public MainPage() { TiltEffect.SetIsTiltEnabled(this, true); searching = false; refreshingFavs = false; refreshingNearby = false; ApplicationBar = (Microsoft.Phone.Shell.ApplicationBar)Resources["DefaultAppBar"]; OCTranspoStopsData.initDB(); InitializeComponent(); setupLists(); setupSearchBox(); setupMap(); }
async void timer_Tick(Object sender, EventArgs args) { searchBoxTimer.Stop(); searchProgressBar.Visibility = Visibility.Visible; String query = routesSearch.Text; routes = await OCTranspoStopsData.getStopByNameOrID(query); searchHasItems(routes.Count > 0, query.Length > 0); this.routesList.ItemsSource = routes; searchBoxTimer.Stop(); searchProgressBar.Visibility = Visibility.Collapsed; }
//TODO :GENERALIZE/Abstract public async Task <OCDirection> fetchTimes(String stopID) { String times = ""; String fourTimes = ""; DateTime now = DateTime.Now; String originalDate = ""; List <OCSchedule> schedules = await OCTranspoStopsData.getScheduleForDayAndStop(now.DayOfWeek.ToString(), stopID, this.RouteNo); int idx = 0; foreach (OCSchedule schedule in schedules) { if (schedule.arrival_time.StartsWith("24")) { originalDate = schedule.arrival_time; schedule.arrival_time = DateTime.Now.AddDays(1).ToShortDateString() + " 00:" + schedule.arrival_time.Substring(3); } DateTime date = DateTime.Parse(schedule.arrival_time); if (date.CompareTo(now) > 0) { if (originalDate.Length > 0) { schedule.arrival_time = originalDate; } if (idx < 3) { times = times + " " + schedule.arrival_time.Substring(0, schedule.arrival_time.Length - 3); } else { fourTimes = fourTimes + " " + schedule.arrival_time.Substring(0, schedule.arrival_time.Length - 3); } idx++; if (idx > 6) { break; } } } fourTimes = fourTimes.Length > 0 ? fourTimes.Substring(1) : fourTimes; times = times.Length > 0 ? times.Substring(1) : times; if (times.Trim().Length == 0) { times = "Sorry, there are no more stops today."; } this.fourArrivalTimes = fourTimes; this.nextTimes = times; return(this); }
private async void deleteFavourite_Click(object sender, RoutedEventArgs e) { var menItem = (MenuItem)sender; OCDirection dir = (OCDirection)menItem.DataContext; int result = await OCTranspoStopsData.deleteFavourite(dir); if (result > 0) { favourites.Remove(dir); } else { MessageBox.Show("There was an issue deleting your favourite."); } }
public static async void drawMapMarkers(Map map) { if (map.ZoomLevel > 12) { map.Layers.Clear(); MapLayer mapLayer = new MapLayer(); ObservableCollection <OCStop> stops = await OCTranspoStopsData.getCloseStops(map.Center.Latitude, map.Center.Longitude, map.ZoomLevel); foreach (OCStop stop in stops) { drawMapMarker(stop, Color.FromArgb(255, 210, 30, 0), mapLayer, true); } layMyLocation(mapLayer); map.Layers.Add(mapLayer); } }
private async Task <Boolean> saveSettings(Boolean fromExit) { int result = await OCTranspoStopsData.updateSettings(OCSettings.newOCSettings(distance)); if (result > 0) { MessageBox.Show("Settings were successfully saved."); dirtyPage = false; if (this.NavigationService.CanGoBack && fromExit == false) { this.NavigationService.GoBack(); } return(true); } else { MessageBox.Show("There was an error saving your settings, please try again."); return(false); } }
private async void refreshFavourites() { if (refreshingFavs == false) { refreshingFavs = true; favourites = await OCTranspoStopsData.getFavourites(); this.routesList.ItemsSource = routes; foreach (OCDirection stop in favourites) { OCDirection stop2 = await stop.fetchTimes(stop.FromStopNumber.ToString()); stop.fourArrivalTimes = stop2.fourArrivalTimes; stop.nextTimes = stop2.nextTimes; } this.favouritesList.ItemsSource = favourites; setFavouriteErrorMessage(false, favourites.Count > 0); refreshingFavs = false; } }
private async void addFavourite_Click(object sender, RoutedEventArgs e) { var menItem = (MenuItem)sender; OCApiRoute apiRoute = (OCApiRoute)menItem.DataContext; OCDirection direction = OCDirection.newOCDirection(apiRoute.RouteNumber, apiRoute.RouteHeading, apiRoute.Direction, "", 0); direction.FromStopName = stopName.Text; direction.FromStopNumber = int.Parse(stopID.Text); direction.DirectionalName = "TO " + apiRoute.RouteHeading.ToUpper(); int result = await OCTranspoStopsData.addFavouriteStop(direction); if (result > 0) { MessageBox.Show("Your favourite stop was succesfully added."); } else { MessageBox.Show("There was an error adding your favourite stop, please try again."); } }