| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using InABox.Core;
- using InABox.WPF;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Runtime.CompilerServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using Xceed.Wpf.Toolkit;
- namespace InABox.DynamicGrid;
- public class DateDynamicGridColumnFilter(IBaseDynamicGrid grid, DynamicColumnBase column) : IDynamicGridColumnFilter, INotifyPropertyChanged
- {
- public event Action<IDynamicGridColumnFilter>? FilterChanged;
- public event PropertyChangedEventHandler? PropertyChanged;
- private DateTime? _fromDate;
- public DateTime? FromDate
- {
- get => _fromDate;
- set
- {
- _fromDate = value;
- FilterChanged?.Invoke(this);
- OnPropertyChanged();
- }
- }
- private DateTime? _toDate;
- public DateTime? ToDate
- {
- get => _toDate;
- set
- {
- _toDate = value;
- FilterChanged?.Invoke(this);
- OnPropertyChanged();
- }
- }
- public void ClearFilter()
- {
- _fromDate = null;
- _toDate = null;
- FilterChanged?.Invoke(this);
- }
- public FrameworkElement CreateControl()
- {
- var grid = new Grid();
- grid.AddColumn(GridUnitType.Star);
- grid.AddColumn(GridUnitType.Auto);
- grid.AddRow(GridUnitType.Auto);
- grid.AddRow(GridUnitType.Auto);
- grid.AddChild(new Label
- {
- Content = "From: ",
- VerticalAlignment = VerticalAlignment.Center
- }, 0, 0);
- var fromPicker = new DateTimePicker
- {
- Format = DateTimeFormat.Custom,
- FormatString = "dd MMM yyyy HH:mm",
- VerticalAlignment = VerticalAlignment.Stretch,
- VerticalContentAlignment = VerticalAlignment.Center,
- HorizontalContentAlignment = HorizontalAlignment.Center,
- CalendarDisplayMode = CalendarMode.Month,
- ShowButtonSpinner = false,
- Height = 25,
- Width = 150
- };
- fromPicker.Bind(DateTimePicker.ValueProperty, this, x => x.FromDate, mode: BindingMode.TwoWay);
- grid.AddChild(fromPicker, 0, 1);
- grid.AddChild(new Label
- {
- Content = "To: ",
- VerticalAlignment = VerticalAlignment.Center,
- Margin = new(0, 5, 0, 0)
- }, 1, 0);
- var toPicker = new DateTimePicker
- {
- Format = DateTimeFormat.Custom,
- FormatString = "dd MMM yyyy HH:mm",
- VerticalAlignment = VerticalAlignment.Stretch,
- VerticalContentAlignment = VerticalAlignment.Center,
- HorizontalContentAlignment = HorizontalAlignment.Center,
- CalendarDisplayMode = CalendarMode.Month,
- ShowButtonSpinner = false,
- Width = 150,
- Height = 25,
- Margin = new(0, 5, 0, 0)
- };
- toPicker.Bind(DateTimePicker.ValueProperty, this, x => x.ToDate, mode: BindingMode.TwoWay);
- grid.AddChild(toPicker, 1, 1);
- return grid;
- }
- public bool FilterRow(CoreRow row)
- {
- if(grid.GetData(row, column) is DateTime date)
- {
- return (_fromDate is null || date >= _fromDate.Value)
- && (_toDate is null || date <= _toDate.Value);
- }
- else
- {
- return true;
- }
- }
- public bool IsFiltered()
- {
- return _fromDate is not null || _toDate is not null;
- }
- private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
|