Browse Source

Aggregates on Groups

reports
Peter Forstmeier 12 years ago
parent
commit
5b8b6f3400
  1. 14
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs
  2. 15
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs
  3. 7
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/AstExtensions.cs
  4. 8
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs
  5. 48
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/AggregatesGroupesFixture.cs
  6. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/FieldsFixture.cs
  7. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/ParametersFixture.cs
  8. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/StandardTests.cs

14
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs

@ -1,13 +1,13 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System; using System;
using ICSharpCode.Reporting.DataManager.Listhandling; using System.Collections.Generic;
using ICSharpCode.Reporting.Expressions; using ICSharpCode.Reporting.Expressions;
using ICSharpCode.Reporting.Expressions.Irony; using ICSharpCode.Reporting.Expressions.Irony;
using ICSharpCode.Reporting.Expressions.Irony.Ast; using ICSharpCode.Reporting.Expressions.Irony.Ast;
using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.Items;
using ICSharpCode.Reporting.PageBuilder.ExportColumns; using ICSharpCode.Reporting.PageBuilder.ExportColumns;
using System.Collections.Generic;
namespace ICSharpCode.Reporting.Exporter.Visitors namespace ICSharpCode.Reporting.Exporter.Visitors
{ {
/// <summary> /// <summary>
@ -18,19 +18,15 @@ namespace ICSharpCode.Reporting.Exporter.Visitors
readonly ReportingLanguageGrammer grammar; readonly ReportingLanguageGrammer grammar;
readonly ReportingExpressionEvaluator evaluator; readonly ReportingExpressionEvaluator evaluator;
public ExpressionVisitor(ReportSettings reportSettings) {
public ExpressionVisitor(ReportSettings reportSettings,IEnumerable<object> dataSource) {
grammar = new ReportingLanguageGrammer(); grammar = new ReportingLanguageGrammer();
evaluator = new ReportingExpressionEvaluator(grammar); evaluator = new ReportingExpressionEvaluator(grammar);
evaluator.AddReportSettings(reportSettings); evaluator.AddReportSettings(reportSettings);
if (dataSource != null) {
evaluator.AddDataSource(dataSource);
}
} }
public void SetSourceList (IEnumerable<object> list) { public void SetCurrentDataSource (IEnumerable<object> dataSource) {
evaluator.SetCurrentDataSource(dataSource);
} }

15
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.DataManager.Listhandling;
using ICSharpCode.Reporting.Exporter;
using ICSharpCode.Reporting.Exporter.Visitors; using ICSharpCode.Reporting.Exporter.Visitors;
using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.Items;
using ICSharpCode.Reporting.PageBuilder.ExportColumns; using ICSharpCode.Reporting.PageBuilder.ExportColumns;
@ -33,15 +32,15 @@ namespace ICSharpCode.Reporting.Expressions
public void Run() public void Run()
{ {
Console.WriteLine(); var visitor = new ExpressionVisitor (reportSettings);
Console.WriteLine("Start ExpressionVisitor");
var visitor = new ExpressionVisitor (reportSettings,dataSource.SortedList); if (dataSource.SortedList != null) {
visitor.Evaluator.Globals.Add("DataSource",dataSource); visitor.SetCurrentDataSource(dataSource.SortedList);
}
if (dataSource.GroupedList != null) {
visitor.SetCurrentDataSource(dataSource.GroupedList);
}
visitor.Run(pages); visitor.Run(pages);
Console.WriteLine("Finish ExpressionVisitor");
Console.WriteLine();
} }
} }
} }

7
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/AstExtensions.cs

@ -42,6 +42,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast
return rs.ParameterCollection; return rs.ParameterCollection;
} }
public static void AddReportSettings (this ReportingExpressionEvaluator app,ReportSettings reportSettings) { public static void AddReportSettings (this ReportingExpressionEvaluator app,ReportSettings reportSettings) {
if (reportSettings == null) if (reportSettings == null)
throw new ArgumentNullException("reportSettings"); throw new ArgumentNullException("reportSettings");
@ -70,7 +71,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast
#region DataSource #region DataSource
public static void AddDataSource (this ReportingExpressionEvaluator app,IEnumerable<object> dataSource){ public static void SetCurrentDataSource (this ReportingExpressionEvaluator app,IEnumerable<object> dataSource){
if (dataSource == null) if (dataSource == null)
throw new ArgumentNullException("dataSource"); throw new ArgumentNullException("dataSource");
if (!app.Globals.ContainsKey("DataSource")) { if (!app.Globals.ContainsKey("DataSource")) {
@ -79,9 +80,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast
app.Globals["DataSource"] = dataSource; app.Globals["DataSource"] = dataSource;
} }
} }
#endregion #endregion
} }
} }

8
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs

