| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- 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 : DynamicDataGrid<JobForm>, IMasterDetailControl<Job,JobForm>, IDataModelSource
- {
-
- 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()
- {
- ActionColumns.Add(new DynamicImageColumn(PRSDesktop.Resources.pencil.AsBitmapImage(), EditAction));
- }
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.SelectColumns = true;
- options.FilterRows = true;
- }
-
- private bool EditAction(CoreRow? row)
- {
- if (row == null) return false;
- if(DynamicFormEditWindow.EditDigitalForm<JobForm>(row.Get<JobForm, Guid>(x => x.ID), out var dataModel))
- {
- dataModel.Update(null);
- return true;
- }
- return false;
- }
- 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;
- }
- }
- }
|