1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Windows.Media.Imaging;
- using InABox.Core;
- using InABox.DynamicGrid.Properties;
- using InABox.WPF;
- namespace InABox.DynamicGrid
- {
- public class DynamicTickColumn<T, P> : DynamicActionColumn where T : BaseObject, new() where P : struct
- {
- private readonly BitmapImage? Data = Resources.tick.AsBitmapImage();
- private readonly BitmapImage? Header;
- private readonly BitmapImage? NoData;
- private readonly Expression<Func<T, P>> Property;
- public DynamicTickColumn(Expression<Func<T, P>> property, BitmapImage? header, BitmapImage? data, BitmapImage? nodata,
- Func<CoreRow, bool>? action = null) : base(r => null, action)
- {
- Header = header;
- Data = data;
- NoData = nodata;
- Property = property;
- Image = GetImage;
- Filters = new[] { "(Blank)", "(Not Blank)" };
- FilterRecord = TickFilter;
- }
- private bool TickFilter(CoreRow row, string[] filter)
- {
- if (filter.Contains("(Blank)") && !HasData(row))
- return true;
- if (filter.Contains("(Not Blank)") && HasData(row))
- return true;
- return false;
- }
- private BitmapImage? GetImage(CoreRow row)
- {
- if (row == null)
- return Header;
- return HasData(row) ? Data : NoData;
- }
- private bool HasData(CoreRow row)
- {
- var value = row.Get(Property);
- return !value.Equals(default(P));
- //bool hasdata = false;
- //if (typeof(P) == typeof(bool))
- // hasdata = value.Equals(true);
- //else if (typeof(P) == typeof(DateTime))
- // hasdata = !value.Equals(DateTime.MinValue);
- //return hasdata;
- }
- }
- }
|