using System; using System.Linq; using System.Threading; using Comal.Classes; using InABox.Core; using InABox.DynamicGrid; using InABox.Wpf; namespace PRSDesktop; public class ConsignmentParcelGrid : DynamicDataGrid { public Guid ConsignmentID { get; set; } public bool Completed { get; set; } protected override DynamicGridColumns LoadColumns() { var columns = new DynamicGridColumns(); columns.Add(x => x.Description, 0, "Parcels", "", Alignment.MiddleLeft); return columns; } protected override void Reload( Filters criteria, Columns columns, ref SortOrder? sort, CancellationToken token, Action action) { criteria.Add(Filter.Where(x => x.Consignment.ID).IsEqualTo(ConsignmentID)); base.Reload(criteria, columns, ref sort, token, (table,exception) => { if ((ConsignmentID != CoreUtils.FullGuid) && (table != null)) { var row = table.NewRow(); row.Set(x => x.ID, CoreUtils.FullGuid); row.Set(x => x.Description, "(All Items)"); table.Rows.Insert(0, row); row = table.NewRow(); row.Set(x => x.ID, Guid.Empty); row.Set(x => x.Description, "(Unallocated Items)"); table.Rows.Add(row); } action(table,exception); }); } protected override bool CanCreateItems() { if (ConsignmentID == Guid.Empty) { MessageWindow.ShowMessage("Please select a Consignment first!", "Error"); return false; } if (Completed) { MessageWindow.ShowMessage("Cannot Modify a Completed Requisition!", "Error"); return false; } return base.CanCreateItems(); } public override ConsignmentParcel CreateItem() { var item = base.CreateItem(); item.Consignment.ID = ConsignmentID; return item; } protected override void DoEdit() { Guid id = SelectedRows.FirstOrDefault()?.Get(x => x.ID) ?? Guid.Empty; if ((id == CoreUtils.FullGuid) || (id == Guid.Empty)) MessageWindow.ShowMessage("You cannot edit this item!", "Error"); else base.DoEdit(); } }