Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit c56fbe5

Browse files
BasePageBuilder fires 'SectionEvent' to modify Items at runtime
1 parent cf9c74a commit c56fbe5

10 files changed

Lines changed: 76 additions & 24 deletions

File tree

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="Src\DataSource\PropertyPath.cs" />
103103
<Compile Include="Src\DataSource\PropertyTypeHash.cs" />
104104
<Compile Include="Src\DataSource\ReflectionExtension.cs" />
105+
<Compile Include="Src\Events\SectionEvent.cs" />
105106
<Compile Include="Src\Exporter\BaseExporter.cs" />
106107
<Compile Include="Src\Exporter\DebugExporter.cs" />
107108
<Compile Include="Src\Exporter\Visitors\ExpressionVisitor.cs" />
@@ -207,6 +208,7 @@
207208
<Folder Include="Src\DataManager\Listhandling" />
208209
<Folder Include="Src\Expressions" />
209210
<Folder Include="Src\Items\Graphics" />
211+
<Folder Include="Src\Events" />
210212
<Folder Include="Src\Pdf" />
211213
<Folder Include="Src\Wpf" />
212214
<Folder Include="Src\PageBuilder" />
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Created by SharpDevelop.
3+
* User: Peter Forstmeier
4+
* Date: 05.02.2014
5+
* Time: 20:33
6+
*
7+
* To change this template use Tools | Options | Coding | Edit Standard Headers.
8+
*/
9+
using System;
10+
using ICSharpCode.Reporting.Interfaces;
11+
12+
namespace ICSharpCode.Reporting
13+
{
14+
/// <summary>
15+
/// Description of SectionEvent.
16+
/// </summary>
17+
public class SectionEventArgs : EventArgs
18+
{
19+
20+
21+
public SectionEventArgs(IReportContainer section){
22+
if (section == null)
23+
throw new ArgumentNullException("section");
24+
Section = section;
25+
}
26+
27+
public IReportContainer Section {get;private set;}
28+
29+
}
30+
}

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportCreator.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
// DEALINGS IN THE SOFTWARE.
1818

1919
using System;
20-
using System.Collections.Generic;
2120
using System.Collections.ObjectModel;
2221

23-
using ICSharpCode.Reporting.BaseClasses;
24-
using ICSharpCode.Reporting.Interfaces.Export;
2522
using ICSharpCode.Reporting.PageBuilder.ExportColumns;
2623

