QuoteCostSheetsGrid.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.DynamicGrid;
  6. namespace PRSDesktop
  7. {
  8. public class QuoteCostSheetGrid : DynamicDataGrid<QuoteCostSheet>
  9. {
  10. private Guid _quoteid = Guid.Empty;
  11. public QuoteCostSheetGrid()
  12. {
  13. Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.SelectColumns);
  14. OnCustomiseEditor += CustomiseEditor;
  15. HiddenColumns.Add(x => x.CostSheet.ID);
  16. HiddenColumns.Add(x => x.CostSheet.Deleted);
  17. }
  18. public Guid QuoteID
  19. {
  20. get => _quoteid;
  21. set
  22. {
  23. _quoteid = value;
  24. Refresh(false, true);
  25. }
  26. }
  27. private void CustomiseEditor(IDynamicEditorForm sender, QuoteCostSheet[]? items, DynamicGridColumn column, BaseEditor editor)
  28. {
  29. if (column.ColumnName.Equals("CostSheet.ID"))
  30. editor.Editable = items?.FirstOrDefault()?.CostSheet.IsValid() != true ? Editable.Enabled : Editable.Disabled;
  31. }
  32. protected override void Reload(Filters<QuoteCostSheet> criteria, Columns<QuoteCostSheet> columns, ref SortOrder<QuoteCostSheet> sort,
  33. Action<CoreTable?, Exception?> action)
  34. {
  35. criteria.Add(new Filter<QuoteCostSheet>(x => x.Quote.ID).IsEqualTo(QuoteID));
  36. base.Reload(criteria, columns, ref sort, action);
  37. }
  38. protected override QuoteCostSheet CreateItem()
  39. {
  40. var result = base.CreateItem();
  41. result.Quote.ID = QuoteID;
  42. return result;
  43. }
  44. }
  45. }