123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reactive.Linq;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- using InABox.WPF;
- using PRSDesktop.Panels.Requisitions;
- namespace PRSDesktop;
- internal class JobPickingListItemGrid : DynamicDataGrid<RequisitionItem>, ISpecificGrid, IMasterDetailControl<Requisition, RequisitionItem>
- {
- public Requisition? Master { get; set; }
- private Task<List<Product>>? _products;
-
- public Filter<RequisitionItem> MasterDetailFilter => Master != null
- ? new Filter<RequisitionItem>(x => x.RequisitionLink.ID).IsEqualTo(Master.ID)
- : new Filter<RequisitionItem>().None();
- protected override void Init()
- {
- base.Init();
- HiddenColumns.Add(x => x.RequisitionLink.JobLink.ID);
- HiddenColumns.Add(x => x.Product.ID);
- HiddenColumns.Add(x => x.Style.ID);
- HiddenColumns.Add(x => x.JobLink.ID);
- HiddenColumns.Add(x =>x.Dimensions.Unit.ID);
- HiddenColumns.Add(x => x.Dimensions.UnitSize);
- HiddenColumns.Add(x => x.JobRequisitionItem.ID);
- HiddenColumns.Add(x => x.Location.ID);
- HiddenColumns.Add(x => x.EditType);
- HiddenColumns.Add(x => x.Done);
- }
-
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options.AddRange(
- DynamicGridOption.SelectColumns,
- DynamicGridOption.FilterRows
- );
- }
- protected override void Reload(Filters<RequisitionItem> criteria, Columns<RequisitionItem> columns,
- ref SortOrder<RequisitionItem>? sort,
- Action<CoreTable?, Exception?> action)
- {
- criteria.Add(MasterDetailFilter);
- base.Reload(criteria, columns, ref sort, action);
- }
- private List<Product> GetProducts()
- {
- _products ??= Task.Run(() =>
- {
- return Client.Query(null, new Columns<Product>(x => x.Code).Add(x => x.Name).Add(x => x.ID)).ToList<Product>();
- });
- return _products.Result;
- }
- private void DoEdit(CoreRow? row)
- {
- var item = row?.ToObject<RequisitionItem>();
- if(item is null)
- {
- if (!CanCreateItems())
- return;
- item = CreateItem();
- }
- var editor = new RequisitionItemEditor(GetProducts, item, false);
- if(editor.ShowDialog() == true && editor.Result is not null)
- {
- Refresh(false, true);
- DoChanged();
- }
- }
- protected override void DoEdit()
- {
- var rows = SelectedRows;
- if (rows.Length != 1) return;
- if (rows[0].Get<RequisitionItem, bool>(x => x.Done))
- {
- base.DoEdit();
- }
- else
- {
- DoEdit(rows[0]);
- }
- }
- protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
- {
- DoEdit(null);
- }
- public override void InitialiseEditorForm(IDynamicEditorForm editor, RequisitionItem[] items, Func<Type, CoreTable?>? pageDataHandler = null, bool preloadPages = false)
- {
- base.InitialiseEditorForm(editor, items, pageDataHandler, preloadPages);
- if(items.Any(x => x.Done))
- {
- editor.ReadOnly = true;
- }
- }
- protected override bool CanCreateItems()
- {
- return base.CanCreateItems() && (Master?.ID ?? Guid.Empty) != Guid.Empty;
- }
- public override RequisitionItem CreateItem()
- {
- var result = base.CreateItem();
- result.RequisitionLink.ID = Master?.ID ?? Guid.Empty;
- result.RequisitionLink.Synchronise(Master ?? new Requisition());
- result.JobLink.ID = Master?.JobLink.ID ?? Guid.Empty;
- result.JobLink.Synchronise(Master?.JobLink ?? new JobLink());
- return result;
- }
- }
|