using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; using System.Windows; using Comal.Classes; using InABox.Clients; using InABox.Configuration; using InABox.Core; using InABox.DynamicGrid; using InABox.Wpf; using PRSDesktop.Panels.Jobs; namespace PRSDesktop; public enum StockReleaseWriteDownMethod { AverageCost, Zero } public class ProjectsPanelSettings : BaseObject, IUserConfigurationSettings, IMasterDetailSettings { [NullEditor] public DynamicSplitPanelView ViewType { get; set; } = DynamicSplitPanelView.Combined; [NullEditor] public double AnchorWidth { get; set; } = 300; [NullEditor] public Guid MasterID { get; set; } } public class ProjectsSettings : BaseObject, IGlobalConfigurationSettings { private class VisiblePanelsGenerator : LookupGenerator { public VisiblePanelsGenerator(object[] items) : base(items) { AddValue(typeof(JobDetails).EntityName().Split('.').Last(),"Details"); AddValue(typeof(JobScopePanel).EntityName().Split('.').Last(), "Scopes"); AddValue(typeof(JobDocumentSetPanel).EntityName().Split('.').Last(), "Documents"); AddValue(typeof(JobStagesPanel).EntityName().Split('.').Last(), "Stages"); AddValue(typeof(JobITPGrid).EntityName().Split('.').Last(), "ITPs"); AddValue(typeof(JobProductMappingsGrid).EntityName().Split('.').Last(), "Product Mappings"); AddValue(typeof(JobProductStylesGrid).EntityName().Split('.').Last(), "Product Styles"); AddValue(typeof(JobBillOfMaterialsPanel).EntityName().Split('.').Last(), "BOM"); AddValue(typeof(JobRequisitionPanel).EntityName().Split('.').Last(), "Requisitions"); AddValue(typeof(JobStockGrid).EntityName().Split('.').Last(), "Stock Holdings"); AddValue(typeof(JobPickingListPanel).EntityName().Split('.').Last(), "Picking Lists"); AddValue(typeof(JobOrderGrid).EntityName().Split('.').Last(), "Orders"); AddValue(typeof(JobDesignPanel).EntityName().Split('.').Last(), "Designs"); AddValue(typeof(ManufacturingGrid).EntityName().Split('.').Last(), "Manufacturing"); AddValue(typeof(ReadyToGoGrid).EntityName().Split('.').Last(), "Dispatch"); AddValue(typeof(DeliveryPanel).EntityName().Split('.').Last(), "Deliveries"); AddValue(typeof(DeliveredOnSiteGrid).EntityName().Split('.').Last(), "OnSite"); AddValue(typeof(TaskPanel).EntityName().Split('.').Last(), "Tasks"); AddValue(typeof(JobEquipmentGrid).EntityName().Split('.').Last(), "EquipmentTab"); AddValue(typeof(JobEmployeePanel).EntityName().Split('.').Last(), "Employees"); AddValue(typeof(JobTrackerGrid).EntityName().Split('.').Last(), "Trackers"); AddValue(typeof(JobAssignmentPanel).EntityName().Split('.').Last(), "Assignments"); AddValue(typeof(JobTimesheetGrid).EntityName().Split('.').Last(), "Timesheets"); AddValue(typeof(JobFormGrid).EntityName().Split('.').Last(), "Forms"); AddValue(typeof(InvoicePanel).EntityName().Split('.').Last(), "Invoices"); AddValue(typeof(JobSpreadsheetGrid).EntityName().Split('.').Last(), "Spreadsheets"); AddValue(typeof(JobSummaryPanel).EntityName().Split('.').Last(), "Summary"); } } [CheckListEditor(typeof(VisiblePanelsGenerator), ColumnWidth = 200, Width = 600)] [EditorSequence(2)] public Dictionary VisiblePanels { get; set; } [EnumLookupEditor(typeof(StockReleaseWriteDownMethod))] [EditorSequence(2)] public StockReleaseWriteDownMethod StockRelease { get; set; } public ProjectsSettings() { VisiblePanels = new Dictionary(); } } public class ProjectsPanel : MasterDetailPanel { protected override string MasterCaption => "Project List"; protected override string DetailCaption => "Project Details"; protected override string MasterColumnsTag => "Projects"; private ProjectsSettings _settings; public ProjectsPanel() : base() { _settings = new GlobalConfiguration().Load(); } private void SetPageVisible(Type type, IMasterDetailPage? page) { if (page is null) return; page.Tab.Visibility = _settings.VisiblePanels.TryGetValue(type.EntityName().Split('.').Last(), out bool visible) ? visible ? Visibility.Visible : Visibility.Collapsed : Visibility.Visible; } private void SetStockRelease() { if (_pages.TryGetValue(typeof(JobSummaryPanel), out IMasterDetailPage? p) && p is IMasterDetailPanelPage panel && panel.Panel is JobSummaryPanel summary) summary.StockRelease = _settings.StockRelease; if (_pages.TryGetValue(typeof(JobStockGrid), out IMasterDetailPage? g) && g is JobStockGrid grid) grid.StockRelease = _settings.StockRelease; } private void SetPagesVisible() { foreach (var page in _pages.Where(x=>x.Value is not null)) SetPageVisible(page.Key,page.Value); } private void DoCreatePanel(Func cancreate, string caption) where TPanel : class, IBasePanel, IMasterDetailControl, new() { _pages[typeof(TPanel)] = CreatePage>(cancreate, caption); } private void DoCreateGrid(Func cancreate, string caption) where TGrid : DynamicGrid, IDataModelSource, IMasterDetailControl, new() where TEntity : BaseObject, new() { _pages[typeof(TGrid)] = CreatePage>(cancreate, caption); } private Dictionary _pages = new(); protected override void CreatePages() { DoCreatePanel(() => true,"Details"); DoCreatePanel(Security.CanView, "Scopes"); DoCreatePanel(Security.CanView, "Documents"); DoCreatePanel(Security.CanView, "Stages"); DoCreateGrid(Security.CanView, "ITPs"); DoCreateGrid(Security.CanView, "Product Mappings"); DoCreateGrid(Security.CanView, "Product Styles"); DoCreatePanel(Security.CanView, "BOM"); DoCreatePanel(Security.CanView, "Requisitions"); DoCreatePanel(Security.CanView, "Stock Holdings"); DoCreatePanel(Security.CanView, "Picking Lists"); DoCreateGrid(Security.CanView, "Orders"); DoCreatePanel(Security.CanView, "Designs"); DoCreateGrid(Security.CanView, "Manufacturing"); DoCreateGrid(Security.CanView, "Dispatch"); DoCreatePanel(Security.CanView, "Deliveries"); DoCreateGrid(Security.CanView, "OnSite"); DoCreatePanel(Security.CanView, "Tasks"); DoCreateGrid(Security.CanView, "Equipment"); DoCreatePanel(Security.CanView, "Employees"); DoCreateGrid(Security.CanView, "Trackers"); DoCreatePanel(Security.CanView, "Assignments"); DoCreateGrid(Security.CanView, "Timesheets"); DoCreateGrid(Security.CanView, "Forms"); DoCreatePanel(Security.CanView, "Invoices"); DoCreateGrid(Security.CanView, "Spreadsheets"); DoCreatePanel(Security.CanView, "Summary"); SetPagesVisible(); SetStockRelease(); } protected override void AfterLoadSettings(ProjectsPanelSettings settings) { } protected override void BeforeSaveSettings(ProjectsPanelSettings settings) { } public override void CreateToolbarButtons(IPanelHost host) { host.CreateSetupAction(new PanelAction() { Caption = "Projects Settings", Image = PRSDesktop.Resources.specifications, OnExecute = action => { var grid = new DynamicItemsListGrid(); if (grid.EditItems(new ProjectsSettings[] { _settings })) { new GlobalConfiguration().Save(_settings); SetPagesVisible(); SetStockRelease(); } } }); ProjectSetupActions.JobStatuses(host); ProjectSetupActions.DocumentMilestones(host); ProjectSetupActions.JobScopeStatuses(host); ProjectSetupActions.JobRetentionTypes(host); ProjectSetupActions.DrawingTemplates(host); SystemSetupActions.ERPStatuses(host); host.CreateSetupSeparator(); ProjectSetupActions.JobSpreadsheetTemplates(host); host.CreateSetupSeparator(); ProjectSetupActions.SetoutGroups(host); base.CreateToolbarButtons(host); } }