ProjectsPanel.cs 9.9 KB

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