Browse Source

Cleanup DataPageBuilder.cs

reports
Peter Forstmeier 12 years ago
parent
commit
d3ffbf32b9
  1. 5
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs
  2. 9
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/Converter/ContainerConverter.cs
  3. 95
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs

5
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs

@ -40,7 +40,6 @@ namespace ICSharpCode.Reporting.PageBuilder
ReportModel = reportModel; ReportModel = reportModel;
Pages = new Collection<ExportPage>(); Pages = new Collection<ExportPage>();
Graphics = CreateGraphics.FromSize(reportModel.ReportSettings.PageSize); Graphics = CreateGraphics.FromSize(reportModel.ReportSettings.PageSize);
// ExpressionVisitor = new ExpressionVisitor(ReportModel.ReportSettings,null);
} }
#region create Report Sections #region create Report Sections
@ -101,7 +100,7 @@ namespace ICSharpCode.Reporting.PageBuilder
protected bool PageFull(IExportContainer row) { protected bool PageFull(IExportContainer row) {
if (row.DisplayRectangle.Bottom > DetailEnds.Y) { if (row.DisplayRectangle.Bottom> DetailEnds.Y) {
return true; return true;
} }
return false; return false;
@ -112,7 +111,7 @@ namespace ICSharpCode.Reporting.PageBuilder
protected IExportContainer CreateSection(IReportContainer container,Point location) protected IExportContainer CreateSection(IReportContainer container,Point location)
{ {
var containerConverter = new ContainerConverter(Graphics, location); var containerConverter = new ContainerConverter(location);
var convertedContainer = containerConverter.ConvertToExportContainer(container); var convertedContainer = containerConverter.ConvertToExportContainer(container);
var list = containerConverter.CreateConvertedList(container.Items); var list = containerConverter.CreateConvertedList(container.Items);

9
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/Converter/ContainerConverter.cs

@ -22,12 +22,8 @@ namespace ICSharpCode.Reporting.PageBuilder.Converter
/// </summary> /// </summary>
class ContainerConverter : IContainerConverter class ContainerConverter : IContainerConverter
{ {
public ContainerConverter(Graphics graphics, Point currentLocation) public ContainerConverter(Point currentLocation)
{ {
if (graphics == null) {
throw new ArgumentNullException("graphics");
}
Graphics = graphics;
CurrentLocation = currentLocation; CurrentLocation = currentLocation;
} }
@ -63,9 +59,6 @@ namespace ICSharpCode.Reporting.PageBuilder.Converter
} }
} }
protected Point CurrentLocation { get; set; } protected Point CurrentLocation { get; set; }
internal Graphics Graphics {get;private set;}
} }
} }

95
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs

