| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.Core.Postable;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- namespace PRSDesktop;
- public enum InvoicingStrategy
- {
- InvoiceOnIssue,
- InvoiceOnPurchase
- }
- public class InvoicePanelSettings : BaseObject, IGlobalConfigurationSettings
- {
- [EditorSequence(1)]
- public InvoicingStrategy InvoicingStrategy { get; set; }
- }
- public class InvoicePanelUserSettings : BaseObject, IUserConfigurationSettings
- {
- public DynamicSplitPanelView View { get; set; } = DynamicSplitPanelView.Combined;
- public double AnchorWidth { get; set; } = 500;
- }
- /// <summary>
- /// Interaction logic for InvoiceGrid.xaml
- /// </summary>
- public partial class InvoicePanel : UserControl, IPanel<Invoice>, IMasterDetailControl<Job>
- {
- private InvoicePanelSettings _settings;
- private InvoicePanelUserSettings _userSettings;
- private InvoiceableGridSettings _gridSettings;
-
- public InvoicePanel()
- {
- InitializeComponent();
- Invoices.OnSelectItem += Invoices_OnSelectItem;
- _settings = new GlobalConfiguration<InvoicePanelSettings>().Load();
- _userSettings = UserConfiguration.Load<InvoicePanelUserSettings>();
- _gridSettings = UserConfiguration.Load<InvoiceableGridSettings>();
- Time.InvoiceGridSettings = _gridSettings;
- Parts.InvoiceGridSettings = _gridSettings;
- Bills.InvoiceGridSettings = _gridSettings;
- _gridSettings.PropertyChanged += GridSettings_PropertyChanged;
- SplitPanel.View = _userSettings.View;
- SplitPanel.AnchorWidth = _userSettings.AnchorWidth;
- }
- private void GridSettings_PropertyChanged(object? sender, PropertyChangedEventArgs e)
- {
- UserConfiguration.Save(_gridSettings);
- }
- public Job? Master
- {
- get => Invoices.Master;
- set
- {
- Invoices.Master = value;
- Lines.Job = value;
- }
- }
-
- public bool IsReady { get; set; }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public Dictionary<string, object[]> Selected()
- {
- return new Dictionary<string, object[]> { { typeof(Invoice).EntityName(), Invoices.SelectedRows } };
- }
- public void CreateToolbarButtons(IPanelHost host)
- {
- AccountsSetupActions.Standard(host);
- host.CreateSetupSeparator();
-
- host.CreateSetupAction(new PanelAction()
- {
- Caption = "Invoices Settings",
- Image = PRSDesktop.Resources.edit,
- OnExecute = action =>
- {
- if (DynamicGridUtils.EditObject(_settings))
- {
- new GlobalConfiguration<InvoicePanelSettings>().Save(_settings);
- Parts.InvoiceSettings = _settings;
- }
- }
- });
- PostUtils.CreateToolbarButtons(
- host,
- () => (DataModel(Selection.Selected) as IDataModel<Invoice>)!,
- () => Invoices.Refresh(false, true),
- true);
- }
- public void Setup()
- {
- Invoices.Refresh(true, false);
- Parts.Refresh(true, false);
- Time.Refresh(true, false);
- Lines.Refresh(true, false);
- Bills.Refresh(true, false);
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- }
- public void Refresh()
- {
- Invoices.Refresh(false, true);
- }
- public string SectionName => "Invoice Grid";
- public DataModel DataModel(Selection selection)
- {
- var ids = Invoices.ExtractValues(x => x.ID, selection).ToArray();
- return new InvoiceDataModel(Filter<Invoice>.Where(x => x.ID).InList(ids));
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- private void Invoices_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- var _invoice = e.Rows?.FirstOrDefault()?.ToObject<Invoice>();
-
- Parts.Invoice = _invoice;
- Parts.Refresh(false, true);
-
- Time.Invoice = _invoice;
- Time.Refresh(false, true);
- Lines.Invoice = _invoice;
- Lines.Refresh(false, true);
- Bills.Invoice = _invoice;
- Bills.Refresh(false, true);
- }
- private void DynamicSplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
- {
- _userSettings.View = SplitPanel.View;
- _userSettings.AnchorWidth = SplitPanel.AnchorWidth;
- new UserConfiguration<InvoicePanelUserSettings>().Save(_userSettings);
- }
- }
|