DynamicCrossJoinGrid.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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; set; }
  16. public Expression<Func<TLeft, Guid>> LeftProperty { get; set; }
  17. public DynamicCrossJoinGrid(TLeft left, Expression<Func<TEntity, Guid>> leftMapping, Expression<Func<TLeft, Guid>> leftProperty)
  18. {
  19. Left = left;
  20. LeftMapping = leftMapping;
  21. LeftProperty = leftProperty;
  22. Options.BeginUpdate().Clear().Add(DynamicGridOption.FilterRows).Add(DynamicGridOption.SelectColumns).EndUpdate();
  23. }
  24. protected override void GenerateColumns(DynamicGridColumns columns)
  25. {
  26. base.GenerateColumns(columns);
  27. var prefix = $"{typeof(TLeft).Name}.";
  28. columns.RemoveAll(x => x.ColumnName.StartsWith(prefix));
  29. }
  30. protected override void Reload(Filters<TEntity> criteria, Columns<TEntity> columns, ref SortOrder<TEntity> sort, Action<CoreTable?, Exception?> action)
  31. {
  32. var filter = new Filter<TEntity>();
  33. filter.Expression = CoreUtils.ExtractMemberExpression<TEntity, Guid>(LeftMapping);
  34. filter.Operator = Operator.IsEqualTo;
  35. filter.Value = CoreUtils.GetPropertyValue(Left, CoreUtils.GetFullPropertyName(LeftProperty, "."));
  36. criteria.Add(filter);
  37. base.Reload(criteria, columns, ref sort, action);
  38. }
  39. }
  40. }