InvoiceGrid.xaml.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 InvoiceGrid : UserControl, IPanel<Invoice>, IJobControl
  14. {
  15. public InvoiceGrid()
  16. {
  17. InitializeComponent();
  18. Invoices.OnSelectItem += Invoices_OnSelectItem;
  19. }
  20. public Guid JobID
  21. {
  22. get => Invoices.JobID;
  23. set
  24. {
  25. Invoices.JobID = value;
  26. Parts.JobID = value;
  27. Time.JobID = value;
  28. }
  29. }
  30. public bool IsReady { get; set; }
  31. public event DataModelUpdateEvent OnUpdateDataModel;
  32. public Dictionary<string, object[]> Selected()
  33. {
  34. return new Dictionary<string, object[]> { { typeof(Invoice).EntityName(), Invoices.SelectedRows } };
  35. }
  36. public void CreateToolbarButtons(IPanelHost host)
  37. {
  38. }
  39. public void Setup()
  40. {
  41. Invoices.Refresh(true, false);
  42. Parts.Refresh(true, false);
  43. Time.Refresh(true, false);
  44. Lines.Refresh(true, false);
  45. }
  46. public void Shutdown()
  47. {
  48. }
  49. public void Refresh()
  50. {
  51. Invoices.Refresh(false, true);
  52. var bData = Invoices.SelectedRows.Any();
  53. Parts.Refresh(false, bData);
  54. Time.Refresh(false, bData);
  55. Lines.Refresh(false, bData);
  56. }
  57. public string SectionName => "Invoice Grid";
  58. public DataModel DataModel(Selection selection)
  59. {
  60. var ids = Invoices.ExtractValues(x => x.ID, selection).ToArray();
  61. return new InvoiceDataModel(new Filter<Invoice>(x => x.ID).InList(ids));
  62. }
  63. public void Heartbeat(TimeSpan time)
  64. {
  65. }
  66. private void Invoices_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  67. {
  68. var row = e.Rows?.FirstOrDefault();
  69. var id = row != null ? row.Get<Invoice, Guid>(x => x.ID) : CoreUtils.FullGuid;
  70. Parts.InvoiceID = id;
  71. Parts.Refresh(false, true);
  72. Time.InvoiceID = id;
  73. Time.Refresh(false, true);
  74. Lines.InvoiceID = id;
  75. Lines.Refresh(false, true);
  76. }
  77. }
  78. }