From d3ffbf32b96c1765c41b77541cd16e8dd63d06f6 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 21 Dec 2013 18:10:20 +0100 Subject: [PATCH] Cleanup DataPageBuilder.cs --- .../Src/PageBuilder/BasePageBuilder.cs | 5 +- .../Converter/ContainerConverter.cs | 9 +- .../Src/PageBuilder/DataPageBuilder.cs | 95 +++++++------------ 3 files changed, 39 insertions(+), 70 deletions(-) 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 737a8e0b14..1057d9ca51 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs @@ -40,7 +40,6 @@ namespace ICSharpCode.Reporting.PageBuilder ReportModel = reportModel; Pages = new Collection(); Graphics = CreateGraphics.FromSize(reportModel.ReportSettings.PageSize); -// ExpressionVisitor = new ExpressionVisitor(ReportModel.ReportSettings,null); } #region create Report Sections @@ -101,7 +100,7 @@ namespace ICSharpCode.Reporting.PageBuilder protected bool PageFull(IExportContainer row) { - if (row.DisplayRectangle.Bottom > DetailEnds.Y) { + if (row.DisplayRectangle.Bottom> DetailEnds.Y) { return true; } return false; @@ -112,7 +111,7 @@ namespace ICSharpCode.Reporting.PageBuilder protected IExportContainer CreateSection(IReportContainer container,Point location) { - var containerConverter = new ContainerConverter(Graphics, location); + var containerConverter = new ContainerConverter(location); var convertedContainer = containerConverter.ConvertToExportContainer(container); var list = containerConverter.CreateConvertedList(container.Items); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/Converter/ContainerConverter.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/Converter/ContainerConverter.cs index a62cd0792a..9ee0aee577 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/Converter/ContainerConverter.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/Converter/ContainerConverter.cs @@ -22,12 +22,8 @@ namespace ICSharpCode.Reporting.PageBuilder.Converter /// class ContainerConverter : IContainerConverter { - public ContainerConverter(Graphics graphics, Point currentLocation) + public ContainerConverter(Point currentLocation) { - if (graphics == null) { - throw new ArgumentNullException("graphics"); - } - Graphics = graphics; CurrentLocation = currentLocation; } @@ -63,9 +59,6 @@ namespace ICSharpCode.Reporting.PageBuilder.Converter } } - protected Point CurrentLocation { get; set; } - - internal Graphics Graphics {get;private set;} } } 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 11fc62fe97..ee4555fb65 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs @@ -55,31 +55,30 @@ namespace ICSharpCode.Reporting.PageBuilder CurrentSection = ReportModel.DetailSection; if(DataSourceContainsData()) { CurrentLocation = DetailStart; + var converter = new ContainerConverter(DetailStart); if (IsGrouped()) { - BuildGroupedDetails(); + BuildGroupedDetails(converter,DetailStart); } else { - BuildSortedDetails(); + BuildSortedDetails(converter,DetailStart); } } } + - void BuildGroupedDetails () { + void BuildGroupedDetails (IContainerConverter converter,Point startPosition) { var exportRows = new List(); - var converter = new ContainerConverter(base.Graphics, CurrentLocation); - var pagePosition = DetailStart; + var pagePosition = startPosition; var sectionPosition = pagePosition; foreach (IGrouping grouping in DataSource.GroupedList) { var groupHeader = (BaseRowItem)CurrentSection.Items.Where(p => p.GetType() == typeof(GroupHeader)).FirstOrDefault(); + var sectionContainer = CreateContainerForSection(CurrentPage, pagePosition); DataSource.Fill(groupHeader.Items,grouping.FirstOrDefault()); - var sectionContainer = CreateContainerForSection(CurrentPage, pagePosition); -// Console.WriteLine("Page Position {0}",pagePosition); - var headerRow = converter.ConvertToExportContainer(groupHeader); headerRow.Location = new Point(headerRow.Location.X,groupHeader.Location.Y); @@ -102,30 +101,47 @@ namespace ICSharpCode.Reporting.PageBuilder foreach (var child in grouping) { var dataItems = CurrentSection.Items.Where(p => p.GetType() == typeof(BaseDataItem)).ToList(); - DataSource.Fill(dataItems,child); - var convertedItems = converter.CreateConvertedList(dataItems.ToList()); + List convertedItems = FillAndConvert(sectionContainer, child, dataItems, converter); AdjustLocationInSection(sectionPosition, convertedItems); - -// Console.WriteLine("section height {0} Bottom {1}",sectionContainer.Size,convertedItems[0].DisplayRectangle.Bottom); - converter.SetParent(sectionContainer, convertedItems); +/* + if (PageFull(sectionContainer)) { + InsertExportRows(exportRows); + exportRows.Clear(); + PerformPageBreak(); +// pagePosition = DetailStart; +// sectionContainer.Location = pagePosition; + } +*/ sectionContainer.ExportedItems.AddRange(convertedItems); + MeasureAndArrangeContainer(sectionContainer); exportRows.Add(sectionContainer); - sectionPosition = new Point(CurrentSection.Location.X, sectionPosition.Y + 25); - sectionContainer.Size = new Size(sectionContainer.Size.Width,convertedItems[0].Location.Y + 40); + sectionPosition = new Point(CurrentSection.Location.X, sectionPosition.Y + convertedItems[0].DisplayRectangle.Size.Height + 5); + sectionContainer.Size = new Size(sectionContainer.Size.Width,convertedItems[0].Location.Y + convertedItems[0].DisplayRectangle.Size.Height * 2); } + + MeasureAndArrangeContainer(sectionContainer); pagePosition = new Point(pagePosition.X,sectionContainer.DisplayRectangle.Bottom + 1); } InsertExportRows(exportRows); } - void AdjustLocationInSection(Point sectionPosition,List convertedItems) + List FillAndConvert(ExportContainer parent, object current, List dataItems, IContainerConverter converter) + { + DataSource.Fill(dataItems, current); + var convertedItems = converter.CreateConvertedList(dataItems.ToList()); + converter.SetParent(parent, convertedItems); + return convertedItems; + } + + + static void AdjustLocationInSection(Point sectionPosition,List convertedItems) { foreach (var element in convertedItems) { element.Location = new Point(element.Location.X, sectionPosition.Y); @@ -133,20 +149,14 @@ namespace ICSharpCode.Reporting.PageBuilder } - void BuildSortedDetails(){ + void BuildSortedDetails(IContainerConverter converter,Point startPosition){ var exportRows = new List(); - var converter = new ContainerConverter(base.Graphics, CurrentLocation); - var pagePosition = DetailStart; - + var pagePosition = startPosition; foreach (var element in DataSource.SortedList) { - var sectionContainer = CreateContainerForSection(CurrentPage, pagePosition); - DataSource.Fill(CurrentSection.Items,element); - - var convertedItems = converter.CreateConvertedList(ReportModel.DetailSection.Items); - converter.SetParent(sectionContainer, convertedItems); - + var convertedItems = FillAndConvert(sectionContainer,element,ReportModel.DetailSection.Items,converter); + if (PageFull(sectionContainer)) { InsertExportRows(exportRows); exportRows.Clear(); @@ -165,39 +175,6 @@ namespace ICSharpCode.Reporting.PageBuilder InsertExportRows(exportRows); } - /* - void old_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(){ CurrentPage.PageInfo.PageNumber = Pages.Count + 1;