CellDescriptor.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using FastReport.Table;
  4. namespace FastReport.AdvMatrix
  5. {
  6. internal enum CellContentType
  7. {
  8. MixedText,
  9. SingleExpression,
  10. Aggregate
  11. }
  12. internal class CellDescriptor
  13. {
  14. public TableCell TemplateCell { get; private set; }
  15. public List<string> Expressions { get; private set; }
  16. public AggregateExpressionPairList Aggregates { get; private set; }
  17. public List<string> SpecialFunctions { get; private set; }
  18. public string Text { get; set; }
  19. public int ColumnIndex { get; set; }
  20. public int RowIndex { get; set; }
  21. public CellContentType ContentType { get; private set; }
  22. public bool HasRowTotal { get; private set; }
  23. public bool HasColumnTotal { get; private set; }
  24. public bool HasGrandTotal { get; private set; }
  25. public CellDescriptor(AdvMatrixObject matrix, TableCell templateCell)
  26. {
  27. TemplateCell = templateCell;
  28. Expressions = new List<string>();
  29. Aggregates = new AggregateExpressionPairList(matrix);
  30. SpecialFunctions = new List<string>();
  31. Text = "";
  32. templateCell.SetDescriptor(this);
  33. }
  34. public void ClearData()
  35. {
  36. foreach (AggregateExpressionPair ae in Aggregates)
  37. {
  38. ae.ClearData();
  39. }
  40. }
  41. public void GetExpressions(List<string> expressions)
  42. {
  43. expressions.AddRange(Expressions);
  44. foreach (AggregateExpressionPair ae in Aggregates)
  45. {
  46. expressions.Add(ae.Expression);
  47. }
  48. }
  49. public void UpdateContentType()
  50. {
  51. foreach (string ident in SpecialFunctions)
  52. {
  53. if (ident.Contains("ColumnTotal"))
  54. HasColumnTotal = true;
  55. if (ident.Contains("RowTotal"))
  56. HasRowTotal = true;
  57. if (ident.Contains("GrandTotal"))
  58. HasGrandTotal = true;
  59. }
  60. if (Expressions.Count == 1)
  61. {
  62. if (Aggregates.Count == 1 && Expressions[0] == Aggregates[0].ToAggregateCall())
  63. {
  64. ContentType = CellContentType.Aggregate;
  65. }
  66. else
  67. {
  68. ContentType = CellContentType.SingleExpression;
  69. Text = Expressions[0];
  70. }
  71. }
  72. }
  73. }
  74. }