CustomerInvoiceTimeSheet.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 CustomerInvoiceTimeSheet : DynamicOneToManyGrid<Invoice, TimeSheet>
  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<TimeSheet>(
  19. new Filter<TimeSheet>(x => x.InvoiceLink).NotLinkValid().And(x => x.JobLink.ID).IsEqualTo(invoice.JobLink.ID)
  20. .And(x => x.Approved).IsNotEqualTo(DateTime.MinValue),
  21. new Columns<TimeSheet>(x => x.Date,
  22. x => x.EmployeeLink
  23. .Name) //new System.Linq.Expressions.Expression<Func<TimeSheet, object>>[] { x => x.Date, x => x.EmployeeLink.Name }
  24. );
  25. if (dialog.ShowDialog())
  26. {
  27. var items = dialog.Items();
  28. foreach (var item in items)
  29. {
  30. item.InvoiceLink.ID = invoice.ID;
  31. SaveItem(item);
  32. }
  33. Refresh(false, true);
  34. }
  35. }
  36. protected override void DeleteItems(params CoreRow[] rows)
  37. {
  38. foreach (var row in rows)
  39. {
  40. var item = row.ToObject<TimeSheet>();
  41. item.InvoiceLink.ID = Guid.Empty;
  42. SaveItem(item);
  43. }
  44. }
  45. }
  46. }