2724
namespace ICSharpCode.Reporting.Interfaces
@@ -33,7 +30,7 @@ public interface IReportCreator
3330
{
3431
void BuildExportList ();
3532
Collection<ExportPage> Pages {get;}
36-
33+
event EventHandler<SectionEventArgs> SectionRendering;
3734
// PagesCollection Pages{get;}
3835
// event EventHandler<PageCreatedEventArgs> PageCreated;
3936
// event EventHandler<SectionRenderEventArgs> SectionRendering;

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportModel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,7 @@ public interface IReportModel
3131
{
3232
ReportSettings ReportSettings {get;set;}
3333
Collection<BaseSection> SectionCollection {get;}
34-
/*
35-
ISection ReportHeader {get;}
36-
ISection PageHeader {get;}
37-
ISection DetailSection {get;}
38-
ISection PageFooter {get;}
39-
ISection ReportFooter {get;}
4034

41-
GlobalEnums.PushPullModel DataModel {get;}
42-
*/
4335
IReportContainer ReportHeader {get;}
4436
IReportContainer PageHeader {get;}
4537
IReportContainer DetailSection {get;}

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace ICSharpCode.Reporting.PageBuilder
3939
/// </summary>
4040
public class BasePageBuilder:IReportCreator
4141
{
42+
43+
public event EventHandler<SectionEventArgs> SectionRendering;
4244

4345
public BasePageBuilder(IReportModel reportModel){
4446
if (reportModel == null) {
@@ -53,14 +55,29 @@ public BasePageBuilder(IReportModel reportModel){
5355

5456
void BuildReportHeader(){
5557
if (Pages.Count == 0) {
56-
var header = CreateSection(ReportModel.ReportHeader,CurrentLocation);
58+
var sea = new SectionEventArgs(ReportModel.ReportHeader);
59+
60+
Raise<SectionEventArgs> (SectionRendering,this,sea);
61+
62+
var header = CreateSection(sea.Section,CurrentLocation);
63+
5764
var r = new Rectangle(header.Location.X, header.Location.Y, header.Size.Width, header.Size.Height);
5865
CurrentLocation = new Point (ReportModel.ReportSettings.LeftMargin,r.Bottom + 1);
5966
AddSectionToPage(header);
67+
Raise<SectionEventArgs> (SectionRendering,this,new SectionEventArgs(ReportModel.ReportHeader));
6068
}
6169
}
6270

71+
protected static void Raise <T>(EventHandler<T> handler, object sender, T e)
72+
where T: EventArgs{
73+
// Copy to a temporary variable to be thread-safe.
74+
EventHandler<T> temp = handler;
6375

76+
if (temp != null) {
77+
temp(sender, e);
78+
}
79+
}
80+
6481
void BuildPageHeader(){
6582
var pageHeader = CreateSection(ReportModel.PageHeader,CurrentLocation);
6683
DetailStart = new Point(ReportModel.ReportSettings.LeftMargin,pageHeader.Location.Y + pageHeader.DesiredSize.Height +1);
@@ -85,6 +102,8 @@ void AddSectionToPage(IExportContainer header){
85102
}
86103

87104

105+
106+
88107
protected void BuildReportFooter(){
89108
var lastSection = CurrentPage.ExportedItems.Last();
90109
CurrentLocation = new Point(ReportModel.ReportSettings.LeftMargin,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ namespace ICSharpCode.Reporting.PageBuilder
3535
/// <summary>
3636
/// Description of DataPageBuilder.
3737
/// </summary>
38+
3839
public class DataPageBuilder:BasePageBuilder
3940
{
4041

42+
4143
public DataPageBuilder(IReportModel reportModel,IEnumerable list):base(reportModel)
4244
{
4345
List = list;

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ namespace ICSharpCode.Reporting
3434
public class ReportingFactory
3535
{
3636

37+
void Method(object s,EventArgs e)
38+
{
39+
Console.WriteLine("Got Event {0}",s.ToString());
40+
}
41+
3742
public IReportCreator ReportCreator (Stream stream,IEnumerable list)
3843
{
3944
ReportModel = LoadReportModel (stream);
40-
IReportCreator builder = null;
41-
builder = new DataPageBuilder(ReportModel,list );
45+
var builder = new DataPageBuilder(ReportModel,list );
46+
4247
return builder;
4348
}
4449

@@ -57,6 +62,7 @@ public IReportCreator ReportCreator (Stream stream)
5762
{
5863
ReportModel = LoadReportModel (stream);
5964
var builder = new FormPageBuilder(ReportModel);
65+
builder.SectionRendering += (sender, e) => Method(sender, e);
6066
return builder;
6167
}
6268

src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/BaseConvertFixture.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System;
2020
using System.Reflection;
2121
using ICSharpCode.Reporting.Interfaces;
22+
using ICSharpCode.Reporting.Items;
2223
using ICSharpCode.Reporting.PageBuilder.ExportColumns;
2324
using NUnit.Framework;
2425

@@ -56,6 +57,16 @@ public void ExportContainerContainsExportText() {
5657
}
5758

5859

60+
[Test]
61+
public void testeventt() {
62+
reportCreator.SectionRendering += (sender, e) => {
63+
Console.WriteLine("Hi with from {0} with {1}",e.ToString(),e.Section.Name);
64+
((BaseTextItem)e.Section.Items[0]).Text = "hallo";
65+
};
66+
reportCreator.BuildExportList();
67+
68+
}
69+
5970
[SetUp]
6071
public void LoadFromStream()
6172
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void ParentInChildsIsSet () {
7171
}
7272
}
7373

74-
74+
7575
[SetUp]
7676
public void Init()
7777
{

src/AddIns/Misc/Reports/ICSharpCode.Reports.Core/Project/Events/PrintEventArgs.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,7 @@
2020
using System.Drawing;
2121

2222

23-
/// <summary>
24-
/// Handles BeforPrint and AfterPrint Events
25-
/// </summary>
26-
/// <remarks>
27-
/// created by - Forstmeier Peter
28-
/// created on - 22.11.2004 13:06:44
29-
/// </remarks>
30-
23+
3124
namespace ICSharpCode.Reports.Core {
3225

3326
public class SectionEventArgs : EventArgs

0 commit comments

Comments
 (0)