123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- 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<object>
- {
-
- 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<string, bool> VisiblePanels { get; set; }
- [EnumLookupEditor(typeof(StockReleaseWriteDownMethod))]
- [EditorSequence(2)]
- public StockReleaseWriteDownMethod StockRelease { get; set; }
-
- public ProjectsSettings()
- {
- VisiblePanels = new Dictionary<string, bool>();
- }
- }
- public class ProjectsPanel : MasterDetailPanel<Job,ProjectsGrid,ProjectsPanelSettings>
- {
-
- 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<ProjectsSettings>().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<TPanel>(Func<bool> cancreate, string caption)
- where TPanel : class, IBasePanel, IMasterDetailControl<Job>, new()
- {
- _pages[typeof(TPanel)] = CreatePage<JobDetailPanel<TPanel>>(cancreate, caption);
- }
-
- private void DoCreateGrid<TGrid,TEntity>(Func<bool> cancreate, string caption)
- where TGrid : DynamicGrid<TEntity>, IDataModelSource, IMasterDetailControl<Job,TEntity>, new()
- where TEntity : BaseObject, new()
- {
- _pages[typeof(TGrid)] = CreatePage<JobDetailGrid<TGrid,TEntity>>(cancreate, caption);
- }
- private Dictionary<Type, IMasterDetailPage?> _pages = new();
-
- protected override void CreatePages()
- {
- DoCreatePanel<JobDetails>(() => true,"Details");
- DoCreatePanel<JobScopePanel>(Security.CanView<JobScope>, "Scopes");
- DoCreatePanel<JobDocumentSetPanel>(Security.CanView<JobDocumentSet>, "Documents");
- DoCreatePanel<JobStagesPanel>(Security.CanView<JobStage>, "Stages");
- DoCreateGrid<JobITPGrid, JobITP>(Security.CanView<JobITP>, "ITPs");
- DoCreateGrid<JobProductMappingsGrid, JobProductMapping>(Security.CanView<JobProductMapping>, "Product Mappings");
- DoCreateGrid<JobProductStylesGrid, JobStyle>(Security.CanView<JobStyle>, "Product Styles");
- DoCreatePanel<JobBillOfMaterialsPanel>(Security.CanView<JobBillOfMaterials>, "BOM");
- DoCreatePanel<JobRequisitionPanel>(Security.CanView<JobRequisition>, "Requisitions");
- DoCreatePanel<JobStockGrid>(Security.CanView<StockHolding>, "Stock Holdings");
- DoCreatePanel<JobPickingListPanel>(Security.CanView<Requisition>, "Picking Lists");
- DoCreateGrid<JobOrderGrid, PurchaseOrderItem>(Security.CanView<PurchaseOrderItem>, "Orders");
- DoCreatePanel<JobDesignPanel>(Security.CanView<Setout>, "Designs");
- DoCreateGrid<ManufacturingGrid, ManufacturingPacket>(Security.CanView<ManufacturingPacket>, "Manufacturing");
- DoCreateGrid<ReadyToGoGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "Dispatch");
- DoCreatePanel<DeliveryPanel>(Security.CanView<Delivery>, "Deliveries");
- DoCreateGrid<DeliveredOnSiteGrid, DeliveryItem>(Security.CanView<DeliveryItem>, "OnSite");
- DoCreatePanel<TaskPanel>(Security.CanView<Kanban>, "Tasks");
- DoCreateGrid<JobEquipmentGrid, JobEquipment>(Security.CanView<Equipment>, "Equipment");
- DoCreatePanel<JobEmployeePanel>(Security.CanView<Employee>, "Employees");
- DoCreateGrid<JobTrackerGrid, JobTracker>(Security.CanView<GPSTracker>, "Trackers");
- DoCreatePanel<JobAssignmentPanel>(Security.CanView<Assignment>, "Assignments");
- DoCreateGrid<JobTimesheetGrid, TimeSheet>(Security.CanView<TimeSheet>, "Timesheets");
- DoCreateGrid<JobFormGrid, JobForm>(Security.CanView<JobForm>, "Forms");
- DoCreatePanel<InvoicePanel>(Security.CanView<Invoice>, "Invoices");
- DoCreateGrid<JobSpreadsheetGrid, JobSpreadsheet>(Security.CanView<JobSpreadsheet>, "Spreadsheets");
- DoCreatePanel<JobSummaryPanel>(Security.CanView<JobMaterial>, "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<ProjectsSettings>();
- if (grid.EditItems(new ProjectsSettings[] { _settings }))
- {
- new GlobalConfiguration<ProjectsSettings>().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);
- }
- }
|