| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading;
- using System.Windows;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- namespace PRSDesktop;
- public class JobITPGrid : DynamicDataGrid<JobITP>, IMasterDetailControl<Job,JobITP>, IDataModelSource
- {
-
- public Job? Master { get; set; }
-
- public Filter<JobITP> MasterDetailFilter => (Master?.ID ?? Guid.Empty) != Guid.Empty
- ? new Filter<JobITP>(x => x.Job.ID).IsEqualTo(Master.ID)
- : new Filter<JobITP>().None();
-
- public JobITPGrid()
- {
- ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { Position = DynamicActionColumnPosition.Start });
- }
-
- protected override void DoReconfigure(DynamicGridOptions options)
- {
- base.DoReconfigure(options);
- options.RecordCount = true;
- options.SelectColumns = true;
- options.AddRows = true;
- options.ImportData = true;
- options.FilterRows = true;
- options.MultiSelect = true;
- options.EditRows = true;
- options.DeleteRows = true;
- }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public string SectionName => "Job ITPs";
-
- public DataModel DataModel(Selection selection)
- {
- var ids = ExtractValues(x => x.ID, selection).ToArray();
- return new BaseDataModel<JobITP>(new Filter<JobITP>(x => x.ID).InList(ids));
- }
-
- private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
- {
- if (row == null) return;
- var item = column.AddItem("Digital Forms", PRSDesktop.Resources.kanban, null);
- DynamicGridUtils.PopulateFormMenu<JobITPForm, JobITP, JobITPLink>(item, row.Get<JobITP, Guid>(x => x.ID), () => row.ToObject<JobITP>());
- }
-
- protected override bool CanCreateItems()
- {
- return base.CanCreateItems() && (Master?.ID ?? Guid.Empty) != Guid.Empty;
- }
- public override JobITP CreateItem()
- {
- var result = base.CreateItem();
- result.Job.ID = Master?.ID ?? Guid.Empty;
- result.Job.Synchronise(Master ?? new Job());
- return result;
- }
- protected override bool CustomiseImportItem(JobITP item)
- {
- item.Job.ID = Master?.ID ?? Guid.Empty;
- item.Job.Synchronise(Master ?? new Job());
- return base.CustomiseImportItem(item);
- }
- protected override void Reload(
- Filters<JobITP> criteria, Columns<JobITP> columns, ref SortOrder<JobITP>? sort,
- CancellationToken token, Action<CoreTable?, Exception?> action)
- {
- criteria.Add(MasterDetailFilter);
- base.Reload(criteria, columns, ref sort, token, action);
- }
- protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, JobITP[] items, string name, object value)
- {
- var result = base.EditorValueChanged(editor, items, name, value);
- if (name == "ITPTypeLink.ID")
- {
- var type = typeof(IDynamicEnclosedListGrid<,>).MakeGenericType(typeof(JobITP), typeof(QAQuestion));
- var page = editor.Pages?.FirstOrDefault(x => x.GetType().GetInterface(type.Name) != null);
- if (page != null)
- {
- var template = new Client<DigitalForm>().Load(new Filter<DigitalForm>(x => x.ID).IsEqualTo(value)).FirstOrDefault();
- var load = page.GetType().GetMethod("LoadItems");
- //load.Invoke(page, new object[] { template != null ? template.Questions : null });
- }
- }
- return result;
- }
- }
|