DynamicCrossJoinGrid.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using InABox.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Linq.Expressions;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace InABox.DynamicGrid
  9. {
  10. public class DynamicCrossJoinGrid<TEntity, TLeft> : DynamicDataGrid<TEntity>
  11. where TEntity : Entity, IRemotable, IPersistent, new()
  12. where TLeft : Entity
  13. {
  14. public TLeft? Left { get; set; }
  15. public Expression<Func<TEntity, Guid>>? LeftMapping { get; init; }
  16. public Expression<Func<TLeft, Guid>>? LeftProperty { get; init; }
  17. public DynamicCrossJoinGrid()
  18. {
  19. Options.BeginUpdate().Clear().Add(DynamicGridOption.SelectColumns).EndUpdate();
  20. }
  21. public DynamicCrossJoinGrid(TLeft left, Expression<Func<TEntity, Guid>> leftMapping, Expression<Func<TLeft, Guid>> leftProperty)
  22. {
  23. Left = left;
  24. LeftMapping = leftMapping;
  25. LeftProperty = leftProperty;
  26. }
  27. protected override void GenerateColumns(DynamicGridColumns columns)
  28. {
  29. base.GenerateColumns(columns);
  30. var prefix = $"{typeof(TLeft).Name}.";
  31. columns.RemoveAll(x => x.ColumnName.StartsWith(prefix));
  32. }
  33. protected override void Reload(Filters<TEntity> criteria, Columns<TEntity> columns, ref SortOrder<TEntity>? sort, Action<CoreTable?, Exception?> action)
  34. {
  35. var filter = new Filter<TEntity>();
  36. filter.Expression = CoreUtils.ExtractMemberExpression<TEntity, Guid>(LeftMapping);
  37. filter.Operator = Operator.IsEqualTo;
  38. filter.Value = CoreUtils.GetPropertyValue(Left, CoreUtils.GetFullPropertyName(LeftProperty, "."));
  39. criteria.Add(filter);
  40. base.Reload(criteria, columns, ref sort, action);
  41. }
  42. }
  43. }