void SortStopsTime() { if (IsBusy) { return; } IsBusy = true; try { foreach (Variant Variant in Variants) { StopsTime.Clear(); StopTimeDataStore.Clear(); List <StopTime> DoPosortowania = new List <StopTime>(); foreach (StopTime item in Variant.stopTimesTest) { DoPosortowania.Add(item); } DoPosortowania.Sort((x, y) => x.ArrivalTime.CompareTo(y.ArrivalTime)); foreach (StopTime item in DoPosortowania) { if (item.Nonpassenger == "0" && item.VirtualId == "0" || item.Nonpassenger == null && item.VirtualId == null) { StopsTime.Add(item); } } Variant.stopTimesTest.Clear(); foreach (StopTime stopTime in StopsTime) { Variant.stopTimesTest.Add(stopTime); } } } catch (Exception ex) { Debug.WriteLine(ex); App.Current.MainPage.DisplayAlert("Błąd", "Coś poszło nie tak", "OK"); } finally { IsBusy = false; } }
async Task ExecuteLoadDirectionsCommand() { if (IsBusy) { return; } IsBusy = true; try { StopsCollection.Clear(); var stops = await StopDataStore.GetItemsAsync(true); foreach (Stop stop in stops) { StopsCollection.Add(stop); } StopTimesCollection.Clear(); StopTimeDataStore.Clear(); var stopsTime = await StopTimeDataStore.GetItemsAsync(Route.RouteId, Route.i, true); foreach (StopTime stopTime in stopsTime) { StopTimesCollection.Add(stopTime); } foreach (Stop stop in StopsCollection) { foreach (StopTime stopTime in StopTimesCollection) { if (stop.StopId == stopTime.StopId) { stopTime.StopDesc = stop.StopDesc; } } } foreach (StopTime stopTime in StopTimesCollection) { stopTime.ArrivalTime = stopTime.ArrivalTime.Replace("1899-12-30T", ""); stopTime.DepartureTime = stopTime.DepartureTime.Replace("1899-12-30T", ""); stopTime.ArrivalTime = stopTime.ArrivalTime.Replace("1899-12-31T", "Następnego dnia o:"); stopTime.DepartureTime = stopTime.DepartureTime.Replace("1899-12-31T", "Następnego dnia o:"); } TripsCollection.Clear(); var trips = await TripsDataStore.GetItemsAsync(Route.i, true); foreach (Trip trip in trips) { TripsCollection.Add(trip); } DirectionsCollection.Clear(); Direction DirectionZero = new Direction(); DirectionZero.variants = new List <Variant>(); Direction DirectionOne = new Direction(); DirectionOne.variants = new List <Variant>(); foreach (Trip trip in TripsCollection) { if (Route.RouteId == int.Parse(trip.RouteId)) { if (trip.DirectionId == "2") { Variant variantV2 = new Variant(); variantV2.stopTimesTest = new List <StopTime>(); DirectionZero.directionId = trip.DirectionId; variantV2.directionId = int.Parse(trip.DirectionId); variantV2.tripId = int.Parse(trip.TripId); variantV2.tripHeadsign = trip.TripHeadsign; foreach (StopTime stopTime in StopTimesCollection) { if (int.Parse(stopTime.RouteId) == Route.RouteId && stopTime.TripId == trip.TripId) { variantV2.stopTimesTest.Add(stopTime); } } DirectionZero.variants.Add(variantV2); } if (trip.DirectionId == "1") { Variant variantV1 = new Variant(); variantV1.stopTimesTest = new List <StopTime>(); DirectionOne.directionId = trip.DirectionId; variantV1.directionId = int.Parse(trip.DirectionId); variantV1.tripId = int.Parse(trip.TripId); variantV1.tripHeadsign = trip.TripHeadsign; foreach (StopTime stopTime in StopTimesCollection) { if (int.Parse(stopTime.RouteId) == Route.RouteId && stopTime.TripId == trip.TripId) { variantV1.stopTimesTest.Add(stopTime); } } DirectionOne.variants.Add(variantV1); } } } DirectionsCollection.Add(DirectionOne); DirectionsCollection.Add(DirectionZero); } catch (Exception ex) { Debug.WriteLine(ex); await App.Current.MainPage.DisplayAlert("Błąd", "Coś poszło nie tak", "OK"); } finally { IsBusy = false; } }