Browse Source

PageBreak in Grouped Reports

reports
Peter Forstmeier 12 years ago
parent
commit
0eff7a4cab
  1. 24
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs
  2. 80
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs
  3. 18
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/SectionConverterFixture.cs
  4. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/SectionWithContainerFixture.cs
  5. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/GroupedPushModel.cs

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

@ -98,9 +98,29 @@ namespace ICSharpCode.Reporting.PageBuilder
BuildPageFooter(); BuildPageFooter();
} }
/*
protected bool PageFull (Rectangle rect) {
var sectionRect = new Rectangle(0,0,DetailsRectangle.Width,DetailsRectangle.Height);
var testRect = new Rectangle(1,rect.Location.Y,rect.Width -2,rect.Height);
if (sectionRect.Contains(testRect)) {
return false;
} else {
Console.WriteLine("PageBreak");
return true;
}
}
*/
protected bool PageFull(IExportContainer row) {
if (row.DisplayRectangle.Bottom> DetailEnds.Y) { protected bool PageFull(IExportContainer container) {
int pos;
if (container.ExportedItems.Count > 0) {
pos = container.Location.Y + container.ExportedItems.Last().Location.Y + container.ExportedItems.Last().Size.Height;
} else {
pos = container.Location.Y + container.Size.Height;
}
if (pos > DetailEnds.Y) {
return true; return true;
} }
return false; return false;

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

@ -65,10 +65,7 @@ namespace ICSharpCode.Reporting.PageBuilder
} }
void BuildGroupedDetails (IContainerConverter converter,Point startPosition) { void BuildGroupedDetails (IContainerConverter converter,Point startPosition) {
var exportRows = new List<IExportContainer>();
var pagePosition = startPosition; var pagePosition = startPosition;
var sectionPosition = pagePosition; var sectionPosition = pagePosition;
@ -89,8 +86,6 @@ namespace ICSharpCode.Reporting.PageBuilder
sectionContainer.ExportedItems.Add(headerRow); sectionContainer.ExportedItems.Add(headerRow);
exportRows.Add(sectionContainer);
pagePosition = new Point(CurrentSection.Location.X, pagePosition.Y + sectionContainer.DesiredSize.Height + 1); pagePosition = new Point(CurrentSection.Location.X, pagePosition.Y + sectionContainer.DesiredSize.Height + 1);
// Set Position Child Elements // Set Position Child Elements
@ -99,56 +94,39 @@ namespace ICSharpCode.Reporting.PageBuilder
//Childs //Childs
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();
List<IExportColumn> convertedItems = FillAndConvert(sectionContainer, child, dataItems, converter); List<IExportColumn> convertedItems = FillAndConvert(sectionContainer, child, dataItems, converter);
AdjustLocationInSection(sectionPosition, convertedItems); AdjustLocationInSection(sectionPosition, convertedItems);
/*
var rr = new Rectangle(sectionContainer.DisplayRectangle.X,sectionContainer.DisplayRectangle.Y,sectionContainer.Size.Width,
sectionContainer.Size.Height + convertedItems[0].Size.Height );
// keep this for 'KeepTogether'
// var rr = new Rectangle(sectionContainer.DisplayRectangle.X,sectionContainer.DisplayRectangle.Y,sectionContainer.Size.Width,
// sectionContainer.Size.Height + convertedItems[0].Size.Height );
// if (PageFull(rr)) {
if (PageFull(sectionContainer)) { if (PageFull(sectionContainer)) {
InsertExportRows(exportRows);
exportRows.Clear();
PerformPageBreak(); PerformPageBreak();
// pagePosition = DetailStart; InsertContainer(sectionContainer);
// sectionContainer.Location = pagePosition; pagePosition = DetailStart;
sectionContainer.Location = DetailStart;
} }
*/
sectionContainer.ExportedItems.AddRange(convertedItems); sectionContainer.ExportedItems.AddRange(convertedItems);
MeasureAndArrangeContainer(sectionContainer); MeasureAndArrangeContainer(sectionContainer);
exportRows.Add(sectionContainer);
sectionPosition = new Point(CurrentSection.Location.X, sectionPosition.Y + convertedItems[0].DisplayRectangle.Size.Height + 5); 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); sectionContainer.Size = new Size(sectionContainer.Size.Width,sectionContainer.Size.Height + convertedItems[0].Size.Height);
} }
MeasureAndArrangeContainer(sectionContainer); MeasureAndArrangeContainer(sectionContainer);
InsertContainer(sectionContainer);
pagePosition = new Point(pagePosition.X,sectionContainer.DisplayRectangle.Bottom + 1); pagePosition = new Point(pagePosition.X,sectionContainer.DisplayRectangle.Bottom + 1);
} }
InsertExportRows(exportRows);
}
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) {
element.Location = new Point(element.Location.X, sectionPosition.Y);
}
}
void BuildSortedDetails(IContainerConverter converter,Point startPosition){ void BuildSortedDetails(IContainerConverter converter,Point startPosition){
var exportRows = new List<IExportContainer>(); var exportRows = new List<IExportContainer>();
@ -191,6 +169,15 @@ namespace ICSharpCode.Reporting.PageBuilder
} }
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;
}
void CreateDataSource(){ void CreateDataSource(){
DataSource = new CollectionDataSource(List, ReportModel.ReportSettings); DataSource = new CollectionDataSource(List, ReportModel.ReportSettings);
if (DataSourceContainsData()) { if (DataSourceContainsData()) {
@ -207,12 +194,19 @@ namespace ICSharpCode.Reporting.PageBuilder
} }
Point ResetPosition () { Point ResetPosition () {
return new Point(DetailStart.X,1); return new Point(DetailStart.X,1);
} }
static void AdjustLocationInSection(Point sectionPosition,List<IExportColumn> convertedItems)
{
foreach (var element in convertedItems) {
element.Location = new Point(element.Location.X, sectionPosition.Y);
}
}
void MeasureAndArrangeContainer(IExportContainer container){ void MeasureAndArrangeContainer(IExportContainer container){
container.DesiredSize = MeasureElement(container); container.DesiredSize = MeasureElement(container);
ArrangeContainer(container); ArrangeContainer(container);
@ -225,6 +219,16 @@ namespace ICSharpCode.Reporting.PageBuilder
detail.Parent = parent; detail.Parent = parent;
return detail; return detail;
} }
void InsertContainer(ExportContainer sectionContainer)
{
if (Pages.Count == 0) {
CurrentPage.ExportedItems.Insert(2, sectionContainer);
} else {
CurrentPage.ExportedItems.Insert(1, sectionContainer);
}
}
void InsertExportRows(List<IExportContainer> list){ void InsertExportRows(List<IExportContainer> list){

18
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/SectionConverterFixture.cs

@ -22,16 +22,9 @@ namespace ICSharpCode.Reporting.Test.PageBuilder
IReportContainer container; IReportContainer container;
Graphics graphics; Graphics graphics;
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void ConverterThrowIfGraphicsEqualNull() {
var converter = new ContainerConverter(null,new Point(30,30));
}
[Test] [Test]
public void ConverterReturnExportContainer() { public void ConverterReturnExportContainer() {
var converter = new ContainerConverter(graphics,new Point(30,30)); var converter = new ContainerConverter(new Point(30,30));
var result = converter.ConvertToExportContainer(container); var result = converter.ConvertToExportContainer(container);
Assert.That(result,Is.InstanceOf(typeof(IExportContainer))); Assert.That(result,Is.InstanceOf(typeof(IExportContainer)));
} }
@ -40,7 +33,7 @@ namespace ICSharpCode.Reporting.Test.PageBuilder
[Test] [Test]
public void ConverterReturnExportContainerWithTwoItems() public void ConverterReturnExportContainerWithTwoItems()
{ {
var converter = new ContainerConverter(graphics,new Point(30,30)); var converter = new ContainerConverter(new Point(30,30));
var result = converter.ConvertToExportContainer(container); var result = converter.ConvertToExportContainer(container);
var list = converter.CreateConvertedList(container.Items); var list = converter.CreateConvertedList(container.Items);
result.ExportedItems.AddRange(list); result.ExportedItems.AddRange(list);
@ -50,16 +43,15 @@ namespace ICSharpCode.Reporting.Test.PageBuilder
[Test] [Test]
public void LocationIsAdjusted() { public void LocationIsAdjusted() {
var location = new Point(30,30); var converter = new ContainerConverter(new Point(30,30));
var converter = new ContainerConverter(graphics,location);
var result = converter.ConvertToExportContainer(container); var result = converter.ConvertToExportContainer(container);
Assert.That(result.Location,Is.EqualTo(location)); Assert.That(result.Location,Is.EqualTo(new Point(30,30)));
} }
[Test] [Test]
public void ParentInChildsIsSet () { public void ParentInChildsIsSet () {
var converter = new ContainerConverter(graphics,container.Location); var converter = new ContainerConverter(container.Location);
var convertedContainer = converter.ConvertToExportContainer(container); var convertedContainer = converter.ConvertToExportContainer(container);
var convertedList = converter.CreateConvertedList(container.Items); var convertedList = converter.CreateConvertedList(container.Items);
converter.SetParent(convertedContainer,convertedList); converter.SetParent(convertedContainer,convertedList);

4
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/SectionWithContainerFixture.cs

@ -26,7 +26,7 @@ namespace ICSharpCode.Reporting.Test.PageBuilder
[Test] [Test]
public void SectionContainsOneItemThatIsRow() { public void SectionContainsOneItemThatIsRow() {
var converter = new ContainerConverter(graphics,section.Location); var converter = new ContainerConverter(section.Location);
var list = converter.CreateConvertedList(section.Items); var list = converter.CreateConvertedList(section.Items);
Assert.That(list.Count,Is.EqualTo(1)); Assert.That(list.Count,Is.EqualTo(1));
} }
@ -34,7 +34,7 @@ namespace ICSharpCode.Reporting.Test.PageBuilder
[Test] [Test]
public void RowContainsOneItem() { public void RowContainsOneItem() {
var converter = new ContainerConverter(graphics,section.Location); var converter = new ContainerConverter(section.Location);
var list = converter.CreateConvertedList(section.Items); var list = converter.CreateConvertedList(section.Items);
var item = list[0] as ExportContainer; var item = list[0] as ExportContainer;
var text = item.ExportedItems[0]; var text = item.ExportedItems[0];

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/Reportingfactory/GroupedPushModel.cs

@ -19,7 +19,7 @@ namespace ICSharpCode.Reporting.Test.Reportingfactory
{ {
reportCreator.BuildExportList(); reportCreator.BuildExportList();
// Only a test value // Only a test value
Assert.That(reportCreator.Pages.Count,Is.EqualTo(3)); Assert.That(reportCreator.Pages.Count,Is.EqualTo(2));
} }

Loading…
Cancel
Save