123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows.Controls;
- using Comal.Classes;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.WPF;
- namespace PRSDesktop;
- public class CustomerReceipts : DynamicDataGrid<Receipt>, IPanel<Receipt>
- {
- private bool Outstanding = true;
- public CustomerReceipts()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect);
- AddButton("Show All", PRSDesktop.Resources.view.AsBitmapImage(), ToggleView);
- OnBeforeSave += BeforeSave;
- }
- public bool IsReady { get; set; }
- public event DataModelUpdateEvent OnUpdateDataModel;
- public void CreateToolbarButtons(IPanelHost 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 bool Focus()
- {
- return true;
- }
- public void Refresh()
- {
- Refresh(false, true);
- }
- public void Setup()
- {
- Refresh(true, false);
- }
- public void Shutdown()
- {
- }
- public void Heartbeat(TimeSpan time)
- {
- }
- private void BeforeSave(DynamicEditorForm editor, Receipt[] items)
- {
- if (items == null || items.Length != 1)
- return;
- if (!string.IsNullOrWhiteSpace(items[0].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();
- items[0].Notes = string.Format("Invoice{0} {1}", numbers.Length > 1 ? "s" : "", string.Join(", ", numbers));
- }
- }
- private bool ToggleView(Button sender, CoreRow[] rows)
- {
- Outstanding = !Outstanding;
- UpdateButton(sender, PRSDesktop.Resources.view.AsBitmapImage(), Outstanding ? "Show All" : "Outstanding");
- return true;
- }
- protected override void Reload(Filters<Receipt> criteria, Columns<Receipt> columns, ref SortOrder<Receipt> sort,
- Action<CoreTable, Exception> action)
- {
- if (Outstanding)
- criteria.Add(new Filter<Receipt>(x => x.Reconciled).IsEqualTo(DateTime.MinValue));
- base.Reload(criteria, columns, ref sort, action);
- }
- }
|