123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 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 DeliveryRequiList : DynamicDataGrid<Requisition>
- {
- public DeliveryRequiList()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.SelectColumns);
- HiddenColumns.Add(x => x.Delivery.ID);
- ColumnsTag = "DeliveryRequi";
- }
- 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 = "Number", Width = 40, Caption = "Req.", Alignment = Alignment.MiddleCenter },
- new() { ColumnName = "Title", Width = 0, Caption = "Requisition" },
- new() { ColumnName = "Filled", Width = 50, Caption = "Done", Format = "dd MMM", Alignment = Alignment.MiddleCenter },
- new() { ColumnName = "Boxes", Width = 25, Caption = "#", Alignment = Alignment.MiddleCenter }
- };
- return columns;
- }
- protected override void DoAdd()
- {
- 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<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 Requsition 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");
- OnChanged?.Invoke(this);
- 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 reqid = row.Get<Requisition, Guid>(x => x.ID);
- items = new Client<DeliveryItem>().Load(new Filter<DeliveryItem>(x => x.RequisitionLink.ID).IsEqualTo(reqid));
- var requisition = new Client<Requisition>().Load(new Filter<Requisition>(x => x.ID).IsEqualTo(reqid)).FirstOrDefault();
- if (requisition != null)
- {
- requisition.Delivery.ID = Guid.Empty;
- new Client<Requisition>().Save(requisition, "Removed from Delivery");
- }
- if (items.Any())
- {
- foreach (var item in items)
- item.Delivery.ID = Guid.Empty;
- new Client<DeliveryItem>().Save(items, "Removed From Delivery");
- }
- }
- OnChanged?.Invoke(this);
- Progress.Close();
- }
- protected override void Reload(Filters<Requisition> criteria, Columns<Requisition> columns, ref SortOrder<Requisition> sort,
- Action<CoreTable, Exception> action)
- {
- if (DeliveryID != Guid.Empty)
- criteria.Add(new Filter<Requisition>(x => x.Delivery.ID).IsEqualTo(DeliveryID));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
- }
|