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 62acc59581..2f3e632eac 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 @@ -27,13 +27,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling public class CollectionDataSource:IDataSource { - - readonly DataCollection baseList; readonly ReportSettings reportSettings; readonly Type elementType; readonly PropertyDescriptorCollection listProperties; -// OrderGroup orderGroup; + public CollectionDataSource(IEnumerable list, ReportSettings reportSettings) { @@ -81,13 +79,12 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling } } + public IList CurrentList {get;private set;} public int Count { - get { - return baseList.Count; - } + get {return baseList.Count;} } @@ -98,6 +95,7 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling public IGrouping CurrentKey {get; private set; } + #region Sort void Sort() @@ -167,7 +165,14 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling IEnumerator> groupEnumerator; + + IEnumerable> groupedList; + + public IEnumerable> GroupedList { + get { return groupedList; } + } + IEnumerator listEnumerator; public void Fill(List collection) @@ -219,11 +224,11 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling public bool MoveNext() { var canMove = listEnumerator.MoveNext(); - + if (OrderGroup == OrderGroup.Grouped) { if (! canMove) { var groupCanMove = groupEnumerator.MoveNext(); - CurrentKey = groupEnumerator.Current; + CurrentKey = groupEnumerator.Current; if (groupCanMove) { listEnumerator = groupEnumerator.Current.GetEnumerator(); canMove = listEnumerator.MoveNext(); 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 4bb3ee782a..6e191a7d55 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs @@ -42,61 +42,80 @@ namespace ICSharpCode.Reporting.PageBuilder AddPage(CurrentPage); UpdatePageInfo(); RunExpressions(ReportModel.ReportSettings,DataSource); - var formatVisitor = new FormatVisitor(); formatVisitor.Run(Pages); - } void BuildDetail() { - Console.WriteLine("DatapageBuilder"); - var exportRows = new List(); - var converter = new ContainerConverter(base.Graphics, CurrentLocation); - - var position = DetailStart; - CurrentSection = ReportModel.DetailSection; // Console.WriteLine("Report -grouping {0} ",DataSource.OrderGroup.ToString()); // Console.WriteLine ("groupkey {0}",DataSource.CurrentKey); if(DataSourceContainsData()) { CurrentLocation = DetailStart; - if (! IsGrouped()) { - Console.WriteLine("report is not grouped"); + if (IsGrouped()) { + BuildGroupedDetails(); } else { - Console.WriteLine("report is grouped"); + BuildSortedDetails(); } - do { - var row = CreateContainerForSection(CurrentPage,position); - DataSource.Fill(CurrentSection.Items); - - 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); + + void BuildGroupedDetails () { + Console.WriteLine("report is grouped"); + var exportRows = new List(); + 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()); } - while (DataSource.MoveNext()); - InsertExportRows(exportRows); } + + + + InsertExportRows(exportRows); + } + + void BuildSortedDetails(){ + + var exportRows = new List(); + var converter = new ContainerConverter(base.Graphics, CurrentLocation); + var position = DetailStart; + + do { + var row = CreateContainerForSection(CurrentPage, position); + DataSource.Fill(CurrentSection.Items); + + 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); + + } while (DataSource.MoveNext()); + InsertExportRows(exportRows); } - void PerformPageBreak() - { + + void PerformPageBreak(){ CurrentPage.PageInfo.PageNumber = Pages.Count + 1; Pages.Add(CurrentPage); CurrentPage = CreateNewPage(); @@ -106,15 +125,12 @@ namespace ICSharpCode.Reporting.PageBuilder } - - bool IsGrouped() - { + bool IsGrouped(){ return DataSource.OrderGroup == OrderGroup.Grouped; } - void CreateDataSource() - { + void CreateDataSource(){ DataSource = new CollectionDataSource(List, ReportModel.ReportSettings); if (DataSourceContainsData()) { DataSource.Bind(); @@ -136,15 +152,13 @@ namespace ICSharpCode.Reporting.PageBuilder } - void MeasureAndArrangeContainer(IExportContainer container) - { + void MeasureAndArrangeContainer(IExportContainer container){ container.DesiredSize = MeasureElement(container); ArrangeContainer(container); } - ExportContainer CreateContainerForSection(ExportPage parent,Point location ) - { + ExportContainer CreateContainerForSection(ExportPage parent,Point location ){ var detail = (ExportContainer)CurrentSection.CreateExportColumn(); detail.Location = location; detail.Parent = parent; @@ -152,8 +166,7 @@ namespace ICSharpCode.Reporting.PageBuilder } - void InsertExportRows(List list) - { + void InsertExportRows(List list){ if (Pages.Count == 0) { CurrentPage.ExportedItems.InsertRange(2, list); } else { diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageFixture.cs index b427fc2dd7..6b4edea05c 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageFixture.cs @@ -10,11 +10,9 @@ using System; using System.IO; using System.Reflection; using System.Drawing; -using ICSharpCode.Reporting.Exporter; using ICSharpCode.Reporting.Globals; using ICSharpCode.Reporting.Interfaces; using ICSharpCode.Reporting.Interfaces.Export; -using ICSharpCode.Reporting.PageBuilder; using NUnit.Framework; namespace ICSharpCode.Reporting.Test.PageBuilder @@ -69,7 +67,7 @@ namespace ICSharpCode.Reporting.Test.PageBuilder [SetUp] public void LoadFromStream() { - System.Reflection.Assembly asm = Assembly.GetExecutingAssembly(); + Assembly asm = Assembly.GetExecutingAssembly(); var stream = asm.GetManifestResourceStream(TestHelper.RepWithTwoItems); var reportingFactory = new ReportingFactory(); reportCreator = reportingFactory.ReportCreator(stream);