123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using System;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using InABox.Wpf;
- using System.Threading;
- namespace PRSDesktop
- {
- public class JobFormGrid : DynamicEntityFormGrid<JobForm, Job, JobLink>, IMasterDetailControl<Job,JobForm>, IDataModelSource
- {
- protected override Job Entity { get => Master; set => Master = value; }
- public Job? Master { get; set; }
- public Filter<JobForm> MasterDetailFilter => (Master?.ID ?? Guid.Empty) != Guid.Empty
- ? new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(Master.ID)
- : new Filter<JobForm>().None();
-
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public string SectionName => "Job Forms";
- public DataModel DataModel(Selection selection)
- {
- var ids = ExtractValues(x => x.ID, selection).ToArray();
- return new AutoDataModel<JobForm>(new Filter<JobForm>(x => x.ID).InList(ids));
- }
- public JobFormGrid()
- {
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.SelectColumns = true;
- options.FilterRows = true;
- EditOnAdd = true;
- }
- protected override void Reload(
- Filters<JobForm> criteria, Columns<JobForm> columns, ref SortOrder<JobForm>? sort,
- CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(MasterDetailFilter);
- base.Reload(criteria, columns, ref sort, token, action);
- }
- protected override bool CanCreateItems()
- {
- return base.CanCreateItems() && Master != null;
- }
- public override JobForm CreateItem()
- {
- var result = base.CreateItem();
- result.Parent.ID = Master?.ID ?? Guid.Empty;
- result.Parent.Synchronise(Master ?? new Job());
- return result;
- }
- }
- }
|