InvoicePanel.xaml.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows.Controls;
  5. using Comal.Classes;
  6. using InABox.Core;
  7. using InABox.DynamicGrid;
  8. namespace PRSDesktop
  9. {
  10. /// <summary>
  11. /// Interaction logic for InvoiceGrid.xaml
  12. /// </summary>
  13. public partial class InvoicePanel : UserControl, IPanel<Invoice>, IJobControl
  14. {
  15. public InvoicePanel()
  16. {
  17. InitializeComponent();
  18. Invoices.OnSelectItem += Invoices_OnSelectItem;
  19. }
  20. public Guid ParentID
  21. {
  22. get => Invoices.JobID;
  23. set
  24. {
  25. Invoices.JobID = value;
  26. Parts.JobID = value;
  27. Time.JobID = value;
  28. }
  29. }
  30. public JobPanelSettings Settings { get; set; }
  31. public bool IsReady { get; set; }
  32. public event DataModelUpdateEvent OnUpdateDataModel;
  33. public Dictionary<string, object[]> Selected()
  34. {
  35. return new Dictionary<string, object[]> { { typeof(Invoice).EntityName(), Invoices.SelectedRows } };
  36. }
  37. public void CreateToolbarButtons(IPanelHost host)
  38. {
  39. }
  40. public void Setup()
  41. {
  42. Invoices.Refresh(true, false);
  43. Parts.Refresh(true, false);
  44. Time.Refresh(true, false);
  45. Lines.Refresh(true, false);
  46. }
  47. public void Shutdown()
  48. {
  49. }
  50. public void Refresh()
  51. {
  52. Invoices.Refresh(false, true);
  53. var bData = Invoices.SelectedRows.Any();
  54. Parts.Refresh(false, bData);
  55. Time.Refresh(false, bData);
  56. Lines.Refresh(false, bData);
  57. }
  58. public string SectionName => "Invoice Grid";
  59. public DataModel DataModel(Selection selection)
  60. {
  61. var ids = Invoices.ExtractValues(x => x.ID, selection).ToArray();
  62. return new InvoiceDataModel(new Filter<Invoice>(x => x.ID).InList(ids));
  63. }
  64. public void Heartbeat(TimeSpan time)
  65. {
  66. }
  67. private void Invoices_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  68. {
  69. if (!IsReady)
  70. return;
  71. var row = e.Rows?.FirstOrDefault();
  72. var jobid = row != null ? row.Get<Invoice, Guid>(x => x.JobLink.ID) : CoreUtils.FullGuid;
  73. var invoiceid = row != null ? row.Get<Invoice, Guid>(x => x.ID) : CoreUtils.FullGuid;
  74. Parts.JobID = jobid;
  75. Parts.InvoiceID = invoiceid;
  76. Parts.Refresh(false, true);
  77. Time.JobID = jobid;
  78. Time.InvoiceID = invoiceid;
  79. Time.Refresh(false, true);
  80. Lines.InvoiceID = invoiceid;
  81. Lines.Refresh(false, true);
  82. }
  83. }
  84. }