QuoteTakeoffs.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. using InABox.Wpf;
  7. namespace PRSDesktop
  8. {
  9. public class QuoteTakeoffs : DynamicDataGrid<QuoteTakeoff>, IMasterDetailControl<Quote,QuoteTakeoff>, IDataModelSource
  10. {
  11. public Quote? Master { get; set; }
  12. public Filter<QuoteTakeoff> MasterDetailFilter => Master != null && Master.ID != Guid.Empty
  13. ? new Filter<QuoteTakeoff>(x => x.Quote.ID).IsEqualTo(Master.ID)
  14. : new Filter<QuoteTakeoff>().None();
  15. protected override void DoReconfigure(FluentList<DynamicGridOption> options)
  16. {
  17. base.DoReconfigure(options);
  18. options.AddRange(
  19. DynamicGridOption.RecordCount,
  20. DynamicGridOption.AddRows,
  21. DynamicGridOption.EditRows,
  22. DynamicGridOption.DeleteRows,
  23. DynamicGridOption.SelectColumns,
  24. DynamicGridOption.MultiSelect
  25. );
  26. }
  27. public event DataModelUpdateEvent? OnUpdateDataModel;
  28. public string SectionName => "Quote Takeoffs";
  29. public DataModel DataModel(Selection selection)
  30. {
  31. var ids = ExtractValues(x => x.ID, selection).ToArray();
  32. return new BaseDataModel<QuoteTakeoff>(new Filter<QuoteTakeoff>(x => x.ID).InList(ids));
  33. }
  34. protected override void Reload(Filters<QuoteTakeoff> criteria, Columns<QuoteTakeoff> columns, ref SortOrder<QuoteTakeoff>? sort, Action<CoreTable?, Exception?> action)
  35. {
  36. criteria.Add(MasterDetailFilter);
  37. base.Reload(criteria, columns, ref sort, action);
  38. }
  39. protected override bool CanCreateItems()
  40. {
  41. return base.CanCreateItems() && (Master?.ID ?? Guid.Empty) != Guid.Empty;
  42. }
  43. protected override QuoteTakeoff CreateItem()
  44. {
  45. var result = base.CreateItem();
  46. result.Quote.ID = Master?.ID ?? Guid.Empty;
  47. result.Quote.Synchronise(Master ?? new Quote());
  48. return result;
  49. }
  50. }
  51. }