| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- 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<ConsignmentParcel>
- {
- public Guid ConsignmentID { get; set; }
- public bool Completed { get; set; }
-
- protected override DynamicGridColumns LoadColumns()
- {
- var columns = new DynamicGridColumns();
- columns.Add<ConsignmentParcel>(x => x.Description, 0, "Parcels", "", Alignment.MiddleLeft);
- return columns;
- }
-
- protected override void Reload(
- Filters<ConsignmentParcel> criteria, Columns<ConsignmentParcel> columns, ref SortOrder<ConsignmentParcel>? sort,
- CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(Filter<ConsignmentParcel>.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<ConsignmentParcel, Guid>(x => x.ID, CoreUtils.FullGuid);
- row.Set<ConsignmentParcel, string>(x => x.Description, "(All Items)");
- table.Rows.Insert(0, row);
-
- row = table.NewRow();
- row.Set<ConsignmentParcel, Guid>(x => x.ID, Guid.Empty);
- row.Set<ConsignmentParcel, string>(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<ConsignmentParcel, Guid>(x => x.ID) ?? Guid.Empty;
- if ((id == CoreUtils.FullGuid) || (id == Guid.Empty))
- MessageWindow.ShowMessage("You cannot edit this item!", "Error");
- else
- base.DoEdit();
- }
- }
|