CustomerContactGrid.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Windows;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. namespace PRSDesktop
  7. {
  8. public class CustomerContactGrid : DynamicDataGrid<CustomerContact>, ICustomerGrid
  9. {
  10. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  11. {
  12. base.DoReconfigure(options);
  13. options.AddRange(
  14. DynamicGridOption.AddRows,
  15. DynamicGridOption.EditRows,
  16. DynamicGridOption.SelectColumns,
  17. DynamicGridOption.DeleteRows
  18. );
  19. }
  20. public Customer Customer { get; set; }
  21. protected override void Reload(Filters<CustomerContact> criteria, Columns<CustomerContact> columns, ref SortOrder<CustomerContact> sort,
  22. Action<CoreTable, Exception> action)
  23. {
  24. criteria.Add(new Filter<CustomerContact>(x => x.Customer).LinkValid(Customer.ID));
  25. base.Reload(criteria, columns, ref sort, action);
  26. }
  27. protected override CustomerContact 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. }