ProjectsPanel.cs 9.7 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. var isvisible = _settings.VisiblePanels.TryGetValue(type.EntityName().Split('.').Last(), out bool visible)
  84. ? visible
  85. : true;
  86. page.Tab.Visibility = isvisible
  87. ? Visibility.Visible
  88. : Visibility.Collapsed;
  89. }
  90. private void SetStockRelease()
  91. {
  92. if (_pages.TryGetValue(typeof(JobSummaryPanel), out IMasterDetailPage? p)
  93. && p is IMasterDetailPanelPage panel
  94. && panel.Panel is JobSummaryPanel summary)
  95. summary.StockRelease = _settings.StockRelease;
  96. if (_pages.TryGetValue(typeof(JobStockGrid), out IMasterDetailPage? g)
  97. && g is JobStockGrid grid)
  98. grid.StockRelease = _settings.StockRelease;
  99. }
  100. private void SetPagesVisible()
  101. {
  102. foreach (var page in _pages.Where(x=>x.Value is not null))
  103. SetPageVisible(page.Key,page.Value);
  104. }
  105. private void DoCreatePanel<TPanel>(Func<bool> cancreate, string caption)
  106. where TPanel : class, IBasePanel, IMasterDetailControl<Job>, new()
  107. {
  108. _pages[typeof(TPanel)] = CreatePage<JobDetailPanel<TPanel>>(cancreate, caption);
  109. }
  110. private void DoCreateGrid<TGrid,TEntity>(Func<bool> cancreate, string caption)
  111. where TGrid : DynamicGrid<TEntity>, IDataModelSource, IMasterDetailControl<Job,TEntity>, new()
  112. where TEntity : BaseObject, new()
  113. {
  114. _pages[typeof(TGrid)] = CreatePage<JobDetailGrid<TGrid,TEntity>>(cancreate, caption);
  115. }
  116. private Dictionary<Type, IMasterDetailPage?> _pages = new();
  117. protected override void CreatePages()
  118. {
  119. DoCreatePanel<JobDetails>(() => true,"Details");
  120. DoCreatePanel<JobScopePanel>(Security.CanView<JobScope>, "Scopes");
  121. DoCreatePanel<JobDocumentSetPanel>(Security.CanView<JobDocumentSet>, "Documents");
  122. DoCreatePanel<JobStagesPanel>(Security.CanView<JobStage>, "Stages");
  123. DoCreateGrid<JobITPGrid, JobITP>(Security.CanView<JobITP>, "ITPs");
  124. DoCreateGrid<JobProductMappingsGrid, JobProductMapping>(Security.CanView<JobProductMapping>, "Product Mappings");
  125. DoCreateGrid<JobProductStylesGrid, JobStyle>(Security.CanView<JobStyle>, "Product Styles");
  126. DoCreatePanel<JobBillOfMaterialsPanel>(Security.CanView<JobBillOfMaterials>, "BOM");
  127. DoCreatePanel<JobRequisitionPanel>(Security.CanView<JobRequisition>, "Requisitions");
  128. DoCreatePanel<JobStockGrid>(Security.CanView<StockHolding>, "Stock Holdings");
  129. DoCreatePanel<JobPickingListPanel>(Security.CanView<Requisition>, "Picking Lists");
  130. DoCreateGrid<JobOrderGrid, PurchaseOrderItem>(Security.CanView<PurchaseOrderItem>, "Orders");
  131. DoCreatePanel<JobDesignPanel>(Security.CanView<Setout>, "Designs");
  132. DoCreateGrid<ManufacturingGrid, ManufacturingPacket>(Security.CanView<ManufacturingPacket>, "Manufacturing");
  133. DoCreateGrid<ReadyToGoGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "Dispatch");
  134. DoCreatePanel<DeliveryPanel>(Security.CanView<Delivery>, "Deliveries");
  135. DoCreateGrid<DeliveredOnSiteGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "OnSite");
  136. DoCreatePanel<TaskPanel>(Security.CanView<Kanban>, "Tasks");
  137. DoCreateGrid<JobEquipmentGrid, JobEquipment>(Security.CanView<Equipment>, "Equipment");
  138. DoCreatePanel<JobEmployeePanel>(Security.CanView<Employee>, "Employees");
  139. DoCreateGrid<JobTrackerGrid, JobTracker>(Security.CanView<GPSTracker>, "Trackers");
  140. DoCreatePanel<JobAssignmentPanel>(Security.CanView<Assignment>, "Assignments");
  141. DoCreateGrid<JobTimesheetGrid, TimeSheet>(Security.CanView<TimeSheet>, "Timesheets");
  142. DoCreateGrid<JobFormGrid, JobForm>(Security.CanView<JobForm>, "Forms");
  143. DoCreatePanel<InvoicePanel>(Security.CanView<Invoice>, "Invoices");
  144. DoCreateGrid<JobSpreadsheetGrid, JobSpreadsheet>(Security.CanView<JobSpreadsheet>, "Spreadsheets");
  145. DoCreatePanel<JobSummaryPanel>(Security.CanView<JobMaterial>, "Summary");
  146. SetPagesVisible();
  147. SetStockRelease();
  148. }
  149. protected override void AfterLoadSettings(ProjectsPanelSettings settings)
  150. {
  151. }
  152. protected override void BeforeSaveSettings(ProjectsPanelSettings settings)
  153. {
  154. }
  155. public override void CreateToolbarButtons(IPanelHost host)
  156. {
  157. host.CreateSetupAction(new PanelAction()
  158. {
  159. Caption = "Projects Settings",
  160. Image = PRSDesktop.Resources.specifications,
  161. OnExecute = action =>
  162. {
  163. var grid = new DynamicItemsListGrid<ProjectsSettings>();
  164. if (grid.EditItems(new ProjectsSettings[] { _settings }))
  165. {
  166. new GlobalConfiguration<ProjectsSettings>().Save(_settings);
  167. SetPagesVisible();
  168. SetStockRelease();
  169. }
  170. }
  171. });
  172. ProjectSetupActions.JobStatuses(host);
  173. ProjectSetupActions.DocumentMilestones(host);
  174. ProjectSetupActions.JobScopeStatuses(host);
  175. ProjectSetupActions.DrawingTemplates(host);
  176. host.CreateSetupSeparator();
  177. ProjectSetupActions.JobSpreadsheetTemplates(host);
  178. host.CreateSetupSeparator();
  179. ProjectSetupActions.SetoutGroups(host);
  180. if (SelectedPage is IMasterDetailPanelPage { Panel: not null } subpanel)
  181. subpanel.Panel.CreateToolbarButtons(host);
  182. }
  183. }