123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Windows.Media.Imaging;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using PRSDesktop.Forms;
- namespace PRSDesktop
- {
- internal class DynamicMapColumn<T> : DynamicImageColumn where T : Entity, new()
- {
- private readonly string Latitude = "";
- private readonly string Longitude = "";
- private readonly BitmapImage milestone = Resources.milestone.AsBitmapImage();
- private readonly string Timestamp = "";
- public DynamicMapColumn(DynamicGrid<T> grid, Expression<Func<T, object>> property) : base(r => null)
- {
- Latitude = CoreUtils.GetFullPropertyName(property, ".") + ".Latitude";
- Longitude = CoreUtils.GetFullPropertyName(property, ".") + ".Longitude";
- Timestamp = CoreUtils.GetFullPropertyName(property, ".") + ".Timestamp";
- grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Latitude));
- grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Longitude));
- grid.HiddenColumns.Add(CoreUtils.GetPropertyExpression<T>(Timestamp));
- Property = property;
- Image = MapImage;
- Action = MapClick;
- GetFilter = () => new StaticColumnFilter<bool>(HasLocation, [
- new("(Blank)", false),
- new("(Not Blank)", true)
- ]);
- }
- public Expression<Func<T, object>> Property { get; }
- private bool HasLocation(CoreRow row)
- {
- var lat = row.Get<double>(Latitude);
- var lng = row.Get<double>(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 form = new MapForm(row.Get<double>(Latitude), row.Get<double>(Longitude), row.Get<DateTime>(Timestamp));
- form.ShowDialog();
- }
- return false;
- }
- }
- }
|