diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs index e75d14cdc1..b9741244f6 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/ExpressionVisitor.cs +++ b/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) // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; -using ICSharpCode.Reporting.DataManager.Listhandling; +using System.Collections.Generic; using ICSharpCode.Reporting.Expressions; using ICSharpCode.Reporting.Expressions.Irony; using ICSharpCode.Reporting.Expressions.Irony.Ast; using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.PageBuilder.ExportColumns; -using System.Collections.Generic; + namespace ICSharpCode.Reporting.Exporter.Visitors { /// @@ -18,19 +18,15 @@ namespace ICSharpCode.Reporting.Exporter.Visitors readonly ReportingLanguageGrammer grammar; readonly ReportingExpressionEvaluator evaluator; - - public ExpressionVisitor(ReportSettings reportSettings,IEnumerable dataSource) { + public ExpressionVisitor(ReportSettings reportSettings) { grammar = new ReportingLanguageGrammer(); evaluator = new ReportingExpressionEvaluator(grammar); evaluator.AddReportSettings(reportSettings); - if (dataSource != null) { - evaluator.AddDataSource(dataSource); - } } - public void SetSourceList (IEnumerable list) { - + public void SetCurrentDataSource (IEnumerable dataSource) { + evaluator.SetCurrentDataSource(dataSource); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs index 0e036d8065..e7a7a9c3f8 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs @@ -3,7 +3,6 @@ using System; using System.Collections.ObjectModel; using ICSharpCode.Reporting.DataManager.Listhandling; -using ICSharpCode.Reporting.Exporter; using ICSharpCode.Reporting.Exporter.Visitors; using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.PageBuilder.ExportColumns; @@ -33,15 +32,15 @@ namespace ICSharpCode.Reporting.Expressions public void Run() { - Console.WriteLine(); - Console.WriteLine("Start ExpressionVisitor"); + var visitor = new ExpressionVisitor (reportSettings); - var visitor = new ExpressionVisitor (reportSettings,dataSource.SortedList); - visitor.Evaluator.Globals.Add("DataSource",dataSource); + if (dataSource.SortedList != null) { + visitor.SetCurrentDataSource(dataSource.SortedList); + } + if (dataSource.GroupedList != null) { + visitor.SetCurrentDataSource(dataSource.GroupedList); + } visitor.Run(pages); - - Console.WriteLine("Finish ExpressionVisitor"); - Console.WriteLine(); } } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/AstExtensions.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/AstExtensions.cs index e9a0908808..3579421951 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/AstExtensions.cs +++ b/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; } + public static void AddReportSettings (this ReportingExpressionEvaluator app,ReportSettings reportSettings) { if (reportSettings == null) throw new ArgumentNullException("reportSettings"); @@ -70,7 +71,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast #region DataSource - public static void AddDataSource (this ReportingExpressionEvaluator app,IEnumerable dataSource){ + public static void SetCurrentDataSource (this ReportingExpressionEvaluator app,IEnumerable dataSource){ if (dataSource == null) throw new ArgumentNullException("dataSource"); if (!app.Globals.ContainsKey("DataSource")) { @@ -79,9 +80,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast app.Globals["DataSource"] = dataSource; } } - - - + #endregion } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs index d96cefb16f..1a2705b156 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/Aggregates/SumAggregate.cs +++ b/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() { 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')"; collection[0].Text = script; visitor.Visit(collection[0]); @@ -37,7 +39,9 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates public void CanSum_Double_WholeCollection() { 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')"; collection[0].Text = script; visitor.Visit(collection[0]); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/AggregatesGroupesFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/AggregatesGroupesFixture.cs index dc2755e4e2..60f80ded8d 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/AggregatesGroupesFixture.cs +++ b/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 collection; CollectionDataSource dataSource; ContributorCollection list; - ExpressionVisitor visitor; ReportSettings reportSettings; [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')"; collection[0].Text = script; 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] public void CreateExportlist() { collection = new Collection(); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/FieldsFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/FieldsFixture.cs index cc793671a8..4073025da2 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/FieldsFixture.cs +++ b/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" }); - visitor = new ExpressionVisitor (new ReportSettings(),null); + visitor = new ExpressionVisitor (new ReportSettings()); } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/ParametersFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/ParametersFixture.cs index 17b6775be0..0cafeb570f 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/ParametersFixture.cs +++ b/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 visitor = new ExpressionVisitor(reportSettings,null); + var visitor = new ExpressionVisitor(reportSettings); var script = "=Parameters!param1 + Parameters!param2 + Parameters!param3"; collection[0].Text = script; @@ -56,7 +56,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests } ); var reportSettings = CreateReportSettings(parameters); - var visitor = new ExpressionVisitor(reportSettings,null); + var visitor = new ExpressionVisitor(reportSettings); var script = "=Parameters!paramNotExist"; collection[0].Text = script; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/StandardTests.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/StandardTests.cs index e34640dd82..5a364468a5 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/StandardTests.cs +++ b/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] public void Setup() { - expressionVisitor = new ExpressionVisitor(new ReportSettings(),null); + expressionVisitor = new ExpressionVisitor(new ReportSettings()); } }