12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 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;
- Filters = new[] { "(Blank)", "(Not Blank)" };
- FilterRecord = MapFilter;
- }
- private bool MapFilter(CoreRow row, string[] filter)
- {
- if (filter.Contains("(Blank)") && !HasLocation(row))
- return true;
- if (filter.Contains("(Not Blank)") && HasLocation(row))
- return true;
- return false;
- }
- 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;
- }
- }
- }
|