123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- using System;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop
- {
- public class DeliveryItemsList : DynamicDataGrid<DeliveryItem>
- {
- public DeliveryItemsList()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns);
- HiddenColumns.Add(x => x.ShipmentLink.ID);
- HiddenColumns.Add(x => x.ShipmentCode);
- HiddenColumns.Add(x => x.RequisitionLink.ID);
- //AddButton("Add Rack", null, AddRack);
- //AddButton("Add Requi", null, AddRequi);
- //AddButton("Remove", null, RemoveItems);
- }
- public Guid JobID { get; set; }
- public Guid DeliveryID { get; set; }
- public DateTime Completed { get; set; }
- private bool AddRack(Button arg1, CoreRow[] arg2)
- {
- if (DeliveryID == Guid.Empty)
- {
- MessageBox.Show("Please select a Delivery First");
- return false;
- }
- if (!Completed.IsEmpty())
- {
- MessageBox.Show("You cannot modify a completed delivery!");
- return false;
- }
- var grid = new MultiSelectDialog<Shipment>(
- new Filter<Shipment>(x => x.Delivery).NotLinkValid(),
- null
- );
- if (grid.ShowDialog())
- {
- Progress.Show("Adding Rack Items 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");
- Progress.Close();
- return true;
- }
- return false;
- }
- private bool AddRequi(Button arg1, CoreRow[] arg2)
- {
- if (DeliveryID == Guid.Empty)
- {
- MessageBox.Show("Please select a Delivery First");
- return false;
- }
- if (!Completed.IsEmpty())
- {
- MessageBox.Show("You cannot modify a completed delivery!");
- return false;
- }
- var grid = new MultiSelectDialog<Requisition>(
- new Filter<Requisition>(x => x.JobLink.ID).IsEqualTo(JobID).And(x => x.Archived).IsEqualTo(DateTime.MinValue)
- .And(x => x.Delivery).NotLinkValid(),
- null
- );
- if (grid.ShowDialog())
- {
- Progress.Show("Adding Requisition Items to Delivery");
- var requis = grid.Items();
- var filter = new Filter<DeliveryItem>(x => x.ID).IsEqualTo(CoreUtils.FullGuid);
- foreach (var requi in requis)
- {
- filter = filter.Or(x => x.RequisitionLink.ID).IsEqualTo(requi.ID);
- requi.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<Requisition>().Save(requis, "Added to Delivery");
- Progress.Close();
- return true;
- }
- return false;
- }
- private bool RemoveItems(Button arg1, CoreRow[] arg2)
- {
- if (arg2 == null || !arg2.Any())
- {
- MessageBox.Show("Please select a row first");
- return false;
- }
- if (!Completed.IsEmpty())
- {
- MessageBox.Show("You cannot modify a completed delivery!");
- return false;
- }
- var bResult = false;
- Progress.Show("Removing Items from Delivery");
- DeliveryItem[] items = { };
- var requi = arg2.First().EntityLinkID<DeliveryItem, RequisitionLink>(x => x.RequisitionLink) ?? Guid.Empty;
- if (requi != Guid.Empty)
- {
- items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.RequisitionLink.ID).IsEqualTo(requi));
- var requisition = new Client<Requisition>().Load(new Filter<Requisition>(x => x.ID).IsEqualTo(requi)).FirstOrDefault();
- if (requisition != null)
- {
- requisition.Delivery.ID = Guid.Empty;
- new Client<Requisition>().Save(requisition, "Removed from Delivery");
- }
- }
- else
- {
- var rack = arg2.First().EntityLinkID<DeliveryItem, ShipmentLink>(x => x.ShipmentLink) ?? Guid.Empty;
- if (rack != Guid.Empty)
- {
- items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(rack));
- var shipment = new Client<Shipment>().Load(new Filter<Shipment>(x => x.ID).IsEqualTo(rack)).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");
- bResult = true;
- }
- Progress.Close();
- return bResult;
- }
- protected override void Reload(Filters<DeliveryItem> criteria, Columns<DeliveryItem> columns, ref SortOrder<DeliveryItem> sort,
- Action<CoreTable, Exception> action)
- {
- if (DeliveryID != Guid.Empty)
- criteria.Add(new Filter<DeliveryItem>(x => x.Delivery.ID).IsEqualTo(DeliveryID));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|