CustomerInvoiceDeliveryItem.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using System.Windows;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. namespace PRSDesktop
  7. {
  8. internal class CustomerInvoiceDeliveryItem : DynamicOneToManyGrid<Invoice, DeliveryItem>
  9. {
  10. protected override void DoAdd()
  11. {
  12. var invoice = Item;
  13. if (!invoice.JobLink.IsValid())
  14. {
  15. MessageBox.Show("Please select a job first!");
  16. return;
  17. }
  18. var dialog = new MultiSelectDialog<DeliveryItem>(
  19. new Filter<DeliveryItem>(x => x.InvoiceLink).NotLinkValid().And(x => x.JobLink.ID).IsEqualTo(invoice.JobLink.ID)
  20. , new Columns<DeliveryItem>(x => x.Title, x => x.Description) //new System.Linq.Expressions.Expression<Func<DeliveryItem, object>>[] { x => x.Title, x => x.Description }
  21. );
  22. if (dialog.ShowDialog())
  23. {
  24. var items = dialog.Items();
  25. foreach (var item in items)
  26. {
  27. item.InvoiceLink.ID = invoice.ID;
  28. SaveItem(item);
  29. }
  30. Refresh(false, true);
  31. }
  32. }
  33. protected override void DeleteItems(params CoreRow[] rows)
  34. {
  35. foreach (var row in rows)
  36. {
  37. var item = row.ToObject<DeliveryItem>();
  38. item.InvoiceLink.ID = Guid.Empty;
  39. SaveItem(item);
  40. }
  41. }
  42. }
  43. }