|
@@ -8,144 +8,142 @@ using InABox.DynamicGrid;
|
|
|
using InABox.WPF;
|
|
|
using InABox.Wpf;
|
|
|
|
|
|
-namespace PRSDesktop
|
|
|
+namespace PRSDesktop;
|
|
|
+
|
|
|
+internal class DeliveryRackList : DynamicDataGrid<Shipment>, IMasterDetailControl<Delivery,Shipment>
|
|
|
{
|
|
|
- internal class DeliveryRackList : DynamicDataGrid<Shipment>, IMasterDetailControl<Delivery,Shipment>
|
|
|
+ public Delivery? Master { get; set; }
|
|
|
+
|
|
|
+ public Filter<Shipment> MasterDetailFilter => Master != null && Master.ID != Guid.Empty
|
|
|
+ ? new Filter<Shipment>(x => x.Delivery.ID).IsEqualTo(Master.ID)
|
|
|
+ : new Filter<Shipment>().None();
|
|
|
+
|
|
|
+ public DeliveryRackList()
|
|
|
{
|
|
|
- public Delivery? Master { get; set; }
|
|
|
+ HiddenColumns.Add(x => x.Delivery.ID);
|
|
|
+ ColumnsTag = "DeliveryRack";
|
|
|
+ }
|
|
|
|
|
|
- public Filter<Shipment> MasterDetailFilter => Master != null
|
|
|
- ? new Filter<Shipment>(x => x.Delivery.ID).IsEqualTo(Master.ID)
|
|
|
- : new Filter<Shipment>().None();
|
|
|
-
|
|
|
- public DeliveryRackList()
|
|
|
+ protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
|
+ {
|
|
|
+ base.DoReconfigure(options);
|
|
|
+ options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected override DynamicGridColumns LoadColumns()
|
|
|
+ {
|
|
|
+ var columns = new DynamicGridColumns
|
|
|
{
|
|
|
- HiddenColumns.Add(x => x.Delivery.ID);
|
|
|
- ColumnsTag = "DeliveryRack";
|
|
|
- }
|
|
|
+ new() { ColumnName = "Code", Width = 40, Caption = "Rack", Alignment = Alignment.MiddleCenter },
|
|
|
+ new() { ColumnName = "Description", Width = 0, Caption = "Description" },
|
|
|
+ new() { ColumnName = "ItemCount", Width = 25, Caption = "#", Alignment = Alignment.MiddleCenter }
|
|
|
+ };
|
|
|
+ return columns;
|
|
|
+ }
|
|
|
|
|
|
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
|
|
|
+ protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
|
|
|
+ {
|
|
|
+ if ((Master?.ID ?? Guid.Empty) == Guid.Empty)
|
|
|
{
|
|
|
- base.DoReconfigure(options);
|
|
|
- options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
|
|
|
+ MessageBox.Show("Please select a Delivery First");
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- public Delivery Delivery { get; set; }
|
|
|
|
|
|
- protected override DynamicGridColumns LoadColumns()
|
|
|
+ if (!Master.Completed.IsEmpty())
|
|
|
{
|
|
|
- var columns = new DynamicGridColumns
|
|
|
- {
|
|
|
- new() { ColumnName = "Code", Width = 40, Caption = "Rack", Alignment = Alignment.MiddleCenter },
|
|
|
- new() { ColumnName = "Description", Width = 0, Caption = "Description" },
|
|
|
- new() { ColumnName = "ItemCount", Width = 25, Caption = "#", Alignment = Alignment.MiddleCenter }
|
|
|
- };
|
|
|
- return columns;
|
|
|
+ MessageBox.Show("You cannot modify a completed delivery!");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
|
|
|
+
|
|
|
+ var grid = new MultiSelectDialog<Shipment>(
|
|
|
+ new Filter<Shipment>(x => x.Delivery).NotLinkValid(),
|
|
|
+ new Columns<Shipment>(x => x.ID)
|
|
|
+ .Add(x => x.Delivery.ID)
|
|
|
+ );
|
|
|
+ if (grid.ShowDialog())
|
|
|
{
|
|
|
- if ((Delivery?.ID ?? Guid.Empty) == Guid.Empty)
|
|
|
+ Progress.Show("Adding Racks to Delivery");
|
|
|
+
|
|
|
+ var shipments = grid.Data().ToObjects<Shipment>();
|
|
|
+ var filter = new Filter<DeliveryItem>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
|
|
|
+ foreach (var shipment in shipments)
|
|
|
{
|
|
|
- MessageBox.Show("Please select a Delivery First");
|
|
|
- return;
|
|
|
+ filter = filter.Or(x => x.ShipmentLink.ID).IsEqualTo(shipment.ID);
|
|
|
+ shipment.Delivery.ID = Master.ID;
|
|
|
+ shipment.Delivery.Synchronise(Master);
|
|
|
}
|
|
|
|
|
|
- if (!Delivery.Completed.IsEmpty())
|
|
|
+ var items = new Client<DeliveryItem>().Query(filter, new Columns<DeliveryItem>(x => x.Delivery.ID)).ToArray<DeliveryItem>();
|
|
|
+ foreach (var item in items)
|
|
|
{
|
|
|
- MessageBox.Show("You cannot modify a completed delivery!");
|
|
|
- return;
|
|
|
+ item.Delivery.ID = Master.ID;
|
|
|
+ item.Delivery.Synchronise(Master);
|
|
|
}
|
|
|
|
|
|
+ new Client<DeliveryItem>().Save(items, "Added to Delivery");
|
|
|
+ new Client<Shipment>().Save(shipments, "Added to Delivery");
|
|
|
|
|
|
- var grid = new MultiSelectDialog<Shipment>(
|
|
|
- new Filter<Shipment>(x => x.Delivery).NotLinkValid(),
|
|
|
- null
|
|
|
- );
|
|
|
- if (grid.ShowDialog())
|
|
|
- {
|
|
|
- Progress.Show("Adding Racks to Delivery");
|
|
|
-
|
|
|
- var shipments = grid.Items();
|
|
|
- var filter = new Filter<DeliveryItem>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
|
|
|
- foreach (var shipment in shipments)
|
|
|
- {
|
|
|
- filter = filter.Or(x => x.ShipmentLink.ID).IsEqualTo(shipment.ID);
|
|
|
- shipment.Delivery.ID = Delivery.ID;
|
|
|
- shipment.Delivery.Synchronise(Delivery);
|
|
|
- }
|
|
|
-
|
|
|
- var items = new Client<DeliveryItem>().Load(filter);
|
|
|
- foreach (var item in items)
|
|
|
- {
|
|
|
- item.Delivery.ID = Delivery.ID;
|
|
|
- item.Delivery.Synchronise(Delivery);
|
|
|
- }
|
|
|
-
|
|
|
- new Client<DeliveryItem>().Save(items, "Added to Delivery");
|
|
|
- new Client<Shipment>().Save(shipments, "Added to Delivery");
|
|
|
+ DoChanged();
|
|
|
|
|
|
- DoChanged();
|
|
|
+ Progress.Close();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- Progress.Close();
|
|
|
- }
|
|
|
+ protected override void DeleteItems(params CoreRow[] rows)
|
|
|
+ {
|
|
|
+
|
|
|
+ if ((Master?.ID ?? Guid.Empty) == Guid.Empty)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please select a Delivery First");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rows?.Any() != true)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Please select a row first");
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- protected override void DeleteItems(params CoreRow[] rows)
|
|
|
+ if (!Master.Completed.IsEmpty())
|
|
|
{
|
|
|
-
|
|
|
- if ((Delivery?.ID ?? Guid.Empty) == Guid.Empty)
|
|
|
- {
|
|
|
- MessageBox.Show("Please select a Delivery First");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (rows?.Any() != true)
|
|
|
- {
|
|
|
- MessageBox.Show("Please select a row first");
|
|
|
- return;
|
|
|
- }
|
|
|
+ MessageBox.Show("You cannot modify a completed delivery!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- if (!Delivery.Completed.IsEmpty())
|
|
|
- {
|
|
|
- MessageBox.Show("You cannot modify a completed delivery!");
|
|
|
- return;
|
|
|
- }
|
|
|
+ Progress.Show("Removing Items from Delivery");
|
|
|
|
|
|
- Progress.Show("Removing Items from Delivery");
|
|
|
+ DeliveryItem[] items = { };
|
|
|
|
|
|
- DeliveryItem[] items = { };
|
|
|
+ foreach (var row in rows)
|
|
|
+ {
|
|
|
+ var rackid = row.Get<Shipment, Guid>(x => x.ID);
|
|
|
+ items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(rackid));
|
|
|
+ var shipment = new Client<Shipment>().Load(new Filter<Shipment>(x => x.ID).IsEqualTo(rackid)).FirstOrDefault();
|
|
|
+ if (shipment != null)
|
|
|
+ {
|
|
|
+ shipment.Delivery.ID = Guid.Empty;
|
|
|
+ new Client<Shipment>().Save(shipment, "Removed from Delivery");
|
|
|
+ }
|
|
|
|
|
|
- foreach (var row in rows)
|
|
|
+ if (items.Any())
|
|
|
{
|
|
|
- var rackid = row.Get<Shipment, Guid>(x => x.ID);
|
|
|
- items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(rackid));
|
|
|
- var shipment = new Client<Shipment>().Load(new Filter<Shipment>(x => x.ID).IsEqualTo(rackid)).FirstOrDefault();
|
|
|
- if (shipment != null)
|
|
|
- {
|
|
|
- shipment.Delivery.ID = Guid.Empty;
|
|
|
- new Client<Shipment>().Save(shipment, "Removed from Delivery");
|
|
|
- }
|
|
|
-
|
|
|
- if (items.Any())
|
|
|
- {
|
|
|
- foreach (var item in items)
|
|
|
- item.Delivery.ID = Guid.Empty;
|
|
|
- new Client<DeliveryItem>().Save(items, "Removed From Delivery");
|
|
|
- }
|
|
|
+ foreach (var item in items)
|
|
|
+ item.Delivery.ID = Guid.Empty;
|
|
|
+ new Client<DeliveryItem>().Save(items, "Removed From Delivery");
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- DoChanged();
|
|
|
+ DoChanged();
|
|
|
|
|
|
- Progress.Close();
|
|
|
- }
|
|
|
+ Progress.Close();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- protected override void Reload(Filters<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment>? sort, Action<CoreTable?, Exception?> action)
|
|
|
- {
|
|
|
-
|
|
|
- criteria.Add(MasterDetailFilter);
|
|
|
- base.Reload(criteria, columns, ref sort, action);
|
|
|
- }
|
|
|
+ protected override void Reload(Filters<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment>? sort, Action<CoreTable?, Exception?> action)
|
|
|
+ {
|
|
|
+
|
|
|
+ criteria.Add(MasterDetailFilter);
|
|
|
+ base.Reload(criteria, columns, ref sort, action);
|
|
|
}
|
|
|
}
|