DynamicTickColumn.cs 1.9 KB

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