JobITPGrid.cs 3.3 KB

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