123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- using InABox.Wpf;
- namespace PRSDesktop;
- public class SupplierBillPanelSettings : IUserConfigurationSettings
- {
- public SupplierBillPanelSettings()
- {
- AnchorWidth = 500F;
- ViewType = ScreenViewType.Combined;
- }
- public ScreenViewType ViewType { get; set; }
- public double AnchorWidth { get; set; }
- }
- public class SupplierBillPanelProperties : BaseObject, IGlobalConfigurationSettings
- {
- [IntegerEditor]
- [EditorSequence(1)]
- public int CurrencyDecimalPlaces { get; set; } = 2;
-
- [EditorSequence(2)]
- [CheckBoxEditor]
- public bool AllowBlankBillNumbers { get; set; }
- }
- public partial class SupplierBillPanel : UserControl, IPanel<Bill>, IPropertiesPanel<SupplierBillPanelProperties, CanConfigureAccountsPanels>
- {
- private SupplierBillPanelSettings settings;
- public SupplierBillPanel()
- {
- InitializeComponent();
- }
-
- public bool IsReady { get; set; }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public Dictionary<string, object[]> Selected()
- {
- return new Dictionary<string, object[]> { { typeof(Bill).EntityName(), Bills.SelectedRows } };
- }
- public void CreateToolbarButtons(IPanelHost host)
- {
- AccountsSetupActions.Standard(host);
- PostUtils.CreateToolbarButtons(host,
- () => (DataModel(Selection.Selected) as IDataModel<Bill>)!,
- () => Bills.Refresh(false, true),
- true);
- }
- public string SectionName => "Supplier Bills";
- public SupplierBillPanelProperties Properties { get; set; }
- public DataModel DataModel(Selection selection)
- {
- var ids = Bills.ExtractValues(x => x.ID, selection).ToArray();
- return new BaseDataModel<Bill>(new Filter<Bill>(x => x.ID).InList(ids));
- }
- public void Refresh()
- {
- if (CheckSaved())
- {
- Bills.Refresh(false, true);
- SetChanged(false);
- }
- }
- public void Setup()
- {
- settings = new UserConfiguration<SupplierBillPanelSettings>().Load();
- SplitPanel.View = settings.ViewType == ScreenViewType.Register ? DynamicSplitPanelView.Master :
- settings.ViewType == ScreenViewType.Details ? DynamicSplitPanelView.Detail : DynamicSplitPanelView.Combined;
- SplitPanel.AnchorWidth = settings.AnchorWidth;
- Bill.SetLayoutType<SupplierBillEditLayout>();
- Bills.Refresh(true, false);
- }
-
- private void CheckSaved(CancelEventArgs cancel)
- {
- if (!bChanged)
- {
- return;
- }
- var result = MessageBox.Show("You have an unsaved Supplier Bill; do you wish to save these changes?", "Save Changes?", MessageBoxButton.YesNoCancel);
- if (result == MessageBoxResult.Yes)
- {
- Bill.SaveItem(cancel);
- if (!cancel.Cancel)
- {
- MessageBox.Show("Purchase Order saved.");
- }
- }
- else if (result == MessageBoxResult.Cancel)
- {
- cancel.Cancel = true;
- }
- }
- private bool CheckSaved()
- {
- var cancel = new CancelEventArgs();
- CheckSaved(cancel);
- return !cancel.Cancel;
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- if(cancel is not null)
- {
- CheckSaved(cancel);
- }
- }
- public void Heartbeat(TimeSpan time)
- {
- }
-
- public Dictionary<Type, CoreTable> DataEnvironment()
- {
- return new Dictionary<Type, CoreTable>
- {
- { typeof(Bill), Bills.Data }
- };
- }
- private Bill[]? _bills = null;
- private CoreRow[]? _editRows = null;
-
- private void Bills_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
- {
- if(SplitPanel.View != DynamicSplitPanelView.Master)
- {
- ReloadBills();
- }
- }
- private void ReloadBills()
- {
- if (Bills.SelectedRows.Length != 0)
- {
- _editRows = Bills.SelectedRows;
- _bills = Bills.LoadBills(_editRows);
- Bills.InitialiseEditorForm(Bill, _bills, null, true);
- Bill.Visibility = Visibility.Visible;
- }
- else
- {
- _bills = null;
- _editRows = null;
- Bill.Visibility = Visibility.Hidden;
- }
- }
- private void Bill_OnOnOK()
- {
- using (new WaitCursor())
- {
- var cancel = new System.ComponentModel.CancelEventArgs();
- Bill.SaveItem(cancel);
- if (!cancel.Cancel)
- {
- if(_editRows is not null && _bills is not null)
- {
- for(var i = 0; i < _editRows.Length; ++i)
- {
- Bills.UpdateRow(_editRows[i], _bills[i]);
- Bills.InvalidateRow(_editRows[i]);
- }
- }
- ReloadBills();
- SetChanged(false);
- }
- }
- }
- private void Bill_OnOnCancel()
- {
- ReloadBills();
- SetChanged(false);
- }
- private void SetChanged(bool changed)
- {
- bChanged = changed;
- Bills.IsEnabled = !changed;
- Bill.HideButtons = !changed;
- }
- private bool bChanged = false;
- private void Bill_OnOnChanged(object? sender, EventArgs e)
- {
- SetChanged(true);
- }
- private void SplitPanel_OnChanged(object sender, DynamicSplitPanelSettings e)
- {
- settings.ViewType = SplitPanel.View == DynamicSplitPanelView.Master ? ScreenViewType.Register :
- SplitPanel.View == DynamicSplitPanelView.Detail ? ScreenViewType.Details : ScreenViewType.Combined;
- settings.AnchorWidth = SplitPanel.AnchorWidth;
- new UserConfiguration<SupplierBillPanelSettings>().Save(settings);
- }
- }
|