123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop;
- public class ReceiptGridSettings : IUserConfigurationSettings
- {
- [Obsolete]
- private CoreFilterDefinition? _currentFilter;
- [Obsolete]
- public CoreFilterDefinition? CurrentFilter
- {
- get => _currentFilter;
- set
- {
- if (value is not null)
- {
- Filters = new DynamicGridSelectedFilterSettings(new List<CoreFilterDefinition> { value }, false, null);
- }
- }
- }
- public DynamicGridSelectedFilterSettings Filters { get; set; } = new();
- }
- public class CustomerReceipts : DynamicDataGrid<Receipt>, IPanel<Receipt>
- {
- //private bool Outstanding = true;
- private ReceiptGridSettings _settings;
- public CustomerReceipts()
- {
- //AddButton("Show All", PRSDesktop.Resources.view.AsBitmapImage(), ToggleView);
- OnBeforeSave += BeforeSave;
- }
- protected override void DoReconfigure(FluentList<DynamicGridOption> options)
- {
- base.DoReconfigure(options);
- options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect);
- }
- protected override void Init()
- {
- base.Init();
-
- _settings = new UserConfiguration<ReceiptGridSettings>().Load();
- FilterComponent.SetSettings(_settings.Filters, refresh: false);
- FilterComponent.OnFiltersSelected += FilterComponent_OnFilterSelected;
- }
- private void FilterComponent_OnFilterSelected(DynamicGridSelectedFilterSettings settings)
- {
- _settings.Filters = settings;
- new UserConfiguration<ReceiptGridSettings>().Save(_settings);
- }
- public bool IsReady { get; set; }
- public event DataModelUpdateEvent? OnUpdateDataModel;
- public void CreateToolbarButtons(IPanelHost host)
- {
- AccountsSetupActions.Standard(host);
- //
- }
- public Dictionary<string, object[]> Selected()
- {
- return new Dictionary<string, object[]> { { typeof(Receipt).EntityName(), SelectedRows } };
- }
- public string SectionName => "Customer Receipts";
- public DataModel DataModel(Selection selection)
- {
- var ids = ExtractValues(x => x.ID, selection).ToArray();
- return new BaseDataModel<Receipt>(new Filter<Receipt>(x => x.ID).InList(ids));
- }
- public void Refresh()
- {
- Refresh(false, true);
- }
- public void Setup()
- {
- Refresh(true, false);
- }
- public void Shutdown(CancelEventArgs? cancel)
- {
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- private void BeforeSave(IDynamicEditorForm editor, BaseObject[] items)
- {
- var receipt = items?.FirstOrDefault() as Receipt;
- if (receipt == null)
- return;
-
- if (!string.IsNullOrWhiteSpace(receipt.Notes))
- return;
- var page =
- editor.Pages.FirstOrDefault(x => x is DynamicManyToManyGrid<InvoiceReceipt, Receipt>) as DynamicManyToManyGrid<InvoiceReceipt, Receipt>;
- if (page != null)
- {
- var numbers = page.Data.Rows.Select(r => r.Get<InvoiceReceipt, int>(c => c.InvoiceLink.Number)).ToArray();
- receipt.Notes = string.Format("Invoice{0} {1}", numbers.Length > 1 ? "s" : "", string.Join(", ", numbers));
- }
- }
- }
|