using System; using System.Linq; using System.Linq.Expressions; using System.Windows.Media.Imaging; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; using InABox.Wpf.DynamicGrid; using PRSDesktop.Forms; namespace PRSDesktop { internal class DynamicMapColumn : DynamicImageColumn where T : Entity, new() { private readonly string Latitude; private readonly string Longitude; private readonly BitmapImage milestone = Resources.map.AsBitmapImage(); private readonly string? Geofence = ""; public DynamicMapColumn(DynamicGrid grid, Expression> property) : base(r => null) { Latitude = $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Address.Location)}.{nameof(Address.Location.Latitude)}"; grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression(Latitude)); Longitude = $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Address.Location)}.{nameof(Address.Location.Longitude)}"; grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression(Longitude)); Geofence = $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Address.Geofence)}"; grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression(Geofence)); Image = MapImage; Action = MapClick; GetFilter = () => new StaticColumnFilter(HasLocation, [ new("(Blank)", false), new("(Not Blank)", true) ]); } public DynamicMapColumn(DynamicGrid grid, Expression> property) : base(r => null) { Latitude = $"{CoreUtils.GetFullPropertyName(property, ".")}.{nameof(Location.Latitude)}"; grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression(Latitude)); Longitude = CoreUtils.GetFullPropertyName(property, ".") + ".Longitude"; grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression(Longitude)); Image = MapImage; Action = MapClick; GetFilter = () => new StaticColumnFilter(HasLocation, [ new("(Blank)", false), new("(Not Blank)", true) ]); } private bool HasLocation(CoreRow row) { var lat = row.Get(Latitude); var lng = row.Get(Longitude); return lat != 0.0F && lng != 0.0F; } private BitmapImage? MapImage(CoreRow? row) { return row is null || HasLocation(row) ? milestone : null; } private bool MapClick(CoreRow? row) { if (row is not null && HasLocation(row)) { var mapform = new MapForm(row.Get(Latitude), row.Get(Longitude)); mapform.ShowDialog(); //var Address = new Address(); //Address.Location.Latitude = row.Get(Latitude); //Address.Location.Longitude = row.Get(Longitude); //if (Geofence != null) // Address.Geofence = row.Get(Geofence); //var form = new GeofenceEditor(Address, false); //form.ShowDialog(); } return false; } } }