@ -24,7 +24,9 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
public void CanSum_Int_WholeCollection() public void CanSum_Int_WholeCollection()
{ {
var reportSettings = new ReportSettings(); var reportSettings = new ReportSettings();
var visitor = new ExpressionVisitor(reportSettings,dataSource.SortedList); // var visitor = new ExpressionVisitor(reportSettings,dataSource.SortedList);
var visitor = new ExpressionVisitor (reportSettings);
visitor.SetCurrentDataSource(dataSource.SortedList);
var script = "= sum('intValue')"; var script = "= sum('intValue')";
collection[0].Text = script; collection[0].Text = script;
visitor.Visit(collection[0]); visitor.Visit(collection[0]);
@ -37,7 +39,9 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates
public void CanSum_Double_WholeCollection() public void CanSum_Double_WholeCollection()
{ {
var reportSettings = new ReportSettings(); var reportSettings = new ReportSettings();
var visitor = new ExpressionVisitor(reportSettings,dataSource.SortedList); // var visitor = new ExpressionVisitor(reportSettings,dataSource.SortedList);
var visitor = new ExpressionVisitor (reportSettings);
visitor.SetCurrentDataSource(dataSource.SortedList);
var script = "= sum('doubleValue')"; var script = "= sum('doubleValue')";
collection[0].Text = script; collection[0].Text = script;
visitor.Visit(collection[0]); visitor.Visit(collection[0]);

48
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/AggregatesGroupesFixture.cs

@ -20,13 +20,14 @@ namespace ICSharpCode.Reporting.Test.Expressions.IntegrationTests
Collection<ExportText> collection; Collection<ExportText> collection;
CollectionDataSource dataSource; CollectionDataSource dataSource;
ContributorCollection list; ContributorCollection list;
ExpressionVisitor visitor;
ReportSettings reportSettings; ReportSettings reportSettings;
[Test] [Test]
public void TestMethod() public void SumGroupedList()
{ {
visitor = new ExpressionVisitor(reportSettings,dataSource.GroupedList); // visitor = new ExpressionVisitor(reportSettings,dataSource.GroupedList);
var visitor = new ExpressionVisitor (reportSettings);
visitor.SetCurrentDataSource(dataSource.GroupedList);
var script = "= sum('randomint')"; var script = "= sum('randomint')";
collection[0].Text = script; collection[0].Text = script;
visitor.Visit(collection[0]); visitor.Visit(collection[0]);
@ -35,6 +36,47 @@ namespace ICSharpCode.Reporting.Test.Expressions.IntegrationTests
} }
[Test]
public void SumOneGroup () {
var container = new ExportContainer();
var script = "= sum('randomint')";
collection[0].Text = script;
container.ExportedItems.AddRange(collection);
// visitor = new ExpressionVisitor(reportSettings,dataSource.GroupedList);
var visitor = new ExpressionVisitor (reportSettings);
visitor.SetCurrentDataSource(dataSource.GroupedList);
var group = dataSource.GroupedList.FirstOrDefault();
visitor.SetCurrentDataSource(group);
visitor.Visit(container);
var result = list.Where(k => k.GroupItem == group.Key.ToString()).Sum(x => x.RandomInt);
Assert.That(Convert.ToDouble(collection[0].Text),Is.EqualTo(result));
}
[Test]
public void SumAllGroups () {
var container = new ExportContainer();
container.ExportedItems.AddRange(collection);
// visitor = new ExpressionVisitor(reportSettings,dataSource.GroupedList);
var visitor = new ExpressionVisitor (reportSettings);
visitor.SetCurrentDataSource(dataSource.GroupedList);
foreach (var group in dataSource.GroupedList) {
var script = "= sum('randomint')";
collection[0].Text = script;
visitor.SetCurrentDataSource(group);
visitor.Visit(container);
var result = list.Where(k => k.GroupItem == group.Key.ToString()).Sum(x => x.RandomInt);
Assert.That(Convert.ToDouble(collection[0].Text),Is.EqualTo(result));
}
}
[SetUp] [SetUp]
public void CreateExportlist() { public void CreateExportlist() {
collection = new Collection<ExportText>(); collection = new Collection<ExportText>();

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/FieldsFixture.cs

@ -67,7 +67,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests
{ {
Text = "myExporttextColumn" Text = "myExporttextColumn"
}); });
visitor = new ExpressionVisitor (new ReportSettings(),null); visitor = new ExpressionVisitor (new ReportSettings());
} }
} }

4
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/ParametersFixture.cs

@ -38,7 +38,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests
); );
var reportSettings = CreateReportSettings(parameters); var reportSettings = CreateReportSettings(parameters);
var visitor = new ExpressionVisitor(reportSettings,null); var visitor = new ExpressionVisitor(reportSettings);
var script = "=Parameters!param1 + Parameters!param2 + Parameters!param3"; var script = "=Parameters!param1 + Parameters!param2 + Parameters!param3";
collection[0].Text = script; collection[0].Text = script;
@ -56,7 +56,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests
} }
); );
var reportSettings = CreateReportSettings(parameters); var reportSettings = CreateReportSettings(parameters);
var visitor = new ExpressionVisitor(reportSettings,null); var visitor = new ExpressionVisitor(reportSettings);
var script = "=Parameters!paramNotExist"; var script = "=Parameters!paramNotExist";
collection[0].Text = script; collection[0].Text = script;

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/StandardTests.cs

@ -87,7 +87,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests {
[TestFixtureSetUp] [TestFixtureSetUp]
public void Setup() { public void Setup() {
expressionVisitor = new ExpressionVisitor(new ReportSettings(),null); expressionVisitor = new ExpressionVisitor(new ReportSettings());
} }
} }

Loading…
Cancel
Save