using Comal.Classes; using InABox.Configuration; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Windows.Controls; using System.Windows.Media; namespace PRSDesktop { public class JobRequisitionPanelSettings : BaseObject, IGlobalConfigurationSettings { [Caption("Default Style for Company", IncludePath = false)] public ProductStyleLink ProductStyle { get; set; } public JobRequisitionPanelSettings() { ProductStyle = new ProductStyleLink(); } } /// /// Interaction logic for JobRequisitionsPanel.xaml /// public partial class JobRequisitionsPanel : UserControl, IPanel { Guid JobID = Guid.Empty; private JobRequisitionPanelSettings _settings = null; public JobRequisitionsPanel() { InitializeComponent(); } enum PanelMode { Reserve, Purchase } private PanelMode mode; private PanelMode Mode { get => mode; set { mode = value; SetPanelDetail(); } } private void SetPanelDetail() { if (Mode == PanelMode.Reserve) { reserveCol.Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star); purchaseCol.Width = new System.Windows.GridLength(0); JobRequiItems.Options.Remove(DynamicGridOption.MultiSelect); reserveBtn.Background = new SolidColorBrush(Colors.LightGray); purchaseBtn.Background = new SolidColorBrush(Colors.WhiteSmoke); } else if (Mode == PanelMode.Purchase) { reserveCol.Width = new System.Windows.GridLength(0); purchaseCol.Width = new System.Windows.GridLength(1, System.Windows.GridUnitType.Star); JobRequiItems.Options.Add(DynamicGridOption.MultiSelect); reserveBtn.Background = new SolidColorBrush(Colors.WhiteSmoke); purchaseBtn.Background = new SolidColorBrush(Colors.LightGray); } } public bool IsReady { get; set; } public string SectionName => "Job Requisitions"; public event DataModelUpdateEvent? OnUpdateDataModel; public void CreateToolbarButtons(IPanelHost host) { host.CreateSetupAction(new PanelAction() { Caption = "Product Configuration Settings", Image = PRSDesktop.Resources.specifications, OnExecute = ConfigSettingsClick }); } private void ConfigSettingsClick(PanelAction obj) { var pages = new DynamicEditorPages(); var buttons = new DynamicEditorButtons(); buttons.Add( "", PRSDesktop.Resources.help.AsBitmapImage(), _settings, (f, i) => { Process.Start(new ProcessStartInfo("https://prsdigital.com.au/wiki/index.php/" + typeof(Equipment).Name.SplitCamelCase().Replace(" ", "_")) { UseShellExecute = true }); } ); var propertyEditor = new DynamicEditorForm(typeof(JobRequisitionPanelSettings), pages, buttons); propertyEditor.OnDefineLookups += sender => { var editor = sender.EditorDefinition as ILookupEditor; var colname = sender.ColumnName; var values = editor.Values(colname, new[] { _settings }); sender.LoadLookups(values); }; propertyEditor.OnEditorValueChanged += (sender, name, value) => { CoreUtils.SetPropertyValue(_settings, name, value); return new Dictionary(); }; propertyEditor.Items = new BaseObject[] { _settings }; if (propertyEditor.ShowDialog() == true) { new GlobalConfiguration().Save(_settings); holdings.CompanyDefaultStyle = _settings.ProductStyle; } } public DataModel DataModel(Selection selection) { var ids = JobRequiItems.ExtractValues(x => x.ID, selection).ToArray(); return new BaseDataModel(new Filter(x => x.ID).InList(ids)); } public void Heartbeat(TimeSpan time) { } public void Refresh() { JobRequiItems.Refresh(false, true); } public Dictionary Selected() { var result = new Dictionary(); result[typeof(JobRequisitionItem).EntityName()] = JobRequiItems.SelectedRows; return result; } public void Setup() { Mode = PanelMode.Reserve; SetupJobRequiItemGrids(); _settings = new GlobalConfiguration().Load(); holdings.CompanyDefaultStyle = _settings.ProductStyle; holdings.OnHoldingsReviewRefresh += Holdings_OnHoldingsReviewRefresh; } private void Holdings_OnHoldingsReviewRefresh() { Refresh(); RefreshJobRequiGrids(); } private void RefreshJobRequiGrids() { JobRequiItems.bRefreshing = false; JobRequiItems.Refresh(false, true); } private void SetupJobRequiItemGrids() { JobRequiItems.OnGridRefresh += JobRequiItems_OnGridRefresh; JobRequiItems.OnJobRequiItemSelected += OnJobRequiItemSelected; JobRequiItems.Refresh(true, true); } private void OnJobRequiItemSelected(CoreRow[] rows) { holdings.Item = rows[0].ToObject(); purchasing.JobRequiItems = CreateList(rows); } private List CreateList(CoreRow[] rows) { List list = new List(); foreach (var row in rows) list.Add(row.ToObject()); return list; } private void JobRequiItems_OnGridRefresh() { RefreshJobRequiGrids(); } public void Shutdown() { } private void ReserveStock_Clicked(object sender, System.Windows.RoutedEventArgs e) { Mode = PanelMode.Reserve; } private void PurchaseStock_Clicked(object sender, System.Windows.RoutedEventArgs e) { Mode = PanelMode.Purchase; } } }