InvoicePanel.xaml.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Comal.Classes;
  9. using InABox.Clients;
  10. using InABox.Configuration;
  11. using InABox.Core;
  12. using InABox.Core.Postable;
  13. using InABox.DynamicGrid;
  14. using InABox.Wpf;
  15. namespace PRSDesktop
  16. {
  17. /// <summary>
  18. /// Interaction logic for InvoiceGrid.xaml
  19. /// </summary>
  20. public partial class InvoicePanel : UserControl, IPanel<Invoice>, IMasterDetailControl<Job>
  21. {
  22. public InvoicePanel()
  23. {
  24. InitializeComponent();
  25. Invoices.OnSelectItem += Invoices_OnSelectItem;
  26. }
  27. public Job? Master
  28. {
  29. get => Invoices.Master;
  30. set => Invoices.Master = value;
  31. }
  32. public bool IsReady { get; set; }
  33. public event DataModelUpdateEvent? OnUpdateDataModel;
  34. public Dictionary<string, object[]> Selected()
  35. {
  36. return new Dictionary<string, object[]> { { typeof(Invoice).EntityName(), Invoices.SelectedRows } };
  37. }
  38. public void CreateToolbarButtons(IPanelHost host)
  39. {
  40. AccountsSetupActions.Standard(host);
  41. PostUtils.CreateToolbarButtons(
  42. host,
  43. () => (DataModel(Selection.Selected) as IDataModel<Invoice>)!,
  44. () => Invoices.Refresh(false, true),
  45. true);
  46. }
  47. public void Setup()
  48. {
  49. Invoices.Refresh(true, false);
  50. Parts.Refresh(true, false);
  51. Time.Refresh(true, false);
  52. Lines.Refresh(true, false);
  53. }
  54. public void Shutdown(CancelEventArgs? cancel)
  55. {
  56. }
  57. public void Refresh()
  58. {
  59. Invoices.Refresh(false, true);
  60. }
  61. public string SectionName => "Invoice Grid";
  62. public DataModel DataModel(Selection selection)
  63. {
  64. var ids = Invoices.ExtractValues(x => x.ID, selection).ToArray();
  65. return new InvoiceDataModel(new Filter<Invoice>(x => x.ID).InList(ids));
  66. }
  67. public void Heartbeat(TimeSpan time)
  68. {
  69. }
  70. private void Invoices_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  71. {
  72. var _invoice = e.Rows?.FirstOrDefault()?.ToObject<Invoice>() ?? new Invoice();
  73. Parts.Invoice = _invoice;
  74. Parts.Refresh(false, true);
  75. Time.Invoice = _invoice;
  76. Time.Refresh(false, true);
  77. Lines.Invoice = _invoice;
  78. Lines.Refresh(false, true);
  79. }
  80. }
  81. }