JobITPGrid.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using Comal.Classes;
  6. using InABox.Clients;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using InABox.Wpf;
  10. namespace PRSDesktop;
  11. public class JobITPGrid : DynamicDataGrid<JobITP>, IMasterDetailControl<Job,JobITP>, IDataModelSource
  12. {
  13. public Job? Master { get; set; }
  14. public Filter<JobITP> MasterDetailFilter => (Master?.ID ?? Guid.Empty) != Guid.Empty
  15. ? new Filter<JobITP>(x => x.Job.ID).IsEqualTo(Master.ID)
  16. : new Filter<JobITP>().None();
  17. public JobITPGrid()
  18. {
  19. ActionColumns.Add(new DynamicMenuColumn(BuildMenu) { Position = DynamicActionColumnPosition.Start });
  20. }
  21. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  22. {
  23. base.DoReconfigure(options);
  24. options.AddRange(
  25. DynamicGridOption.RecordCount,
  26. DynamicGridOption.SelectColumns,
  27. DynamicGridOption.AddRows,
  28. DynamicGridOption.ImportData,
  29. DynamicGridOption.FilterRows,
  30. DynamicGridOption.MultiSelect,
  31. DynamicGridOption.EditRows,
  32. DynamicGridOption.DeleteRows
  33. );
  34. }
  35. public event DataModelUpdateEvent? OnUpdateDataModel;
  36. public string SectionName => "Job ITPs";
  37. public DataModel DataModel(Selection selection)
  38. {
  39. var ids = ExtractValues(x => x.ID, selection).ToArray();
  40. return new BaseDataModel<JobITP>(new Filter<JobITP>(x => x.ID).InList(ids));
  41. }
  42. private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
  43. {
  44. if (row == null) return;
  45. var item = column.AddItem("Digital Forms", PRSDesktop.Resources.kanban, null);
  46. DynamicGridUtils.PopulateFormMenu<JobITPForm, JobITP, JobITPLink>(item, row.Get<JobITP, Guid>(x => x.ID), () => row.ToObject<JobITP>());
  47. }
  48. protected override bool CanCreateItems()
  49. {
  50. return base.CanCreateItems() && (Master?.ID ?? Guid.Empty) != Guid.Empty;
  51. }
  52. public override JobITP CreateItem()
  53. {
  54. var result = base.CreateItem();
  55. result.Job.ID = Master?.ID ?? Guid.Empty;
  56. result.Job.Synchronise(Master ?? new Job());
  57. return result;
  58. }
  59. protected override bool CustomiseImportItem(JobITP item)
  60. {
  61. item.Job.ID = Master?.ID ?? Guid.Empty;
  62. item.Job.Synchronise(Master ?? new Job());
  63. return base.CustomiseImportItem(item);
  64. }
  65. protected override void Reload(Filters<JobITP> criteria, Columns<JobITP> columns, ref SortOrder<JobITP>? sort, Action<CoreTable?, Exception?> action)
  66. {
  67. criteria.Add(MasterDetailFilter);
  68. base.Reload(criteria, columns, ref sort, action);
  69. }
  70. protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, JobITP[] items, string name, object value)
  71. {
  72. var result = base.EditorValueChanged(editor, items, name, value);
  73. if (name == "ITPTypeLink.ID")
  74. {
  75. var type = typeof(IDynamicEnclosedListGrid<,>).MakeGenericType(typeof(JobITP), typeof(QAQuestion));
  76. var page = editor.Pages?.FirstOrDefault(x => x.GetType().GetInterface(type.Name) != null);
  77. if (page != null)
  78. {
  79. var template = new Client<DigitalForm>().Load(new Filter<DigitalForm>(x => x.ID).IsEqualTo(value)).FirstOrDefault();
  80. var load = page.GetType().GetMethod("LoadItems");
  81. //load.Invoke(page, new object[] { template != null ? template.Questions : null });
  82. }
  83. }
  84. return result;
  85. }
  86. }