123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Linq.Expressions;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using InABox.Clients;
- using InABox.Core;
- using InABox.WPF;
- namespace InABox.DynamicGrid;
- // public interface IDynamicIssuesColumn
- // {
- // Func<IIssues[], FrameworkElement?>? CustomiseEditor { get; set; }
- // Action<IIssues[], FrameworkElement?>? IssuesUpdated { get; set; }
- // }
- //
- // public class DynamicIssuesColumn<TIssues> : DynamicImageColumn, IDynamicIssuesColumn
- // where TIssues : Entity, IRemotable, IPersistent, IIssues, new()
- // {
- // private static readonly BitmapImage _warning = Wpf.Resources.warning.AsBitmapImage();
- // private static readonly BitmapImage _graywarning = Wpf.Resources.warning.AsGrayScale().AsBitmapImage();
- //
- // private readonly IDynamicGrid _parent;
- //
- // public string IssuesProperty;
- // public string IssuesResolvedProperty;
- // public Func<CoreRow[], TIssues[]> LoadIssues;
- //
- // public Func<IIssues[], FrameworkElement?>? CustomiseEditor { get; set; }
- //
- // public Action<IIssues[], FrameworkElement?>? IssuesUpdated { get; set; }
- //
- // public DynamicIssuesColumn(IDynamicGrid parent, string issuesProperty, string issuesResolvedProperty, Func<CoreRow[], TIssues[]> loadIssues)
- // {
- // Image = IssuesImage;
- // Filters = new[] { "Active Issues", "No Issues" };
- // FilterRecord = DoFilterIssues;
- // ContextMenu = CreateIssuesMenu;
- // ToolTip = CreateIssuesToolTip;
- // _parent = parent;
- // Position = DynamicActionColumnPosition.Start;
- //
- // IssuesProperty = issuesProperty;
- // IssuesResolvedProperty = issuesResolvedProperty;
- // LoadIssues = loadIssues;
- // }
- //
- // public DynamicIssuesColumn(IDynamicGrid parent):
- // this(parent, CoreUtils.GetFullPropertyName<TIssues, string>(x => x.Issues, ""), CoreUtils.GetFullPropertyName<TIssues, DateTime>(x => x.IssuesResolved, ""), (rows) => rows.ToObjects<TIssues>().ToArray())
- // {
- // }
- //
- // private string? GetIssues(CoreRow? row)
- // {
- // return row?.Get<string>(IssuesProperty);
- // }
- //
- // private DateTime GetIssuesResolved(CoreRow? row)
- // {
- // return row?.Get<DateTime>(IssuesResolvedProperty) ?? DateTime.MinValue;
- // }
- //
- // private BitmapImage? IssuesImage(CoreRow? row)
- // {
- // if (GetIssues(row).IsNullOrWhiteSpace())
- // return null;
- // return GetIssuesResolved(row).IsEmpty()
- // ? _warning
- // : _graywarning;
- // }
- //
- // private FrameworkElement? CreateIssuesToolTip(DynamicActionColumn column, CoreRow? row)
- // {
- // var text = GetIssues(row);
- // if (text.IsNullOrWhiteSpace())
- // text = "No Issues Found";
- // return TextToolTip(text);
- // }
- //
- // private bool DoFilterIssues(CoreRow row, string[] filter)
- // {
- // var noissues = GetIssues(row).IsNullOrWhiteSpace();
- // if (filter.Contains("No Issues") && noissues)
- // return true;
- // if (filter.Contains("Active Issues") && !noissues)
- // return true;
- // return false;
- // }
- //
- // private MenuItem CreateMenu(string caption, RoutedEventHandler click)
- // {
- // var item = new MenuItem();
- // item.Header = caption;
- // item.Click += click;
- // return item;
- // }
- //
- // private ContextMenu? CreateIssuesMenu(CoreRow[]? rows)
- // {
- // if (!Security.CanManageIssues<TIssues>())
- // return null;
- //
- // var issues = rows?.Select(GetIssues).Where(x => !string.IsNullOrWhiteSpace(x)).Any();
- // var result = new ContextMenu();
- //
- // if (issues != true)
- // {
- // result.Items.Add(CreateMenu("Create Issue", (o, e) => EditIssues(rows)));
- // }
- // else
- // {
- // result.Items.Add(CreateMenu("Update Issues", (o, e) => EditIssues(rows)));
- // result.Items.Add(CreateMenu("Clear Issues", (o, e) => ClearIssues(rows)));
- // }
- //
- // return result;
- // }
- //
- // private void ClearIssues(CoreRow[]? rows)
- // {
- // if (rows is null)
- // {
- // return;
- // }
- // if (MessageBox.Show("This will clear the flagged issues for these items!\n\nAre you sure you wish to continue?", "Confirm",
- // MessageBoxButton.YesNo) == MessageBoxResult.Yes)
- // {
- // var _updates = LoadIssues(rows).ToArray();
- // foreach (var update in _updates)
- // {
- // update.Issues = "";
- // }
- // using (new WaitCursor())
- // {
- // Client.Save(_updates, "Clearing Issues", (o, e) => { });
- // }
- //
- // // False here to prevent Refreshing and losing the selected row record
- // foreach (var row in rows)
- // _parent.UpdateRow(row, IssuesProperty, "");
- // }
- // }
- //
- // private void EditIssues(CoreRow[]? rows)
- // {
- // var _objects = LoadIssues(rows ?? Array.Empty<CoreRow>());
- //
- // var _map = new Dictionary<CoreRow, TIssues>();
- // if (rows is not null)
- // {
- // var i = 0;
- // foreach (var row in rows)
- // {
- // _map[row] = _objects[i];
- // ++i;
- // }
- // }
- //
- // var _values = _map.Values.OfType<IIssues>().ToArray();
- // var _editor = new DynamicIssuesEditor(_values);
- // var _custom = CustomiseEditor?.Invoke(_values);
- // if (_custom != null)
- // _editor.SetCustom(_custom);
- // if (_editor.ShowDialog() == true)
- // {
- // using (new WaitCursor())
- // {
- // if (_custom != null)
- // IssuesUpdated?.Invoke(_values, _custom);
- // Client.Save(_map.Values, "Updating Issues", (o, e) => { });
- // }
- //
- // foreach (var _row in _map.Keys)
- // _parent.UpdateRow(_row, IssuesProperty, _map[_row].Issues);
- // }
- // }
- // }
|