123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- using System;
- using System.Linq;
- using System.Windows;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop
- {
- internal class DeliveryRackList : DynamicDataGrid<Shipment>
- {
- public DeliveryRackList()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
- HiddenColumns.Add(x => x.Delivery.ID);
- ColumnsTag = "DeliveryRack";
- }
- public Guid JobID { get; set; }
- public Guid DeliveryID { get; set; }
- public DateTime Completed { get; set; }
- protected override DynamicGridColumns LoadColumns()
- {
- 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;
- }
- protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
- {
- if (DeliveryID == Guid.Empty)
- {
- MessageBox.Show("Please select a Delivery First");
- return;
- }
- if (!Completed.IsEmpty())
- {
- MessageBox.Show("You cannot modify a completed delivery!");
- return;
- }
- 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 = DeliveryID;
- }
- var items = new Client<DeliveryItem>().Load(filter);
- foreach (var item in items)
- item.Delivery.ID = DeliveryID;
- new Client<DeliveryItem>().Save(items, "Added to Delivery");
- new Client<Shipment>().Save(shipments, "Added to Delivery");
- DoChanged();
- Progress.Close();
- }
- }
- protected override void DeleteItems(params CoreRow[] rows)
- {
- if (rows == null || !rows.Any())
- {
- MessageBox.Show("Please select a row first");
- return;
- }
- if (!Completed.IsEmpty())
- {
- MessageBox.Show("You cannot modify a completed delivery!");
- return;
- }
- Progress.Show("Removing Items from Delivery");
- 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");
- }
- if (items.Any())
- {
- foreach (var item in items)
- item.Delivery.ID = Guid.Empty;
- new Client<DeliveryItem>().Save(items, "Removed From Delivery");
- }
- }
- DoChanged();
- Progress.Close();
- }
- protected override void Reload(Filters<Shipment> criteria, Columns<Shipment> columns, ref SortOrder<Shipment> sort,
- Action<CoreTable, Exception> action)
- {
- if (DeliveryID != Guid.Empty)
- criteria.Add(new Filter<Shipment>(x => x.Delivery.ID).IsEqualTo(DeliveryID));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|