| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using System;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using InABox.Wpf;
- 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(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options
- .BeginUpdate()
- .Add(DynamicGridOption.SelectColumns)
- .Add(DynamicGridOption.FilterRows)
- .EndUpdate();
- }
-
- 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,
- Action<CoreTable?, Exception?> action)
- {
- criteria.Add(MasterDetailFilter);
- base.Reload(criteria, columns, ref sort, 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;
- }
- }
- }
|