@ -55,31 +55,30 @@ namespace ICSharpCode.Reporting.PageBuilder
CurrentSection = ReportModel.DetailSection; CurrentSection = ReportModel.DetailSection;
if(DataSourceContainsData()) { if(DataSourceContainsData()) {
CurrentLocation = DetailStart; CurrentLocation = DetailStart;
var converter = new ContainerConverter(DetailStart);
if (IsGrouped()) { if (IsGrouped()) {
BuildGroupedDetails(); BuildGroupedDetails(converter,DetailStart);
} else { } else {
BuildSortedDetails(); BuildSortedDetails(converter,DetailStart);
} }
} }
} }
void BuildGroupedDetails () { void BuildGroupedDetails (IContainerConverter converter,Point startPosition) {
var exportRows = new List<IExportContainer>(); var exportRows = new List<IExportContainer>();
var converter = new ContainerConverter(base.Graphics, CurrentLocation); var pagePosition = startPosition;
var pagePosition = DetailStart;
var sectionPosition = pagePosition; var sectionPosition = pagePosition;
foreach (IGrouping<object, object> grouping in DataSource.GroupedList) { foreach (IGrouping<object, object> grouping in DataSource.GroupedList) {
var groupHeader = (BaseRowItem)CurrentSection.Items.Where(p => p.GetType() == typeof(GroupHeader)).FirstOrDefault(); var groupHeader = (BaseRowItem)CurrentSection.Items.Where(p => p.GetType() == typeof(GroupHeader)).FirstOrDefault();
var sectionContainer = CreateContainerForSection(CurrentPage, pagePosition);
DataSource.Fill(groupHeader.Items,grouping.FirstOrDefault()); DataSource.Fill(groupHeader.Items,grouping.FirstOrDefault());
var sectionContainer = CreateContainerForSection(CurrentPage, pagePosition);
// Console.WriteLine("Page Position {0}",pagePosition);
var headerRow = converter.ConvertToExportContainer(groupHeader); var headerRow = converter.ConvertToExportContainer(groupHeader);
headerRow.Location = new Point(headerRow.Location.X,groupHeader.Location.Y); headerRow.Location = new Point(headerRow.Location.X,groupHeader.Location.Y);
@ -102,30 +101,47 @@ namespace ICSharpCode.Reporting.PageBuilder
foreach (var child in grouping) { foreach (var child in grouping) {
var dataItems = CurrentSection.Items.Where(p => p.GetType() == typeof(BaseDataItem)).ToList(); var dataItems = CurrentSection.Items.Where(p => p.GetType() == typeof(BaseDataItem)).ToList();
DataSource.Fill(dataItems,child);
var convertedItems = converter.CreateConvertedList(dataItems.ToList()); List<IExportColumn> convertedItems = FillAndConvert(sectionContainer, child, dataItems, converter);
AdjustLocationInSection(sectionPosition, convertedItems); AdjustLocationInSection(sectionPosition, convertedItems);
/*
// Console.WriteLine("section height {0} Bottom {1}",sectionContainer.Size,convertedItems[0].DisplayRectangle.Bottom); if (PageFull(sectionContainer)) {
converter.SetParent(sectionContainer, convertedItems); InsertExportRows(exportRows);
exportRows.Clear();
PerformPageBreak();
// pagePosition = DetailStart;
// sectionContainer.Location = pagePosition;
}
*/
sectionContainer.ExportedItems.AddRange(convertedItems); sectionContainer.ExportedItems.AddRange(convertedItems);
MeasureAndArrangeContainer(sectionContainer); MeasureAndArrangeContainer(sectionContainer);
exportRows.Add(sectionContainer); exportRows.Add(sectionContainer);
sectionPosition = new Point(CurrentSection.Location.X, sectionPosition.Y + 25); 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 + 40); 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); pagePosition = new Point(pagePosition.X,sectionContainer.DisplayRectangle.Bottom + 1);
} }
InsertExportRows(exportRows); InsertExportRows(exportRows);
} }
void AdjustLocationInSection(Point sectionPosition,List<IExportColumn> convertedItems) List<IExportColumn> FillAndConvert(ExportContainer parent, object current, List<IPrintableObject> 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<IExportColumn> convertedItems)
{ {
foreach (var element in convertedItems) { foreach (var element in convertedItems) {
element.Location = new Point(element.Location.X, sectionPosition.Y); 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<IExportContainer>(); var exportRows = new List<IExportContainer>();
var converter = new ContainerConverter(base.Graphics, CurrentLocation); var pagePosition = startPosition;
var pagePosition = DetailStart;
foreach (var element in DataSource.SortedList) { foreach (var element in DataSource.SortedList) {
var sectionContainer = CreateContainerForSection(CurrentPage, pagePosition); var sectionContainer = CreateContainerForSection(CurrentPage, pagePosition);
DataSource.Fill(CurrentSection.Items,element); var convertedItems = FillAndConvert(sectionContainer,element,ReportModel.DetailSection.Items,converter);
var convertedItems = converter.CreateConvertedList(ReportModel.DetailSection.Items);
converter.SetParent(sectionContainer, convertedItems);
if (PageFull(sectionContainer)) { if (PageFull(sectionContainer)) {
InsertExportRows(exportRows); InsertExportRows(exportRows);
exportRows.Clear(); exportRows.Clear();
@ -165,39 +175,6 @@ namespace ICSharpCode.Reporting.PageBuilder
InsertExportRows(exportRows); InsertExportRows(exportRows);
} }
/*
void old_BuildSortedDetails(){
var exportRows = new List<IExportContainer>();
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; CurrentPage.PageInfo.PageNumber = Pages.Count + 1;

Loading…
Cancel
Save