InvoiceLineGrid.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Linq;
  3. using System.Threading;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using Comal.Classes;
  7. using InABox.Core;
  8. using InABox.DynamicGrid;
  9. using InABox.WPF;
  10. using PRS.Shared;
  11. using PRSDesktop.Utils;
  12. namespace PRSDesktop
  13. {
  14. internal class InvoiceLineGrid : DynamicDataGrid<InvoiceLine>
  15. {
  16. protected override void Init()
  17. {
  18. base.Init();
  19. AddButton("Calculate", PRSDesktop.Resources.costcentre.AsBitmapImage(), CalculateLines);
  20. }
  21. protected override void DoReconfigure(DynamicGridOptions options)
  22. {
  23. base.DoReconfigure(options);
  24. options.RecordCount = true;
  25. options.AddRows = true;
  26. options.DeleteRows = true;
  27. options.EditRows = true;
  28. options.SelectColumns = true;
  29. options.MultiSelect = true;
  30. }
  31. public Invoice Invoice { get; set; }
  32. private bool CalculateLines(Button sender, CoreRow[] rows)
  33. {
  34. InvoiceCalculationSelector selector = new InvoiceCalculationSelector()
  35. {
  36. TimeCalculation = InvoiceTimeCalculation.Activity,
  37. MaterialCalculation = InvoiceMaterialCalculation.Product
  38. };
  39. if (selector.ShowDialog() == true)
  40. {
  41. var time = selector.TimeCalculation;
  42. var materials = selector.MaterialCalculation;
  43. Progress.ShowModal("Calculating Invoice", progress => InvoiceUtilities.GenerateInvoiceLines(Invoice.ID, time, materials, progress));
  44. return true;
  45. }
  46. MessageBox.Show("Please Select or Create an Invoice First!");
  47. return false;
  48. }
  49. protected override void Reload(
  50. Filters<InvoiceLine> criteria, Columns<InvoiceLine> columns, ref SortOrder<InvoiceLine>? sort,
  51. CancellationToken token, Action<CoreTable?, Exception?> action)
  52. {
  53. criteria.Add(new Filter<InvoiceLine>(x => x.InvoiceLink.ID).IsEqualTo(Invoice.ID));
  54. base.Reload(criteria, columns, ref sort, token, action);
  55. }
  56. public override InvoiceLine CreateItem()
  57. {
  58. var result = base.CreateItem();
  59. result.InvoiceLink.ID = Invoice.ID;
  60. result.InvoiceLink.Synchronise(Invoice.ID);
  61. result.SellGL.ID = Invoice.SellGL.ID;
  62. return result;
  63. }
  64. }
  65. }