ProjectsPanel.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using Comal.Classes;
  6. using InABox.Configuration;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using InABox.Wpf;
  10. using PRSDesktop.Panels.Jobs;
  11. namespace PRSDesktop;
  12. public enum StockReleaseWriteDownMethod
  13. {
  14. AverageCost,
  15. Zero
  16. }
  17. public class ProjectsPanelSettings : BaseObject, IUserConfigurationSettings, IMasterDetailSettings
  18. {
  19. [NullEditor] public DynamicSplitPanelView ViewType { get; set; } = DynamicSplitPanelView.Combined;
  20. [NullEditor] public double AnchorWidth { get; set; } = 300;
  21. [NullEditor] public Guid MasterID { get; set; }
  22. }
  23. public class ProjectsSettings : BaseObject, IGlobalConfigurationSettings
  24. {
  25. private class VisiblePanelsGenerator : LookupGenerator<object>
  26. {
  27. public VisiblePanelsGenerator(object[] items) : base(items)
  28. {
  29. AddValue(typeof(JobDetails).EntityName().Split('.').Last(),"Details");
  30. AddValue(typeof(JobScopePanel).EntityName().Split('.').Last(), "Scopes");
  31. AddValue(typeof(JobDocumentSetPanel).EntityName().Split('.').Last(), "Documents");
  32. AddValue(typeof(JobStagesPanel).EntityName().Split('.').Last(), "Stages");
  33. AddValue(typeof(JobITPGrid).EntityName().Split('.').Last(), "ITPs");
  34. AddValue(typeof(JobProductMappingsGrid).EntityName().Split('.').Last(), "Product Mappings");
  35. AddValue(typeof(JobProductStylesGrid).EntityName().Split('.').Last(), "Product Styles");
  36. AddValue(typeof(JobBillOfMaterialsPanel).EntityName().Split('.').Last(), "BOM");
  37. AddValue(typeof(JobRequisitionPanel).EntityName().Split('.').Last(), "Requisitions");
  38. AddValue(typeof(JobStockGrid).EntityName().Split('.').Last(), "Stock Holdings");
  39. AddValue(typeof(JobPickingListPanel).EntityName().Split('.').Last(), "Picking Lists");
  40. AddValue(typeof(JobOrderGrid).EntityName().Split('.').Last(), "Orders");
  41. AddValue(typeof(JobDesignPanel).EntityName().Split('.').Last(), "Designs");
  42. AddValue(typeof(ManufacturingGrid).EntityName().Split('.').Last(), "Manufacturing");
  43. AddValue(typeof(ReadyToGoGrid).EntityName().Split('.').Last(), "Dispatch");
  44. AddValue(typeof(DeliveryPanel).EntityName().Split('.').Last(), "Deliveries");
  45. AddValue(typeof(DeliveredOnSiteGrid).EntityName().Split('.').Last(), "OnSite");
  46. AddValue(typeof(TaskPanel).EntityName().Split('.').Last(), "Tasks");
  47. AddValue(typeof(JobEquipmentGrid).EntityName().Split('.').Last(), "EquipmentTab");
  48. AddValue(typeof(JobEmployeePanel).EntityName().Split('.').Last(), "Employees");
  49. AddValue(typeof(JobTrackerGrid).EntityName().Split('.').Last(), "Trackers");
  50. AddValue(typeof(JobAssignmentPanel).EntityName().Split('.').Last(), "Assignments");
  51. AddValue(typeof(JobTimesheetGrid).EntityName().Split('.').Last(), "Timesheets");
  52. AddValue(typeof(JobFormGrid).EntityName().Split('.').Last(), "Forms");
  53. AddValue(typeof(InvoicePanel).EntityName().Split('.').Last(), "Invoices");
  54. AddValue(typeof(JobSpreadsheetGrid).EntityName().Split('.').Last(), "Spreadsheets");
  55. AddValue(typeof(JobSummaryPanel).EntityName().Split('.').Last(), "Summary");
  56. }
  57. }
  58. [CheckListEditor(typeof(VisiblePanelsGenerator), ColumnWidth = 200, Width = 600)]
  59. [EditorSequence(2)]
  60. public Dictionary<string, bool> VisiblePanels { get; set; }
  61. [EnumLookupEditor(typeof(StockReleaseWriteDownMethod))]
  62. [EditorSequence(2)]
  63. public StockReleaseWriteDownMethod StockRelease { get; set; }
  64. public ProjectsSettings()
  65. {
  66. VisiblePanels = new Dictionary<string, bool>();
  67. }
  68. }
  69. public class ProjectsPanel : MasterDetailPanel<Job,ProjectsGrid,ProjectsPanelSettings>
  70. {
  71. protected override string MasterCaption => "Project List";
  72. protected override string DetailCaption => "Project Details";
  73. protected override string MasterColumnsTag => "Projects";
  74. private ProjectsSettings _settings;
  75. public ProjectsPanel() : base()
  76. {
  77. _settings = new GlobalConfiguration<ProjectsSettings>().Load();
  78. }
  79. private void SetPageVisible(Type type, IMasterDetailPage? page)
  80. {
  81. if (page is null)
  82. return;
  83. page.Tab.Visibility = _settings.VisiblePanels.TryGetValue(type.EntityName().Split('.').Last(), out bool visible)
  84. ? visible
  85. ? Visibility.Visible
  86. : Visibility.Collapsed
  87. : Visibility.Visible;
  88. }
  89. private void SetStockRelease()
  90. {
  91. if (_pages.TryGetValue(typeof(JobSummaryPanel), out IMasterDetailPage? p)
  92. && p is IMasterDetailPanelPage panel
  93. && panel.Panel is JobSummaryPanel summary)
  94. summary.StockRelease = _settings.StockRelease;
  95. if (_pages.TryGetValue(typeof(JobStockGrid), out IMasterDetailPage? g)
  96. && g is JobStockGrid grid)
  97. grid.StockRelease = _settings.StockRelease;
  98. }
  99. private void SetPagesVisible()
  100. {
  101. foreach (var page in _pages.Where(x=>x.Value is not null))
  102. SetPageVisible(page.Key,page.Value);
  103. }
  104. private void DoCreatePanel<TPanel>(Func<bool> cancreate, string caption)
  105. where TPanel : class, IBasePanel, IMasterDetailControl<Job>, new()
  106. {
  107. _pages[typeof(TPanel)] = CreatePage<JobDetailPanel<TPanel>>(cancreate, caption);
  108. }
  109. private void DoCreateGrid<TGrid,TEntity>(Func<bool> cancreate, string caption)
  110. where TGrid : DynamicGrid<TEntity>, IDataModelSource, IMasterDetailControl<Job,TEntity>, new()
  111. where TEntity : BaseObject, new()
  112. {
  113. _pages[typeof(TGrid)] = CreatePage<JobDetailGrid<TGrid,TEntity>>(cancreate, caption);
  114. }
  115. private Dictionary<Type, IMasterDetailPage?> _pages = new();
  116. protected override void CreatePages()
  117. {
  118. DoCreatePanel<JobDetails>(() => true,"Details");
  119. DoCreatePanel<JobScopePanel>(Security.CanView<JobScope>, "Scopes");
  120. DoCreatePanel<JobDocumentSetPanel>(Security.CanView<JobDocumentSet>, "Documents");
  121. DoCreatePanel<JobStagesPanel>(Security.CanView<JobStage>, "Stages");
  122. DoCreateGrid<JobITPGrid, JobITP>(Security.CanView<JobITP>, "ITPs");
  123. DoCreateGrid<JobProductMappingsGrid, JobProductMapping>(Security.CanView<JobProductMapping>, "Product Mappings");
  124. DoCreateGrid<JobProductStylesGrid, JobStyle>(Security.CanView<JobStyle>, "Product Styles");
  125. DoCreatePanel<JobBillOfMaterialsPanel>(Security.CanView<JobBillOfMaterials>, "BOM");
  126. DoCreatePanel<JobRequisitionPanel>(Security.CanView<JobRequisition>, "Requisitions");
  127. DoCreatePanel<JobStockGrid>(Security.CanView<StockHolding>, "Stock Holdings");
  128. DoCreatePanel<JobPickingListPanel>(Security.CanView<Requisition>, "Picking Lists");
  129. DoCreateGrid<JobOrderGrid, PurchaseOrderItem>(Security.CanView<PurchaseOrderItem>, "Orders");
  130. DoCreatePanel<JobDesignPanel>(Security.CanView<Setout>, "Designs");
  131. DoCreateGrid<ManufacturingGrid, ManufacturingPacket>(Security.CanView<ManufacturingPacket>, "Manufacturing");
  132. DoCreateGrid<ReadyToGoGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "Dispatch");
  133. DoCreatePanel<DeliveryPanel>(Security.CanView<Delivery>, "Deliveries");
  134. DoCreateGrid<DeliveredOnSiteGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "OnSite");
  135. DoCreatePanel<TaskPanel>(Security.CanView<Kanban>, "Tasks");
  136. DoCreateGrid<JobEquipmentGrid, JobEquipment>(Security.CanView<Equipment>, "Equipment");
  137. DoCreatePanel<JobEmployeePanel>(Security.CanView<Employee>, "Employees");
  138. DoCreateGrid<JobTrackerGrid, JobTracker>(Security.CanView<GPSTracker>, "Trackers");
  139. DoCreatePanel<JobAssignmentPanel>(Security.CanView<Assignment>, "Assignments");
  140. DoCreateGrid<JobTimesheetGrid, TimeSheet>(Security.CanView<TimeSheet>, "Timesheets");
  141. DoCreateGrid<JobFormGrid, JobForm>(Security.CanView<JobForm>, "Forms");
  142. DoCreatePanel<InvoicePanel>(Security.CanView<Invoice>, "Invoices");
  143. DoCreateGrid<JobSpreadsheetGrid, JobSpreadsheet>(Security.CanView<JobSpreadsheet>, "Spreadsheets");
  144. DoCreatePanel<JobSummaryPanel>(Security.CanView<JobMaterial>, "Summary");
  145. SetPagesVisible();
  146. SetStockRelease();
  147. }
  148. protected override void AfterLoadSettings(ProjectsPanelSettings settings)
  149. {
  150. }
  151. protected override void BeforeSaveSettings(ProjectsPanelSettings settings)
  152. {
  153. }
  154. public override void CreateToolbarButtons(IPanelHost host)
  155. {
  156. host.CreateSetupAction(new PanelAction()
  157. {
  158. Caption = "Projects Settings",
  159. Image = PRSDesktop.Resources.specifications,
  160. OnExecute = action =>
  161. {
  162. var grid = new DynamicItemsListGrid<ProjectsSettings>();
  163. if (grid.EditItems(new ProjectsSettings[] { _settings }))
  164. {
  165. new GlobalConfiguration<ProjectsSettings>().Save(_settings);
  166. SetPagesVisible();
  167. SetStockRelease();
  168. }
  169. }
  170. });
  171. ProjectSetupActions.JobStatuses(host);
  172. ProjectSetupActions.DocumentMilestones(host);
  173. ProjectSetupActions.JobScopeStatuses(host);
  174. ProjectSetupActions.DrawingTemplates(host);
  175. host.CreateSetupSeparator();
  176. ProjectSetupActions.JobSpreadsheetTemplates(host);
  177. host.CreateSetupSeparator();
  178. ProjectSetupActions.SetoutGroups(host);
  179. if (SelectedPage is IMasterDetailPanelPage { Panel: not null } subpanel)
  180. subpanel.Panel.CreateToolbarButtons(host);
  181. }
  182. }