JobITPGrid.cs 3.3 KB

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