SchedulePage.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Threading;
  5. using System.Windows.Controls;
  6. namespace RaspisKusach.Pages
  7. {
  8. public partial class SchedulePage : Page
  9. {
  10. public SchedulePage()
  11. {
  12. InitializeComponent();
  13. TripsListBox.Items.Clear();
  14. Thread th = new Thread(ThreadUpdate);
  15. th.Start();
  16. }
  17. public void ThreadUpdate()
  18. {
  19. while (true)
  20. {
  21. Dispatcher.BeginInvoke(new Action(() =>
  22. {
  23. TimeUpdate();
  24. TripsUpdate();
  25. }));
  26. Thread.Sleep(1000);
  27. }
  28. }
  29. void TimeUpdate()
  30. {
  31. TimeNowLabel.Content = DateTime.Now.ToString(new CultureInfo("ru-RU"));
  32. }
  33. void TripsUpdate()
  34. {
  35. List<TripClass> routeList = new List<TripClass>();
  36. TimeSpan timeOffset = new TimeSpan(0,15,0);
  37. foreach (Trips trip in cnt.db.Trips)
  38. {
  39. if(Functions.GetArrivalTime(Session.ThisStation, trip) >= (DateTime.Now-timeOffset)
  40. && Functions.GetDepartureTime(Session.ThisStation, trip) <= DateTime.Now+timeOffset)
  41. routeList.Add(new TripClass()
  42. {
  43. Trip = trip,
  44. StationDirection = Functions.GetRouteDirection(trip),
  45. TimeArrival = Functions.GetArrivalTime(Session.ThisStation, trip).ToString(new CultureInfo("ru-RU")),
  46. TimeDeparture = Functions.GetDepartureTime(Session.ThisStation, trip).ToString(new CultureInfo("ru-RU"))
  47. });
  48. }
  49. TripsListBox.ItemsSource = routeList;
  50. }
  51. public class TripClass
  52. {
  53. public Trips Trip { get; set; }
  54. public string StationDirection { get; set; }
  55. public string TimeArrival { get; set; }
  56. public string TimeDeparture { get; set; }
  57. }
  58. }
  59. }