| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using Comal.Stores;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop;
- internal class GPSTrackerLocationGrid : DynamicOneToManyGrid<GPSTracker, GPSTrackerLocation>
- {
- private static List<GPSTrackerLocation> _cache;
- protected override void Init()
- {
- base.Init();
- Criteria.Add(
- new Filter<GPSTrackerLocation>(x => x.Location.Timestamp).IsGreaterThanOrEqualTo(DateTime.Now.AddDays(-1))
- );
- HiddenColumns.Add(x => x.Location.Longitude);
- HiddenColumns.Add(x => x.Location.Latitude);
- HiddenColumns.Add(x => x.Location.Address);
- ActionColumns.Add(new DynamicMapColumn<GPSTrackerLocation>(this, x => x.Location));
- // AddButton("Get Addresses", null, GetAddressClick);
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.SelectColumns = true;
- options.RecordCount = true;
- options.FilterRows = true;
- }
- // public static string ReverseGeocode(double latitude, double longitude)
- // {
- // _cache ??= Client.Query(
- // new Filter<GPSTrackerLocation>(x => x.Location.Address).IsNotEqualTo(""),
- // Columns.None<GPSTrackerLocation>().Add(
- // x => x.Location.Address,
- // x => x.Location.Longitude,
- // x => x.Location.Latitude))
- // .ToList<GPSTrackerLocation>();
- // var tuple = _cache.FirstOrDefault(x => Equals(x.Location.Latitude, latitude) && Equals(x.Location.Longitude, longitude));
- // if (tuple == null)
- // {
- // var address = StoreUtils.ReverseGeocode(latitude, longitude);
- // if (!string.IsNullOrWhiteSpace(address))
- // {
- // tuple = new GPSTrackerLocation();
- // tuple.Location.Latitude = latitude;
- // tuple.Location.Longitude = longitude;
- // tuple.Location.Address = address;
- // _cache.Add(tuple);
- // }
- // }
- //
- // return tuple != null ? tuple.Location.Address : "";
- // }
- // private bool GetAddressClick(Button arg1, CoreRow[] arg2)
- // {
- // var result = false;
- // var rows = Data.Rows.Where(r =>
- // string.IsNullOrWhiteSpace(r.Get<GPSTrackerLocation, string>(c => c.Location.Address))
- // && !Equals(r.Get<GPSTrackerLocation, double>(c => c.Location.Latitude), 0.0F)
- // && !Equals(r.Get<GPSTrackerLocation, double>(c => c.Location.Longitude), 0.0F)
- // );
- // Progress.ShowModal("Updating Addresses", progress =>
- // {
- // foreach (var row in rows)
- // {
- // var item = LoadItem(row);
- // var address = ReverseGeocode(
- // row.Get<GPSTrackerLocation, double>(x => x.Location.Latitude),
- // row.Get<GPSTrackerLocation, double>(x => x.Location.Longitude)
- // );
- // if (!string.IsNullOrWhiteSpace(address))
- // {
- // item.Location.Address = address;
- // UpdateRow<GPSTrackerLocation, string>(row, x => x.Location.Address, address, false);
- // result = true;
- // }
- // }
- // });
- // return result;
- // }
- }
|