ProjectsPanel.cs 9.7 KB

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