CustomerProductGrid.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Threading;
  3. using System.Windows;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.DynamicGrid;
  7. namespace PRSDesktop
  8. {
  9. public class CustomerProductGrid : DynamicDataGrid<CustomerProduct>, ICustomerGrid
  10. {
  11. protected override void DoReconfigure(DynamicGridOptions options)
  12. {
  13. base.DoReconfigure(options);
  14. options.AddRows = true;
  15. options.EditRows = true;
  16. options.SelectColumns = true;
  17. options.DeleteRows = true;
  18. }
  19. public Customer Customer { get; set; }
  20. protected override void Reload(
  21. Filters<CustomerProduct> criteria, Columns<CustomerProduct> columns, ref SortOrder<CustomerProduct>? sort,
  22. CancellationToken token, Action<CoreTable?, Exception?> action)
  23. {
  24. criteria.Add(new Filter<CustomerProduct>(x => x.Customer).LinkValid(Customer.ID));
  25. base.Reload(criteria, columns, ref sort, token, action);
  26. }
  27. public override CustomerProduct CreateItem()
  28. {
  29. var result = base.CreateItem();
  30. result.Customer.ID = Customer.ID;
  31. result.Customer.Synchronise(Customer);
  32. return result;
  33. }
  34. protected override BaseEditor? GetEditor(object item, DynamicGridColumn column)
  35. {
  36. if (column.ColumnName.Equals("Customer.ID"))
  37. return new NullEditor();
  38. return base.GetEditor(item, column);
  39. }
  40. protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
  41. {
  42. if (Customer.ID == Guid.Empty)
  43. MessageBox.Show("Please select a Customer first!");
  44. else
  45. base.DoAdd();
  46. }
  47. }
  48. }