Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/reports@5839 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61pull/1/head
12 changed files with 684 additions and 22 deletions
@ -0,0 +1,57 @@
@@ -0,0 +1,57 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 21.05.2010 |
||||
* Time: 19:35 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Collections; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Exporter.Converter |
||||
{ |
||||
|
||||
public interface IItemsConverter |
||||
{ |
||||
ReportItemCollection Convert (BaseReportItem parent,IEnumerable<BaseReportItem> itemsSource); |
||||
Point LocationAfterConvert {get;} |
||||
} |
||||
|
||||
|
||||
/// <summary>
|
||||
/// Description of ItemsConverterr.
|
||||
/// </summary>
|
||||
|
||||
|
||||
public class ItemsConverter:IItemsConverter |
||||
{ |
||||
Point locationAfterConvert; |
||||
|
||||
|
||||
|
||||
public ItemsConverter() |
||||
{ |
||||
} |
||||
|
||||
|
||||
public ReportItemCollection Convert (BaseReportItem parent,IEnumerable<BaseReportItem> itemsSource) |
||||
{ |
||||
var col = new ReportItemCollection(); |
||||
foreach (BaseReportItem element in itemsSource) { |
||||
|
||||
col.Add(element); |
||||
} |
||||
this.locationAfterConvert = new Point(parent.Size.Width,parent.Size.Height); |
||||
return col; |
||||
} |
||||
|
||||
|
||||
public Point LocationAfterConvert { |
||||
get { return locationAfterConvert; } |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,225 @@
@@ -0,0 +1,225 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 15.05.2010 |
||||
* Time: 18:21 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Collections.ObjectModel; |
||||
using System.Drawing; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.Reports.Core.Interfaces; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Exporter |
||||
{ |
||||
/// <summary>
|
||||
/// Description of BuildExportList.
|
||||
/// </summary>
|
||||
public class DataExportListBuilder:AbstractExportListBuilder |
||||
{ |
||||
|
||||
|
||||
public DataExportListBuilder(IReportModel reportModel,IDataManager dataManager):base(reportModel) |
||||
{ |
||||
this.DataManager = dataManager; |
||||
this.DataManager.GetNavigator.MoveNext(); |
||||
} |
||||
|
||||
|
||||
public override void WritePages () |
||||
{ |
||||
base.CreateNewPage(); |
||||
|
||||
base.PositionAfterRenderSection = this.BuildReportHeader(SinglePage.SectionBounds.ReportHeaderRectangle.Location); |
||||
|
||||
this.BuildPageHeader(); |
||||
|
||||
// BaseSection section = base.ReportModel.DetailSection;
|
||||
//
|
||||
// section.SectionOffset = base.SinglePage.SectionBounds.DetailStart.Y;
|
||||
// this.BuildDetail (section,dataNavigator);
|
||||
//
|
||||
// this.BuildReportFooter(SectionBounds.ReportFooterRectangle);
|
||||
// this.BuildPageFooter();
|
||||
// //this is the last Page
|
||||
this.AddPage(base.SinglePage); |
||||
//base.FinishRendering(this.dataNavigator);
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
public IDataManager DataManager {get; private set;} |
||||
|
||||
} |
||||
|
||||
public class PageDescriptions :Collection<PageDescription> |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
public class AbstractExportListBuilder |
||||
{ |
||||
|
||||
private PageDescriptions pages; |
||||
private readonly object pageLock = new object(); |
||||
|
||||
|
||||
public AbstractExportListBuilder (IReportModel reportModel) |
||||
{ |
||||
this.ReportModel = reportModel; |
||||
} |
||||
|
||||
|
||||
public virtual void WritePages () |
||||
{ |
||||
|
||||
} |
||||
|
||||
|
||||
private ReportItemCollection ConvertContainer (ISimpleContainer container) |
||||
{ |
||||
var col = new ReportItemCollection(); |
||||
foreach (BaseReportItem element in container.Items) |
||||
{ |
||||
col.Add(element); |
||||
} |
||||
return col; |
||||
} |
||||
|
||||
|
||||
|
||||
private void ConvertSimpleItems (IEnumerable<BaseReportItem> items) |
||||
{ |
||||
foreach (BaseReportItem element in items) { |
||||
var container = element as ISimpleContainer; |
||||
|
||||
if (container != null) { |
||||
Console.WriteLine(" is recursive"); |
||||
container.Items.AddRange(ConvertContainer (container)); |
||||
} |
||||
|
||||
this.SinglePage.Items.Add(element); |
||||
} |
||||
} |
||||
|
||||
|
||||
private bool CanGrow (IEnumerable<BaseReportItem> collection) |
||||
{ |
||||
IEnumerable<BaseReportItem> canGrowShrinkCollection = from bt in collection where bt.CanGrow == true select bt; |
||||
return (canGrowShrinkCollection.Count() > 0); |
||||
} |
||||
|
||||
|
||||
private bool CanShrink (IEnumerable<BaseReportItem> collection) |
||||
{ |
||||
IEnumerable<BaseReportItem> canGrowShrinkCollection = from bt in collection where bt.CanShrink == true select bt; |
||||
return (canGrowShrinkCollection.Count() > 0); |
||||
} |
||||
|
||||
|
||||
|
||||
protected virtual Point BuildReportHeader (Point reportHeaderStart) |
||||
{ |
||||
System.Console.WriteLine("BuildReportHeader at {0} with {1} items ",reportHeaderStart,ReportModel.ReportHeader.Items.Count); |
||||
|
||||
BaseSection section = ReportModel.ReportHeader; |
||||
Size size = section.Size; |
||||
Point retval = Point.Empty; |
||||
|
||||
if ((!CanGrow(section.Items)) | (!CanShrink(section.Items))) { |
||||
ConvertSimpleItems (section.Items); |
||||
retval = new Point (reportHeaderStart.X , reportHeaderStart.Y + size.Height); |
||||
} else { |
||||
retval = new Point (reportHeaderStart.X , 150); |
||||
} |
||||
|
||||
return retval; |
||||
} |
||||
|
||||
|
||||
|
||||
protected virtual void BuildPageHeader () |
||||
{ |
||||
// System.Diagnostics.Trace.WriteLine(" BuildPageHeader");
|
||||
// PositionAfterRenderSection = new Point(PositionAfterRenderSection.X,PositionAfterRenderSection.Y + 20);
|
||||
} |
||||
|
||||
|
||||
protected virtual void BuildDetailInternal (BaseSection section) |
||||
{ |
||||
System.Diagnostics.Trace.WriteLine("BuildDetailInterna "); |
||||
} |
||||
|
||||
|
||||
protected virtual void BuildPageFooter () |
||||
{ |
||||
System.Diagnostics.Trace.WriteLine("BuildPageFooter "); |
||||
} |
||||
|
||||
protected virtual void BuildReportFooter () |
||||
{ |
||||
System.Diagnostics.Trace.WriteLine("BuildReportFooter "); |
||||
} |
||||
|
||||
|
||||
public virtual void CreateNewPage () |
||||
{ |
||||
this.SinglePage = this.InitNewPage(); |
||||
PrintHelper.InitPage(this.SinglePage,this.ReportModel.ReportSettings); |
||||
this.SinglePage.CalculatePageBounds(this.ReportModel); |
||||
// this.pageFull = false;
|
||||
} |
||||
|
||||
public Point PositionAfterRenderSection {get;set;} |
||||
|
||||
|
||||
protected PageDescription InitNewPage () |
||||
{ |
||||
SectionBounds sectionBounds = new SectionBounds (ReportModel.ReportSettings,(this.Pages.Count == 0)); |
||||
return new PageDescription(sectionBounds,Pages.Count + 1); |
||||
} |
||||
|
||||
|
||||
|
||||
protected void AddPage (PageDescription page) |
||||
{ |
||||
if (page == null) { |
||||
throw new ArgumentNullException("page"); |
||||
} |
||||
// lock (addLock) {
|
||||
Pages.Add(page); |
||||
|
||||
// }
|
||||
//FirePageCreated(page);
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public PageDescription SinglePage {get;private set;} |
||||
|
||||
public IReportModel ReportModel {get;private set;} |
||||
|
||||
|
||||
public PageDescriptions Pages |
||||
{ |
||||
get { |
||||
lock(pageLock) { |
||||
if (this.pages == null) { |
||||
pages = new PageDescriptions(); |
||||
|
||||
} |
||||
return pages; |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
} |
||||
@ -0,0 +1,52 @@
@@ -0,0 +1,52 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 16.05.2010 |
||||
* Time: 19:06 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
using System; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Exporter |
||||
{ |
||||
/// <summary>
|
||||
/// Description of PageDescription.
|
||||
/// </summary>
|
||||
|
||||
|
||||
public class PageDescription:SinglePage |
||||
{ |
||||
|
||||
private ReportItemCollection items; |
||||
|
||||
|
||||
public PageDescription (SectionBounds sectionBounds,int pageNumber):base(sectionBounds,pageNumber) |
||||
{ |
||||
if (sectionBounds == null) { |
||||
throw new ArgumentNullException("sectionBounds"); |
||||
} |
||||
this.SectionBounds = sectionBounds; |
||||
} |
||||
|
||||
public ReportItemCollection Items |
||||
{ |
||||
get { |
||||
if (this.items == null) { |
||||
this.items = new ReportItemCollection(); |
||||
} |
||||
return this.items; |
||||
} |
||||
} |
||||
|
||||
// public ExporterCollection Items
|
||||
// {
|
||||
// get {
|
||||
// if (this.items == null) {
|
||||
// items = new ExporterCollection();
|
||||
// }
|
||||
// return items;
|
||||
// }
|
||||
// }
|
||||
} |
||||
} |
||||
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 21.05.2010 |
||||
* Time: 19:44 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using ICSharpCode.Reports.Core.Exporter.Converter; |
||||
using ICSharpCode.Reports.Core.Test.TestHelpers; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Test.Exporter.Converter |
||||
{ |
||||
[TestFixture] |
||||
public class ItemsConverterFixture:ConcernOf<ItemsConverter> |
||||
{ |
||||
[Test] |
||||
public void ConvertSimpleItem() |
||||
{ |
||||
BaseSection section = new BaseSection(); |
||||
section.Items.Add(CreateSimpeTextItem()); |
||||
Point point = new Point(1,1); |
||||
ReportItemCollection result = Sut.Convert (section,section.Items); |
||||
Assert.AreEqual(new Point(section.Size.Width,section.Size.Height),Sut.LocationAfterConvert); |
||||
Assert.AreEqual(1,result.Count); |
||||
|
||||
} |
||||
|
||||
|
||||
private BaseReportItem CreateSimpeTextItem () |
||||
{ |
||||
BaseTextItem bt = new BaseTextItem(); |
||||
bt.Text = "MyText"; |
||||
return bt; |
||||
} |
||||
|
||||
|
||||
public override void Setup() |
||||
{ |
||||
Sut = new ItemsConverter(); |
||||
} |
||||
|
||||
|
||||
|
||||
[TestFixtureSetUp] |
||||
public void Init() |
||||
{ |
||||
// TODO: Add Init code.
|
||||
} |
||||
|
||||
[TestFixtureTearDown] |
||||
public void Dispose() |
||||
{ |
||||
// TODO: Add tear down code.
|
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,122 @@
@@ -0,0 +1,122 @@
|
||||
/* |
||||
* Created by SharpDevelop. |
||||
* User: Peter Forstmeier |
||||
* Date: 15.05.2010 |
||||
* Time: 18:29 |
||||
* |
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers. |
||||
*/ |
||||
|
||||
using System; |
||||
using System.Drawing; |
||||
using ICSharpCode.Reports.Core.Exporter; |
||||
using ICSharpCode.Reports.Core.Interfaces; |
||||
using ICSharpCode.Reports.Core.Project.Interfaces; |
||||
using ICSharpCode.Reports.Core.Test.TestHelpers; |
||||
using NUnit.Framework; |
||||
|
||||
namespace ICSharpCode.Reports.Core.Test.Exporter |
||||
{ |
||||
[TestFixture] |
||||
public class DataListBuilderFixture:ConcernOf<DataExportListBuilder> |
||||
{ |
||||
ReportModel reportModel; |
||||
|
||||
[Test] |
||||
public void Can_Create_ExportListBuilder() |
||||
{ |
||||
ReportSettings rs = new ReportSettings(); |
||||
rs.ConnectionString = "goodConnection"; |
||||
|
||||
IDataAccessStrategy da = new MockDataAccessStrategy (rs); |
||||
IDataManager dataManager = ICSharpCode.Reports.Core.DataManager.CreateInstance(rs,da); |
||||
|
||||
var reportModel = ReportModel.Create(); |
||||
|
||||
DataExportListBuilder sut = new DataExportListBuilder(reportModel,dataManager); |
||||
Assert.IsNotNull(sut); |
||||
IDataNavigator n = sut.DataManager.GetNavigator; |
||||
Assert.AreEqual(0,sut.DataManager.GetNavigator.CurrentRow); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void PagesCollection_Should_Be_Not_Null() |
||||
{ |
||||
Sut.WritePages(); |
||||
Assert.IsNotNull(Sut.Pages); |
||||
Assert.AreEqual(1,Sut.Pages.Count); |
||||
|
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void Pagenumber_Should_Be_One() |
||||
{ |
||||
Sut.WritePages(); |
||||
Assert.AreEqual(1,Sut.Pages.Count); |
||||
Assert.AreEqual(1,Sut.Pages[0].PageNumber); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void LocPos() |
||||
{ |
||||
Sut.WritePages(); |
||||
Point retVal = new Point (50,50 + reportModel.ReportHeader.Size.Height); |
||||
Assert.AreEqual(retVal.Y,Sut.PositionAfterRenderSection.Y); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void Add_One_Item_In_ReportHeader() |
||||
{ |
||||
var item = CreateSimpeTextItem(); |
||||
reportModel.ReportHeader.Items.Add(item); |
||||
Sut.WritePages(); |
||||
BaseReportItem it = Sut.Pages[0].Items[0]; |
||||
Assert.IsNotNull(it); |
||||
Assert.AreEqual(1,Sut.Pages[0].Items.Count); |
||||
} |
||||
|
||||
|
||||
[Test] |
||||
public void Add_Container_In_ReportHeader() |
||||
{ |
||||
BaseRowItem row = new BaseRowItem() { |
||||
Location = new Point (5,5) |
||||
}; |
||||
row.Items.Add(CreateSimpeTextItem()); |
||||
reportModel.ReportHeader.Items.Add(row); |
||||
Sut.WritePages(); |
||||
Assert.AreEqual(1,Sut.Pages[0].Items.Count); |
||||
var checkRow = Sut.Pages[0].Items[0]; |
||||
Assert.IsAssignableFrom(typeof(BaseRowItem),checkRow); |
||||
|
||||
BaseReportItem checkItem = ((BaseRowItem)checkRow).Items[0]; |
||||
Assert.IsNotNull(checkItem); |
||||
} |
||||
|
||||
|
||||
private BaseReportItem CreateSimpeTextItem () |
||||
{ |
||||
BaseTextItem bt = new BaseTextItem(); |
||||
bt.Text = "MyText"; |
||||
return bt; |
||||
} |
||||
|
||||
public override void Setup() |
||||
{ |
||||
ReportSettings rs = new ReportSettings(); |
||||
rs.ConnectionString = "goodConnection"; |
||||
|
||||
IDataAccessStrategy da = new MockDataAccessStrategy (rs); |
||||
IDataManager dataManager = ICSharpCode.Reports.Core.DataManager.CreateInstance(rs,da); |
||||
|
||||
reportModel = ReportModel.Create(); |
||||
|
||||
Sut = new DataExportListBuilder(reportModel,dataManager); |
||||
} |
||||
|
||||
} |
||||
} |
||||
Loading…
Reference in new issue