using System; using System.Linq.Expressions; using System.Windows.Controls; using Comal.Classes; using InABox.Core; using InABox.DynamicGrid; namespace PRSDesktop { public class EmployeeJobGrid : DynamicCrossJoinGrid { public override Expression> LeftMapping => x => x.EmployeeLink.ID; public override Expression> LeftProperty => x => x.ID; private Button _status; private bool _activeonly = true; public EmployeeJobGrid() { _status = AddButton("Show All", null, ToggleActive); _status.Width = 80; } protected override void GenerateColumns(DynamicGridColumns columns) { columns.Add(x => x.JobLink.JobNumber, 70, "Job", "", Alignment.MiddleCenter); columns.Add(x => x.JobLink.Name, 0, "Job Name", "", Alignment.MiddleLeft); columns.Add(x => x.Inducted, 70, "Inducted", "dd MMM yy", Alignment.MiddleCenter); columns.Add(x => x.Active, 25, "Act", "", Alignment.MiddleCenter); } private bool ToggleActive(Button arg1, CoreRow[] arg2) { _activeonly = !_activeonly; UpdateButton(_status,null,_activeonly ? "Show All" : "Active Only"); return true; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder? sort, Action action) { if (_activeonly) criteria.Add(new Filter(x => x.Active).IsEqualTo(true).And(x=>x.JobLink.JobStatus.Active).IsEqualTo(true)); base.Reload(criteria, columns, ref sort, action); } } }