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 { 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( new Filter(x => x.Delivery).NotLinkValid(), null ); if (grid.ShowDialog()) { Progress.Show("Adding Racks to Delivery"); var shipments = grid.Items(); var filter = new Filter(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().Load(filter); foreach (var item in items) item.Delivery.ID = DeliveryID; new Client().Save(items, "Added to Delivery"); new Client().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(x => x.ID); items = new Client().Load(new Filter(x => x.ShipmentLink.ID).IsEqualTo(rackid)); var shipment = new Client().Load(new Filter(x => x.ID).IsEqualTo(rackid)).FirstOrDefault(); if (shipment != null) { shipment.Delivery.ID = Guid.Empty; new Client().Save(shipment, "Removed from Delivery"); } if (items.Any()) { foreach (var item in items) item.Delivery.ID = Guid.Empty; new Client().Save(items, "Removed From Delivery"); } } DoChanged(); Progress.Close(); } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { if (DeliveryID != Guid.Empty) criteria.Add(new Filter(x => x.Delivery.ID).IsEqualTo(DeliveryID)); base.Reload(criteria, columns, ref sort, action); } } }