diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionSource.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionSource.cs index 91d7ad113b..ce0b752dc1 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionSource.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionSource.cs @@ -28,7 +28,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling /// /// Description of CollectionHandling. /// - internal class CollectionSource:IDataViewHandling + public class CollectionSource:IDataViewHandling { private PropertyDescriptorCollection listProperties; 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 b924d16c74..83b70cd293 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 @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; using System.Collections.ObjectModel; +using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.Expressions; using ICSharpCode.Reporting.Expressions.Irony; using ICSharpCode.Reporting.Expressions.Irony.Ast; @@ -20,16 +21,22 @@ namespace ICSharpCode.Reporting.Exporter.Visitors readonly ReportingExpressionEvaluator evaluator; - public ExpressionVisitor(Collection pages,ReportSettings reportSettings):this(reportSettings) + public ExpressionVisitor(Collection pages, + ReportSettings reportSettings, + CollectionSource dataSource):this(reportSettings,dataSource) { this.pages = pages; } - internal ExpressionVisitor(ReportSettings reportSettings) { + internal ExpressionVisitor(ReportSettings reportSettings,CollectionSource dataSource) { grammar = new ReportingLanguageGrammer(); evaluator = new ReportingExpressionEvaluator(grammar); evaluator.AddReportSettings(reportSettings); + if (dataSource != null) { + evaluator.AddDataSource(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 2534000d88..7f1e853286 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/ExpressionRunner.cs @@ -2,6 +2,7 @@ // This code is distributed under the GNU LGPL (for details please see \doc\license.txt) using System; using System.Collections.ObjectModel; +using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.Exporter; using ICSharpCode.Reporting.Exporter.Visitors; using ICSharpCode.Reporting.Items; @@ -19,10 +20,13 @@ namespace ICSharpCode.Reporting.Expressions // http://blog.miraclespain.com/archive/2009/Oct-07.html // private readonly ExpressionVisitor visitor; + private readonly CollectionSource dataSource; - public ExpressionRunner(Collection pages,ReportSettings reportSettings):base(pages) + public ExpressionRunner(Collection pages,ReportSettings reportSettings,CollectionSource dataSource):base(pages) { - visitor = new ExpressionVisitor (Pages,reportSettings); + this.dataSource = dataSource; + visitor = new ExpressionVisitor (Pages,reportSettings,dataSource); + visitor.Evaluator.Globals.Add("DataSource",dataSource); } 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 8c716fed14..c6a8bf8df5 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 @@ -1,10 +1,11 @@ // 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 Irony.Interpreter; +using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.Interfaces.Export; using ICSharpCode.Reporting.Items; using ICSharpCode.Reporting.PageBuilder.ExportColumns; +using Irony.Interpreter; namespace ICSharpCode.Reporting.Expressions.Irony.Ast { @@ -63,6 +64,25 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast public static ExportContainer GetCurrentContainer (this ScriptThread thread){ return (ExportContainer)thread.App.Globals["CurrentContainer"]; } + + #endregion + + #region DataSource + + public static void AddDataSource (this ReportingExpressionEvaluator app,CollectionSource dataSource){ + if (dataSource == null) + throw new ArgumentNullException("dataSource"); + if (!app.Globals.ContainsKey("DataSource")) { + app.Globals.Add("DataSource",dataSource); + } else { + app.Globals["DataSource"] = dataSource; + } + } + + +// public static CollectionSource GetDataSource (this ScriptThread thread){ +// return (CollectionSource)thread.App.Globals["DataSource"]; +// } #endregion } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs index 666c391667..2c6eb3a0fe 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs @@ -18,14 +18,20 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports /// /// Description of ImportAggregates. /// + public static class ImportExtensions + { + public static CollectionSource GetDataSource (this ScriptThread thread){ + return (CollectionSource)thread.App.Globals["DataSource"]; + } + } + public static class ImportAggregates { public static object Sum(ScriptThread thread, AstNode[] childNodes) { double sum = 0; var fieldName = childNodes[0].Evaluate(thread).ToString(); - var dataSource = (CollectionSource)thread.App.Globals["Current"]; - + var dataSource = thread.GetDataSource(); var curpos = dataSource.CurrentPosition; dataSource.CurrentPosition = 0; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs index fc66fd307a..1e59979c98 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs @@ -13,6 +13,7 @@ using System.Drawing; using System.Linq; using ICSharpCode.Reporting.BaseClasses; +using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.Exporter; using ICSharpCode.Reporting.Exporter.Visitors; using ICSharpCode.Reporting.Expressions; @@ -39,7 +40,7 @@ namespace ICSharpCode.Reporting.PageBuilder ReportModel = reportModel; Pages = new Collection(); Graphics = CreateGraphics.FromSize(reportModel.ReportSettings.PageSize); - ExpressionVisitor = new ExpressionVisitor(ReportModel.ReportSettings); + ExpressionVisitor = new ExpressionVisitor(ReportModel.ReportSettings,null); } #region create Report Sections @@ -191,9 +192,9 @@ namespace ICSharpCode.Reporting.PageBuilder #region Visitors - protected void RunExpressions(ReportSettings reportsettings) + protected void RunExpressions(ReportSettings reportsettings,CollectionSource dataSource) { - var er = new ExpressionRunner(Pages,reportsettings); + var er = new ExpressionRunner(Pages,reportsettings,dataSource); er.Run(); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs index 8113517586..a293a6d17d 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs @@ -41,7 +41,7 @@ namespace ICSharpCode.Reporting.PageBuilder base.BuildReportFooter(); base.AddPage(CurrentPage); UpdatePageInfo(); - RunExpressions(ReportModel.ReportSettings); + RunExpressions(ReportModel.ReportSettings,DataSource); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/FormPageBuilder.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/FormPageBuilder.cs index 95a0e67c99..d9864af080 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/FormPageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/FormPageBuilder.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.Reporting.PageBuilder base.AddPage(CurrentPage); UpdatePageInfo(); // RunDebugVisitor(); - RunExpressions(ReportModel.ReportSettings); +// RunExpressions(ReportModel.ReportSettings); } 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 9c443488e2..64571b1ecb 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 @@ -15,19 +15,18 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates { Collection collection; - ExpressionVisitor expressionVisitor; AggregateCollection agc; AggregateFuctionHelper helper; - CollectionSource cs; + CollectionSource dataSource; + [Test] public void CanSum_Int_WholeCollection() { var reportSettings = new ReportSettings(); - var visitor = new ExpressionVisitor(reportSettings); + var visitor = new ExpressionVisitor(reportSettings,dataSource); var script = "= sum('intValue')"; collection[0].Text = script; - visitor.Evaluator.Globals.Add("Current",cs); visitor.Visit(collection[0]); Assert.That (collection[0].Text,Is.EqualTo("406")); Assert.That(Convert.ToInt32(collection[0].Text),Is.TypeOf(typeof(int))); @@ -38,10 +37,9 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates public void CanSum_Double_WholeCollection() { var reportSettings = new ReportSettings(); - var visitor = new ExpressionVisitor(reportSettings); + var visitor = new ExpressionVisitor(reportSettings,dataSource); var script = "= sum('doubleValue')"; collection[0].Text = script; - visitor.Evaluator.Globals.Add("Current",cs); visitor.Visit(collection[0]); Assert.That (collection[0].Text,Is.EqualTo("408,25")); Assert.That(Convert.ToDouble(collection[0].Text),Is.TypeOf(typeof(double))); @@ -59,14 +57,9 @@ namespace ICSharpCode.Reporting.Test.Expressions.Aggregates helper = new AggregateFuctionHelper(); agc = helper.AggregateCollection; - cs = new CollectionSource(agc,typeof(Aggregate),new ReportSettings()); - cs.Bind(); + dataSource = new CollectionSource(agc,typeof(Aggregate),new ReportSettings()); + dataSource.Bind(); } - - [TestFixtureSetUp] - public void Setup() { - expressionVisitor = new ExpressionVisitor(new ReportSettings()); - } } } 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 649a857056..cc793671a8 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 @@ -13,9 +13,8 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests public class FieldsFixture { Collection collection; - ExpressionVisitor expressionVisitor; - - + ExpressionVisitor visitor; + [Test] public void FieldsInContainer() { var script = "=Fields!myfield1 + Fields!myfield2"; @@ -30,11 +29,12 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests Text = " is great", Name = "myfield2" }); - var visitor = new ExpressionVisitor(new ReportSettings()); + var exportContainer = new ExportContainer(); exportContainer.ExportedItems.Add(collection[0]); exportContainer.ExportedItems.Add(collection[1]); exportContainer.ExportedItems.Add(collection[2]); + visitor.Visit(exportContainer); Assert.That (collection[0].Text,Is.EqualTo("Sharpdevelop is great")); } @@ -49,10 +49,11 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests Text = "Sharpdevelop", Name = "myfield1" }); - var visitor = new ExpressionVisitor(new ReportSettings()); + var exportContainer = new ExportContainer(); exportContainer.ExportedItems.Add(collection[0]); exportContainer.ExportedItems.Add(collection[1]); + visitor.Visit(exportContainer); Assert.That (collection[0].Text.StartsWith("Missing")); Assert.That (collection[0].Text.Contains("myfieldNotExist")); @@ -61,16 +62,13 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests [SetUp] public void CreateExportlist() { - collection = new Collection(); + collection = new Collection(); collection.Add(new ExportText() - { - Text = "myExporttextColumn" - }); + { + Text = "myExporttextColumn" + }); + visitor = new ExpressionVisitor (new ReportSettings(),null); } - [TestFixtureSetUp] - public void Setup() { - expressionVisitor = new ExpressionVisitor(new ReportSettings()); - } } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs index b3ddef0a55..e8cf9b27e1 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Expressions/IntegrationTests/GlobalsFixture.cs @@ -13,12 +13,11 @@ using NUnit.Framework; namespace ICSharpCode.Reporting.Test.Expressions.InterationTests { [TestFixture] - + [Ignore] public class GlobalsFixture { IReportCreator reportCreator; Collection collection; - ExpressionVisitor expressionVisitor; [Test] public void CanReadPageNumber() @@ -108,10 +107,10 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests } - [TestFixtureSetUp] - public void Setup() { - - expressionVisitor = new ExpressionVisitor(new ReportSettings()); - } +// [TestFixtureSetUp] +// public void Setup() { +// +// expressionVisitor = 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 fe6c402fff..17b6775be0 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 @@ -14,7 +14,6 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests public class ParametersFixture { Collection collection; - ExpressionVisitor expressionVisitor; [Test] @@ -39,7 +38,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests ); var reportSettings = CreateReportSettings(parameters); - var visitor = new ExpressionVisitor(reportSettings); + var visitor = new ExpressionVisitor(reportSettings,null); var script = "=Parameters!param1 + Parameters!param2 + Parameters!param3"; collection[0].Text = script; @@ -57,7 +56,7 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests } ); var reportSettings = CreateReportSettings(parameters); - var visitor = new ExpressionVisitor(reportSettings); + var visitor = new ExpressionVisitor(reportSettings,null); var script = "=Parameters!paramNotExist"; collection[0].Text = script; @@ -84,9 +83,5 @@ namespace ICSharpCode.Reporting.Test.Expressions.InterationTests }); } - [TestFixtureSetUp] - public void Setup() { - expressionVisitor = new ExpressionVisitor(new ReportSettings()); - } } } 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 5a364468a5..e34640dd82 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()); + expressionVisitor = new ExpressionVisitor(new ReportSettings(),null); } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_FromListFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_FromListFixture.cs index 557f1debb6..252b0e1cfa 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_FromListFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Model/Report_FromListFixture.cs @@ -32,7 +32,7 @@ namespace ICSharpCode.Reporting.Test.Model [Test] public void DetailContainsOneDataItem() { var section = model.DetailSection; - Assert.That(section.Items.Count,Is.EqualTo(1)); + Assert.That(section.Items.Count,Is.EqualTo(2)); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd index 1a5a2404c9..99a74a23e2 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd @@ -78,6 +78,24 @@ False False + + 384, 13 + 100, 20 + White + Segoe UI, 9pt + None + TopLeft + False + False + System.Int + No + BaseDataItem2 + False + Black + ControlText + RandomInt + BaseDataItem2 + 29, 14 100, 20 @@ -138,7 +156,24 @@ 0 False False - + + + 298, 4 + 100, 20 + White + Segoe UI, 9pt + None + TopLeft + False + False + No + = sum('RandomInt') + False + Black + ControlText + BaseTextItem2147483646 + + Black ReportFooter diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd index c2dee1ca84..0307901de9 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/TestForGlobals.srd @@ -37,8 +37,8 @@ False - 247, 17 - 179, 20 + 383, 17 + 277, 20 White Segoe UI, 9pt None @@ -54,7 +54,7 @@ 16, 17 - 130, 20 + 264, 20 White Microsoft Sans Serif, 10pt None @@ -84,7 +84,7 @@ 16, 4 - 100, 20 + 264, 20 White Segoe UI, 9pt None @@ -142,7 +142,7 @@ 16, 4 - 100, 20 + 176, 20 White Segoe UI, 9pt None @@ -157,8 +157,8 @@ BaseTextItem2147483646 - 622, 5 - 100, 20 + 499, 5 + 223, 20 White Microsoft Sans Serif, 10pt None