JobITPGrid.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 JobID { get; set; }
  35. private void BuildMenu(DynamicMenuColumn column, CoreRow? row)
  36. {
  37. if (row == null) return;
  38. var item = column.AddItem("Digital Forms", PRSDesktop.Resources.kanban, null);
  39. DynamicGridUtils.PopulateFormMenu<JobITPForm, JobITP, JobITPLink>(item, row.Get<JobITP, Guid>(x => x.ID));
  40. }
  41. protected override void DoAdd()
  42. {
  43. if (JobID.Equals(Guid.Empty) || JobID.Equals(CoreUtils.FullGuid))
  44. MessageBox.Show("Please select a Job first!");
  45. else
  46. base.DoAdd();
  47. }
  48. protected override JobITP CreateItem()
  49. {
  50. var result = base.CreateItem();
  51. result.Job.ID = JobID;
  52. return result;
  53. }
  54. protected override bool CustomiseImportItem(JobITP item)
  55. {
  56. item.Job.ID = JobID;
  57. return base.CustomiseImportItem(item);
  58. }
  59. protected override void Reload(Filters<JobITP> criteria, Columns<JobITP> columns, ref SortOrder<JobITP> sort, Action<CoreTable, Exception> action)
  60. {
  61. criteria.Add(new Filter<JobITP>(x => x.Job.ID).IsEqualTo(JobID));
  62. base.Reload(criteria, columns, ref sort, action);
  63. }
  64. protected override Dictionary<string, object> EditorValueChanged(DynamicEditorForm editor, JobITP[] items, string name, object value)
  65. {
  66. var result = base.EditorValueChanged(editor, items, name, value);
  67. if (name == "ITPTypeLink.ID")
  68. {
  69. var type = typeof(IDynamicEnclosedListGrid<,>).MakeGenericType(typeof(JobITP), typeof(QAQuestion));
  70. var page = editor.Pages.FirstOrDefault(x => x.GetType().GetInterface(type.Name) != null);
  71. if (page != null)
  72. {
  73. var template = new Client<DigitalForm>().Load(new Filter<DigitalForm>(x => x.ID).IsEqualTo(value)).FirstOrDefault();
  74. var load = page.GetType().GetMethod("LoadItems");
  75. //load.Invoke(page, new object[] { template != null ? template.Questions : null });
  76. }
  77. }
  78. return result;
  79. }
  80. }