DynamicTickColumn.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. using System.Windows.Media.Imaging;
  5. using InABox.Core;
  6. using InABox.WPF;
  7. namespace InABox.DynamicGrid
  8. {
  9. public class DynamicTickColumn<T, P> : DynamicImageColumn where T : BaseObject, new() where P : struct
  10. {
  11. private readonly BitmapImage? Data = Wpf.Resources.tick.AsBitmapImage();
  12. private readonly BitmapImage? Header;
  13. private readonly BitmapImage? NoData;
  14. private readonly Expression<Func<T, P>> Property;
  15. public DynamicTickColumn(Expression<Func<T, P>> property, BitmapImage? header, BitmapImage? data, BitmapImage? nodata,
  16. ActionDelegate? action = null) : base(r => null, action)
  17. {
  18. Header = header;
  19. Data = data;
  20. NoData = nodata;
  21. Property = property;
  22. Image = GetImage;
  23. Filters = new[] { "(Blank)", "(Not Blank)" };
  24. FilterRecord = TickFilter;
  25. }
  26. private bool TickFilter(CoreRow row, string[] filter)
  27. {
  28. if (filter.Contains("(Blank)") && !HasData(row))
  29. return true;
  30. if (filter.Contains("(Not Blank)") && HasData(row))
  31. return true;
  32. return false;
  33. }
  34. private BitmapImage? GetImage(CoreRow? row)
  35. {
  36. if (row == null)
  37. return Header;
  38. return HasData(row) ? Data : NoData;
  39. }
  40. private bool HasData(CoreRow row)
  41. {
  42. var value = row.Get(Property);
  43. return !value.Equals(default(P));
  44. //bool hasdata = false;
  45. //if (typeof(P) == typeof(bool))
  46. // hasdata = value.Equals(true);
  47. //else if (typeof(P) == typeof(DateTime))
  48. // hasdata = !value.Equals(DateTime.MinValue);
  49. //return hasdata;
  50. }
  51. }
  52. }