AssignmentGrid.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Comal.Classes;
  5. using InABox.Clients;
  6. using InABox.Core;
  7. using InABox.DynamicGrid;
  8. namespace PRSDesktop
  9. {
  10. public class AssignmentGrid : DynamicDataGrid<Assignment>
  11. {
  12. public AssignmentGrid()
  13. {
  14. HiddenColumns.Add(x => x.JobLink.Deleted);
  15. }
  16. protected override Dictionary<string, object?> EditorValueChanged(IDynamicEditorForm editor, Assignment[] items, string name, object value)
  17. {
  18. var result = base.EditorValueChanged(editor, items, name, value);
  19. if (name.Equals("EmployeeLink.ID"))
  20. {
  21. if (editor.FindEditor("ActivityLink.ID") is ILookupEditorControl activity)
  22. DefineLookups(activity, items);
  23. }
  24. else if (name.Equals("JobLink.ID"))
  25. {
  26. var itp = editor.FindEditor("ITP.ID") as ILookupEditorControl;
  27. if (itp != null)
  28. DefineLookups(itp, items);
  29. // false here because a job has a defaultscope
  30. // and we need to load the lookups before we set the default value
  31. var scope = editor.FindEditor("JobScope.ID") as ILookupEditorControl;
  32. if (scope != null)
  33. DefineLookups(scope,items,false);
  34. }
  35. else if (name.Equals("Task.ID"))
  36. {
  37. var jobid = new Client<Kanban>().Query(
  38. new Filter<Kanban>(x => x.ID).IsEqualTo(value),
  39. Columns.None<Kanban>().Add(x => x.JobLink.ID)
  40. ).Rows.FirstOrDefault()?.Get<Kanban, Guid>(x => x.JobLink.ID);
  41. DynamicGridUtils.UpdateEditorValue(items, "JobLink.ID", jobid.HasValue ? jobid.Value : Guid.Empty);
  42. DynamicGridUtils.UpdateEditorValue(items, "ITP.ID", Guid.Empty);
  43. var itp = editor.FindEditor("ITP.ID") as ILookupEditorControl;
  44. if (itp != null)
  45. DefineLookups(itp, items);
  46. }
  47. return result;
  48. }
  49. protected override void AfterLoad(IDynamicEditorForm editor, Assignment[] items)
  50. {
  51. base.AfterLoad(editor, items);
  52. var first = items.FirstOrDefault();
  53. if (first?.ID == Guid.Empty)
  54. ReloadForms<Assignment, AssignmentForm, ActivityForm>(editor, first, x => x.Activity.ID, first.ActivityLink.ID);
  55. }
  56. }
  57. }