GPSTrackerLocationGrid.cs 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Controls;
  5. using Comal.Classes;
  6. using Comal.Stores;
  7. using InABox.Clients;
  8. using InABox.Core;
  9. using InABox.DynamicGrid;
  10. using InABox.WPF;
  11. namespace PRSDesktop;
  12. internal class GPSTrackerLocationGrid : DynamicOneToManyGrid<GPSTracker, GPSTrackerLocation>
  13. {
  14. private static List<GPSTrackerLocation> _cache;
  15. protected override void Init()
  16. {
  17. base.Init();
  18. Criteria.Add(
  19. new Filter<GPSTrackerLocation>(x => x.Location.Timestamp).IsGreaterThanOrEqualTo(DateTime.Now.AddDays(-1))
  20. );
  21. HiddenColumns.Add(x => x.Location.Longitude);
  22. HiddenColumns.Add(x => x.Location.Latitude);
  23. HiddenColumns.Add(x => x.Location.Address);
  24. ActionColumns.Add(new DynamicMapColumn<GPSTrackerLocation>(this, x => x.Location));
  25. // AddButton("Get Addresses", null, GetAddressClick);
  26. }
  27. protected override void DoReconfigure(DynamicGridOptions options)
  28. {
  29. base.DoReconfigure(options);
  30. options.SelectColumns = true;
  31. options.RecordCount = true;
  32. options.FilterRows = true;
  33. }
  34. // public static string ReverseGeocode(double latitude, double longitude)
  35. // {
  36. // _cache ??= Client.Query(
  37. // new Filter<GPSTrackerLocation>(x => x.Location.Address).IsNotEqualTo(""),
  38. // Columns.None<GPSTrackerLocation>().Add(
  39. // x => x.Location.Address,
  40. // x => x.Location.Longitude,
  41. // x => x.Location.Latitude))
  42. // .ToList<GPSTrackerLocation>();
  43. // var tuple = _cache.FirstOrDefault(x => Equals(x.Location.Latitude, latitude) && Equals(x.Location.Longitude, longitude));
  44. // if (tuple == null)
  45. // {
  46. // var address = StoreUtils.ReverseGeocode(latitude, longitude);
  47. // if (!string.IsNullOrWhiteSpace(address))
  48. // {
  49. // tuple = new GPSTrackerLocation();
  50. // tuple.Location.Latitude = latitude;
  51. // tuple.Location.Longitude = longitude;
  52. // tuple.Location.Address = address;
  53. // _cache.Add(tuple);
  54. // }
  55. // }
  56. //
  57. // return tuple != null ? tuple.Location.Address : "";
  58. // }
  59. // private bool GetAddressClick(Button arg1, CoreRow[] arg2)
  60. // {
  61. // var result = false;
  62. // var rows = Data.Rows.Where(r =>
  63. // string.IsNullOrWhiteSpace(r.Get<GPSTrackerLocation, string>(c => c.Location.Address))
  64. // && !Equals(r.Get<GPSTrackerLocation, double>(c => c.Location.Latitude), 0.0F)
  65. // && !Equals(r.Get<GPSTrackerLocation, double>(c => c.Location.Longitude), 0.0F)
  66. // );
  67. // Progress.ShowModal("Updating Addresses", progress =>
  68. // {
  69. // foreach (var row in rows)
  70. // {
  71. // var item = LoadItem(row);
  72. // var address = ReverseGeocode(
  73. // row.Get<GPSTrackerLocation, double>(x => x.Location.Latitude),
  74. // row.Get<GPSTrackerLocation, double>(x => x.Location.Longitude)
  75. // );
  76. // if (!string.IsNullOrWhiteSpace(address))
  77. // {
  78. // item.Location.Address = address;
  79. // UpdateRow<GPSTrackerLocation, string>(row, x => x.Location.Address, address, false);
  80. // result = true;
  81. // }
  82. // }
  83. // });
  84. // return result;
  85. // }
  86. }