InvoicePanel.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using com.sun.corba.se.impl.protocol.giopmsgheaders;
  9. using com.sun.security.ntlm;
  10. using Comal.Classes;
  11. using InABox.Clients;
  12. using InABox.Configuration;
  13. using InABox.Core;
  14. using InABox.Core.Postable;
  15. using InABox.DynamicGrid;
  16. namespace PRSDesktop
  17. {
  18. // public class InvoicePanelSettings : IUserConfigurationSettings
  19. // {
  20. // public bool IncludePaidInvoices { get; set; }
  21. // }
  22. /// <summary>
  23. /// Interaction logic for InvoiceGrid.xaml
  24. /// </summary>
  25. public partial class InvoicePanel : UserControl, IPanel<Invoice>, IJobControl
  26. {
  27. //private InvoicePanelSettings _settings;
  28. public InvoicePanel()
  29. {
  30. //_settings = new UserConfiguration<InvoicePanelSettings>().Load();
  31. InitializeComponent();
  32. //Invoices.IncludePaidInvoices = _settings.IncludePaidInvoices;
  33. //_includePaid.IsChecked = _settings.IncludePaidInvoices;
  34. Invoices.OnSelectItem += Invoices_OnSelectItem;
  35. }
  36. public Job Job
  37. {
  38. get => Invoices.Job;
  39. set => Invoices.Job = value;
  40. }
  41. public JobPanelSettings Settings { get; set; }
  42. public bool IsReady { get; set; }
  43. public event DataModelUpdateEvent? OnUpdateDataModel;
  44. public Dictionary<string, object[]> Selected()
  45. {
  46. return new Dictionary<string, object[]> { { typeof(Invoice).EntityName(), Invoices.SelectedRows } };
  47. }
  48. public void CreateToolbarButtons(IPanelHost host)
  49. {
  50. PostUtils.CreateToolbarButtons(
  51. host,
  52. () => (DataModel(Selection.Selected) as IDataModel<Invoice>)!,
  53. () => Invoices.Refresh(false, true),
  54. true);
  55. }
  56. public void Setup()
  57. {
  58. Invoices.Refresh(true, false);
  59. Parts.Refresh(true, false);
  60. Time.Refresh(true, false);
  61. Lines.Refresh(true, false);
  62. }
  63. public void Shutdown(CancelEventArgs? cancel)
  64. {
  65. }
  66. public void Refresh()
  67. {
  68. Invoices.Refresh(false, true);
  69. }
  70. public string SectionName => "Invoice Grid";
  71. public DataModel DataModel(Selection selection)
  72. {
  73. var ids = Invoices.ExtractValues(x => x.ID, selection).ToArray();
  74. return new InvoiceDataModel(new Filter<Invoice>(x => x.ID).InList(ids));
  75. }
  76. public void Heartbeat(TimeSpan time)
  77. {
  78. }
  79. private void Invoices_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  80. {
  81. if (!IsReady)
  82. return;
  83. var _invoice = e.Rows?.FirstOrDefault()?.ToObject<Invoice>() ?? new Invoice();
  84. Parts.Invoice = _invoice;
  85. Parts.Refresh(false, true);
  86. Time.Invoice = _invoice;
  87. Time.Refresh(false, true);
  88. Lines.Invoice = _invoice;
  89. Lines.Refresh(false, true);
  90. }
  91. }
  92. }