ProjectsPanel.cs 10 KB

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