using System; using System.Collections.Generic; using System.Linq; using System.Windows.Media.Imaging; using Comal.Classes; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; namespace PRSDesktop { public class StockTreatmentGrid : DynamicDataGrid { private readonly List _selected = new(); private readonly BitmapImage tick = PRSDesktop.Resources.tick.AsBitmapImage(); public StockTreatmentGrid() { Options.Clear(); ActionColumns.Add(new DynamicImageColumn(SelectedImage, SelectedAction) { Position = DynamicActionColumnPosition.End }); } public Guid Location { get; set; } public IEnumerable Selected => _selected; protected override DynamicGridColumns LoadColumns() { //return base.LoadColumns(); var result = new DynamicGridColumns(); result.Add(x => x.Units, 50, "Qty", "F0", Alignment.MiddleCenter); result.Add(x => x.Product.Code, 120, "Code", "", Alignment.MiddleLeft); result.Add(x => x.Product.Name, 0, "Name", "", Alignment.MiddleLeft); result.Add(x => x.Dimensions.UnitSize, 100, "Size", "", Alignment.MiddleCenter); result.Add(x => x.Job.JobNumber, 70, "Job #", "", Alignment.MiddleCenter); return result; } private BitmapImage SelectedImage(CoreRow arg) { return arg == null ? tick : _selected.Contains(arg.Get(x => x.ID)) ? tick : null; } private bool SelectedAction(CoreRow arg) { if (arg == null) { if (_selected.Any()) _selected.Clear(); else _selected.AddRange(Data.ExtractValues(x => x.ID)); } else { var id = arg.Get(x => x.ID); if (_selected.Contains(id)) _selected.Remove(id); else _selected.Add(id); } return true; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { criteria.Add(new Filter(x => x.Location.ID).IsEqualTo(Location)); base.Reload(criteria, columns, ref sort, action); } } }