From bf9fa9dcc7fe9585a15e9b8a1977b0e461ac0958 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Tue, 17 Dec 2013 20:34:56 +0100 Subject: [PATCH] Remove MoveNext from CollectionDataSource.cs, all data access is done by foreach --- .../Listhandling/CollectionDataSource.cs | 62 +++---------------- .../Src/Interfaces/Data/IDataSource.cs | 7 +-- .../Src/PageBuilder/DataPageBuilder.cs | 50 ++++++++++++--- .../src/DataSource/DataSourceFixture.cs | 62 +++++++++++++++---- 4 files changed, 102 insertions(+), 79 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs index 2f3e632eac..5dc8b84976 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs @@ -87,29 +87,26 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling get {return baseList.Count;} } - public object Current {get; private set;} public OrderGroup OrderGroup {get; private set;} + public IEnumerable SortedList {get; private set;} - public IGrouping CurrentKey {get; private set; } - + public IEnumerable> GroupedList {get;private set;} #region Sort void Sort() { if (reportSettings.SortColumnsCollection.Count > 0) { - var sorted = SortInternal(); + SortedList = SortInternal(); OrderGroup = OrderGroup.Sorted; - listEnumerator = sorted.GetEnumerator(); } else { OrderGroup = OrderGroup.AsIs; - listEnumerator = baseList.GetEnumerator(); + SortedList = CurrentList; } - listEnumerator.MoveNext(); - Current = listEnumerator.Current; + } @@ -131,13 +128,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling void Group() { OrderGroup = OrderGroup.Grouped; - groupedList = GroupInternal(); - groupEnumerator = groupedList.GetEnumerator(); - groupEnumerator.MoveNext(); - CurrentKey = groupEnumerator.Current; - listEnumerator = groupEnumerator.Current.GetEnumerator(); - listEnumerator.MoveNext(); - Current = listEnumerator.Current; + GroupedList = GroupInternal(); } @@ -164,20 +155,9 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling #region Fill - IEnumerator> groupEnumerator; - - - IEnumerable> groupedList; - - public IEnumerable> GroupedList { - get { return groupedList; } - } - - IEnumerator listEnumerator; - - public void Fill(List collection) - { - foreach (var element in collection) { + public void Fill (List collection, object toFill) { + Current = toFill; + foreach (var element in collection) { var container = element as ReportContainer; if (container != null) { FillFromList(container.Items); @@ -186,7 +166,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling } } } - + void FillFromList(List collection) { foreach (IPrintableObject item in collection) { @@ -220,28 +200,6 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling return p.PropertyType; } - - public bool MoveNext() - { - var canMove = listEnumerator.MoveNext(); - - if (OrderGroup == OrderGroup.Grouped) { - if (! canMove) { - var groupCanMove = groupEnumerator.MoveNext(); - CurrentKey = groupEnumerator.Current; - if (groupCanMove) { - listEnumerator = groupEnumerator.Current.GetEnumerator(); - canMove = listEnumerator.MoveNext(); - } - } - Current = listEnumerator.Current; - return canMove; - } - - Current = listEnumerator.Current; - return canMove; - } - #endregion diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs index db0b3c9211..6097791199 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/Data/IDataSource.cs @@ -23,16 +23,11 @@ namespace ICSharpCode.Reporting.Interfaces.Data public interface IDataSource{ void Bind(); - - void Fill(List collection); - + void Fill(List collection,object current); Collection AvailableFields {get;} IList CurrentList {get;} int Count {get;} - object Current {get;} OrderGroup OrderGroup {get;} - IGrouping CurrentKey {get;} - } } 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 6e191a7d55..8ce626a5d3 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs @@ -50,8 +50,6 @@ namespace ICSharpCode.Reporting.PageBuilder void BuildDetail() { CurrentSection = ReportModel.DetailSection; -// Console.WriteLine("Report -grouping {0} ",DataSource.OrderGroup.ToString()); -// Console.WriteLine ("groupkey {0}",DataSource.CurrentKey); if(DataSourceContainsData()) { CurrentLocation = DetailStart; if (IsGrouped()) { @@ -69,20 +67,52 @@ namespace ICSharpCode.Reporting.PageBuilder var converter = new ContainerConverter(base.Graphics, CurrentLocation); var position = DetailStart; - foreach (IGrouping element in DataSource.GroupedList) { - Console.WriteLine ("groupkey {0} - {1}",element.Key,element.Count()); - foreach (var e in element) { - Console.WriteLine("\t{0}",e.ToString()); + foreach (IGrouping grouping in DataSource.GroupedList) { + Console.WriteLine ("groupkey {0} - {1}",grouping.Key,grouping.Count()); + + foreach (var current in grouping) { + Console.WriteLine("\t{0}",current.ToString()); } } - - - InsertExportRows(exportRows); } void BuildSortedDetails(){ + + var exportRows = new List(); + var converter = new ContainerConverter(base.Graphics, CurrentLocation); + var position = DetailStart; + + foreach (var element in DataSource.SortedList) { + + var row = CreateContainerForSection(CurrentPage, position); + DataSource.Fill(CurrentSection.Items,element); + + var convertedItems = converter.CreateConvertedList(ReportModel.DetailSection.Items); + + converter.SetParent(row, convertedItems); + + if (PageFull(row)) { + InsertExportRows(exportRows); + exportRows.Clear(); + PerformPageBreak(); + position = DetailStart; + row.Location = position; + } + + MeasureAndArrangeContainer(row); + + row.ExportedItems.AddRange(convertedItems); + exportRows.Add(row); + position = new Point(CurrentSection.Location.X, position.Y + row.DesiredSize.Height + 1); + } + + InsertExportRows(exportRows); + } + + /* + void old_BuildSortedDetails(){ var exportRows = new List(); var converter = new ContainerConverter(base.Graphics, CurrentLocation); @@ -113,7 +143,7 @@ namespace ICSharpCode.Reporting.PageBuilder } while (DataSource.MoveNext()); InsertExportRows(exportRows); } - +*/ void PerformPageBreak(){ CurrentPage.PageInfo.PageNumber = Pages.Count + 1; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs index d26aca75c9..1aeb75da09 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/DataSource/DataSourceFixture.cs @@ -7,6 +7,7 @@ using ICSharpCode.Reporting.DataManager.Listhandling; using ICSharpCode.Reporting.Interfaces; using ICSharpCode.Reporting.Items; using NUnit.Framework; +using System.Linq; namespace ICSharpCode.Reporting.Test.DataSource { @@ -52,7 +53,8 @@ namespace ICSharpCode.Reporting.Test.DataSource }; var collectionSource = new CollectionDataSource (list,new ReportSettings()); collectionSource.Bind(); - collectionSource.Fill(ric); + var result = collectionSource.SortedList.FirstOrDefault(); + collectionSource.Fill(ric,result); foreach (BaseDataItem element in ric) { Assert.That(element.DataType,Is.EqualTo("System.String")); } @@ -64,13 +66,10 @@ namespace ICSharpCode.Reporting.Test.DataSource var ric = new System.Collections.Generic.List(){ new BaseDataItem(){ ColumnName = "Lastname" - }, new BaseDataItem(){ ColumnName = "Firstname" } - - }; var rs = new ReportSettings(); @@ -79,6 +78,16 @@ namespace ICSharpCode.Reporting.Test.DataSource collectionSource.Bind(); string compare = String.Empty; int i = 0; + foreach (var element in collectionSource.SortedList) { + collectionSource.Fill(ric,element); + Console.WriteLine("first : <{0}> Last <{1}> ",((BaseDataItem)ric[0]).DBValue,((BaseDataItem)ric[1]).DBValue); + + Assert.That(((BaseDataItem)ric[0]).DBValue,Is.GreaterThanOrEqualTo(compare)); + + compare = ((BaseDataItem)ric[0]).DBValue; + i++; + } + /* do { collectionSource.Fill(ric); Console.WriteLine("first : <{0}> Last <{1}> ",((BaseDataItem)ric[0]).DBValue, @@ -89,6 +98,7 @@ namespace ICSharpCode.Reporting.Test.DataSource i ++; }while (collectionSource.MoveNext()); + */ Assert.That(i,Is.EqualTo(collectionSource.Count)); } @@ -96,13 +106,26 @@ namespace ICSharpCode.Reporting.Test.DataSource [Test] public void GroupbyOneColumnAndFill () { var dataItemsCollection = CreateDataItems(); - var repiortsettings = new ReportSettings(); - repiortsettings.GroupColumnsCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); - repiortsettings.GroupColumnsCollection.Add( new GroupColumn("RandomInt",1,ListSortDirection.Ascending)); + var reportsettings = new ReportSettings(); + reportsettings.GroupColumnsCollection.Add( new GroupColumn("GroupItem",1,ListSortDirection.Ascending)); + //repiortsettings.GroupColumnsCollection.Add( new GroupColumn("RandomInt",1,ListSortDirection.Ascending)); - var collectionSource = new CollectionDataSource (list,repiortsettings); + var collectionSource = new CollectionDataSource (list,reportsettings); collectionSource.Bind(); int i = 0; + + foreach (var element in collectionSource.GroupedList) { + Console.WriteLine("Key {0} ",element.Key); + foreach (var l in element) { + collectionSource.Fill(dataItemsCollection,l); + Console.WriteLine("first : <{0}> Last <{1}> Group <{2}> Randomint <{3}>",((BaseDataItem)dataItemsCollection[0]).DBValue, + ((BaseDataItem)dataItemsCollection[1]).DBValue, + ((BaseDataItem)dataItemsCollection[2]).DBValue, + ((BaseDataItem)dataItemsCollection[3]).DBValue); + i++; + } + } + /* do { collectionSource.Fill(dataItemsCollection); Console.WriteLine("first : <{0}> Last <{1}> Group <{2}> Randomint <{3}>",((BaseDataItem)dataItemsCollection[0]).DBValue, @@ -111,7 +134,7 @@ namespace ICSharpCode.Reporting.Test.DataSource ((BaseDataItem)dataItemsCollection[3]).DBValue); i ++; }while (collectionSource.MoveNext()); - + */ Assert.That(i,Is.EqualTo(collectionSource.Count)); } @@ -129,6 +152,15 @@ namespace ICSharpCode.Reporting.Test.DataSource var collectionSource = new CollectionDataSource (list,reportSettings); collectionSource.Bind(); int i = 0; + foreach (var element in collectionSource.SortedList) { + collectionSource.Fill(row,element); + var r = (BaseRowItem)row[0]; + foreach (var result in r.Items) { + Assert.That(((BaseDataItem)result).DBValue,Is.Not.Empty); + } + i ++; + } + /* do { collectionSource.Fill(row); var r = (BaseRowItem)row[0]; @@ -137,7 +169,7 @@ namespace ICSharpCode.Reporting.Test.DataSource } i ++; }while (collectionSource.MoveNext()); - + */ Assert.That(i,Is.EqualTo(collectionSource.Count)); } @@ -167,13 +199,21 @@ namespace ICSharpCode.Reporting.Test.DataSource var collectionSource = new CollectionDataSource (list,rs); collectionSource.Bind(); int i = 0; + foreach (var element in collectionSource.SortedList) { + collectionSource.Fill(row,element); + var res = (BaseDataItem)row.Find(c => ((BaseDataItem)c).ColumnName == "GroupItem"); + Assert.That(res.DBValue,Is.Not.Empty); + i ++; + } + + /* do { collectionSource.Fill(row); var res = (BaseDataItem)row.Find(c => ((BaseDataItem)c).ColumnName == "GroupItem"); Assert.That(res.DBValue,Is.Not.Empty); i ++; }while (collectionSource.MoveNext()); - + */ Assert.That(i,Is.EqualTo(collectionSource.Count)); }