From 0aac9e7333b291346ed0f669142ebe4acb090157 Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 27 Feb 2010 19:12:44 +0000 Subject: [PATCH] cleanup, remove dublicate code git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@5558 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/BaseItems/BaseTableItem.cs | 3 +- .../Project/Events/SectionRenderEventArgs.cs | 6 +- .../Project/Exporter/BasePager.cs | 2 +- .../Exporter/Converters/BaseConverter.cs | 2 +- .../Project/Printing/AbstractRenderer.cs | 191 +++++------------- .../Project/Printing/RenderDataReport.cs | 2 +- .../Project/ReportViewer/ReportViewer.cs | 2 +- 7 files changed, 57 insertions(+), 151 deletions(-) diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/BaseItems/BaseTableItem.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/BaseItems/BaseTableItem.cs index 8c9e17034e..d79dc774cf 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/BaseItems/BaseTableItem.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/BaseItems/BaseTableItem.cs @@ -86,8 +86,7 @@ namespace ICSharpCode.Reports.Core { } // Point saveLocation = this.Location; -// Point currentPosition = new Point(this.SectionBounds.DetailStart.X,rpea.LocationAfterDraw.Y); - Point currentPosition = new Point(this.startSection.Location.X,rpea.LocationAfterDraw.Y); + Point currentPosition = new Point(this.startSection.Location.X,this.startSection.Location.Y); Point tableStart = currentPosition; base.Render(rpea); int defaultLeftPos = PrintHelper.DrawingAreaRelativeToParent(this.Parent,this).Left; diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Events/SectionRenderEventArgs.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Events/SectionRenderEventArgs.cs index 780462b394..a4d7b44d0d 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Events/SectionRenderEventArgs.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Events/SectionRenderEventArgs.cs @@ -15,11 +15,11 @@ namespace ICSharpCode.Reports.Core { public class SectionRenderEventArgs:SectionEventArgs{ private int pageNumber; private int rowNumber; - private GlobalEnums.ReportSection currentSection; + private BaseSection currentSection; public SectionRenderEventArgs(BaseSection section, int pageNumber,int rowNumber, - GlobalEnums.ReportSection currentSection):base(section){ + BaseSection currentSection):base(section){ this.pageNumber = pageNumber; this.currentSection = currentSection; @@ -40,7 +40,7 @@ namespace ICSharpCode.Reports.Core { } - public GlobalEnums.ReportSection CurrentSection { + public BaseSection CurrentSection { get { return currentSection; } diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/BasePager.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/BasePager.cs index 75191b998d..9797898d3d 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/BasePager.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/BasePager.cs @@ -233,7 +233,7 @@ namespace ICSharpCode.Reports.Core.Exporter new SectionRenderEventArgs(section, pages.Count, currentRow, - (GlobalEnums.ReportSection)GlobalEnums.ReportSection.Parse(typeof(GlobalEnums.ReportSection),section.Name)); + section); EventHelper.Raise(SectionRendering,this,ea); } diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/Converters/BaseConverter.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/Converters/BaseConverter.cs index 3838901c4e..6e000debcc 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/Converters/BaseConverter.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Exporter/Converters/BaseConverter.cs @@ -66,7 +66,7 @@ namespace ICSharpCode.Reports.Core.Exporter SectionRenderEventArgs srea = new SectionRenderEventArgs(section, this.SinglePage.PageNumber, this.dataNavigator.CurrentRow, - (GlobalEnums.ReportSection)GlobalEnums.ReportSection.Parse(typeof(GlobalEnums.ReportSection),section.Name)); + section); EventHelper.Raise(SectionRendering,this,srea); } diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/AbstractRenderer.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/AbstractRenderer.cs index 6ec64049aa..cd67fb50bf 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/AbstractRenderer.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/AbstractRenderer.cs @@ -33,20 +33,19 @@ namespace ICSharpCode.Reports.Core private ReportSectionCollection sections; private ReportSettings reportSettings; - private int sectionInUse; - private int currentRow; - private int currentPageNumber; + private int currentPageNumber; - private SectionBounds sectionBounds; - private bool cancel; private IExpressionEvaluatorFacade expressionFassade; + private ILayouter layout; + private IReportModel reportModel; + public event EventHandler Rendering; public event EventHandler SectionRendered; - private ILayouter layout; - protected AbstractRenderer(IReportModel model,ReportDocument reportDocument,ILayouter layout) + + protected AbstractRenderer(IReportModel reportModel,ReportDocument reportDocument,ILayouter layout) { - if (model == null) { + if (reportModel == null) { throw new MissingModelException(); } if (reportDocument == null) { @@ -55,22 +54,27 @@ namespace ICSharpCode.Reports.Core if (layout == null) { throw new ArgumentNullException("layout"); } - this.reportSettings = model.ReportSettings; + this.reportModel = reportModel; + this.reportSettings = reportModel.ReportSettings; this.reportDocument = reportDocument; this.layout = layout; - this.sections = model.SectionCollection; + this.sections = reportModel.SectionCollection; Init(); } - void Init() + private void Init() { this.reportDocument.DocumentName = reportSettings.ReportName; // Events from ReportDocument this.reportDocument.QueryPageSettings += new QueryPageSettingsEventHandler (ReportQueryPage); this.reportDocument.BeginPrint += new PrintEventHandler(ReportBegin); - this.reportDocument.PrintPage += new PrintPageEventHandler(ReportPageStart); + + this.reportDocument.PrintPage += delegate(object sender,PrintPageEventArgs e){ + this.CalculatePageBounds (); + }; + this.reportDocument.EndPrint += new PrintEventHandler(ReportEnd); // homemade events @@ -109,21 +113,20 @@ namespace ICSharpCode.Reports.Core if (this.Rendering != null) { SectionRenderEventArgs ea = new SectionRenderEventArgs (e.Section, this.currentPageNumber, - this.currentRow, - (GlobalEnums.ReportSection)this.sectionInUse); + this.CurrentRow, + this.CurrentSection); this.Rendering(this,ea); - } + } } - private void OnSectionPrinted (object sender,SectionEventArgs e) + private void OnSectionPrinted (object sender,SectionEventArgs e) { if (this.SectionRendered != null) { SectionRenderEventArgs ea = new SectionRenderEventArgs (e.Section, this.currentPageNumber, - this.currentRow, - (GlobalEnums.ReportSection)this.sectionInUse); - + this.CurrentRow, + this.CurrentSection); this.SectionRendered(this,ea); } } @@ -135,59 +138,53 @@ namespace ICSharpCode.Reports.Core internal virtual void PrintReportHeader (object sender, ReportPageEventArgs rpea) { - SectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportHeader, - CultureInfo.InvariantCulture); + this.CurrentSection = this.reportModel.ReportHeader; this.AddSectionEvents(); } internal virtual void PrintPageHeader (object sender, ReportPageEventArgs rpea) { - SectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportPageHeader, - CultureInfo.InvariantCulture); + this.CurrentSection = this.reportModel.PageHeader; this.AddSectionEvents(); } internal virtual void BodyStart (object sender,ReportPageEventArgs rpea) { - this.SectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportDetail, - CultureInfo.InvariantCulture); - + this.CurrentSection = this.reportModel.DetailSection; } internal virtual void PrintDetail (object sender,ReportPageEventArgs rpea) { - SectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportDetail, - CultureInfo.InvariantCulture); + this.CurrentSection = this.reportModel.DetailSection; this.AddSectionEvents(); } internal virtual void BodyEnd (object sender,ReportPageEventArgs rpea) { - this.SectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportFooter, - CultureInfo.InvariantCulture); + this.CurrentSection = this.reportModel.ReportFooter; } + internal virtual void PrintPageEnd (object sender,ReportPageEventArgs rpea) { - SectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportPageFooter, - CultureInfo.InvariantCulture); + this.CurrentSection = this.reportModel.ReportFooter; this.AddSectionEvents(); } internal virtual void PrintReportFooter (object sender,ReportPageEventArgs rpea) { - SectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportFooter, - CultureInfo.InvariantCulture); + this.CurrentSection = this.reportModel.ReportFooter; this.AddSectionEvents(); } + #endregion - public static void PageBreak(ReportPageEventArgs pea) + public static void PageBreak(ReportPageEventArgs pea) { if (pea == null) { throw new ArgumentNullException("pea"); @@ -203,9 +200,9 @@ namespace ICSharpCode.Reports.Core throw new ArgumentNullException("e"); } e.Graphics.DrawString(this.reportSettings.NoDataMessage, - this.ReportSettings.DefaultFont, - new SolidBrush(Color.Black), - sectionBounds.DetailArea); + this.ReportSettings.DefaultFont, + new SolidBrush(Color.Black), + this.SectionBounds.DetailArea); } @@ -265,47 +262,12 @@ namespace ICSharpCode.Reports.Core private void CalculatePageBounds () { - sectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportHeader, - CultureInfo.InvariantCulture); - sectionBounds.MeasureReportHeader(this.CurrentSection); - - //PageHeader - sectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportPageHeader, - CultureInfo.InvariantCulture); - this.sectionBounds.MeasurePageHeader(this.CurrentSection); - - //Detail - sectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportDetail, - CultureInfo.InvariantCulture); - sectionBounds.DetailSectionRectangle = new Rectangle(this.CurrentSection.Location,this.CurrentSection.Size); - - //PageFooter - sectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportPageFooter, - CultureInfo.InvariantCulture); - this.sectionBounds.MeasurePageFooter (this.CurrentSection); - - //ReportFooter - sectionInUse = Convert.ToInt16(GlobalEnums.ReportSection.ReportFooter, - CultureInfo.InvariantCulture); - this.sectionBounds.MeasureReportFooter(this.CurrentSection); - this.sectionBounds.MeasureDetailArea(); - - } - - - private void ReportPageStart (object sender, PrintPageEventArgs ppea) - { - System.Diagnostics.Trace.WriteLine("ReportPageStart"); - if (this.sectionBounds == null) { - throw new ArgumentException("page"); - } - this.CalculatePageBounds (); + this.SinglePage.CalculatePageBounds(this.reportModel); } internal virtual void ReportQueryPage (object sender,QueryPageSettingsEventArgs qpea) { - qpea.PageSettings.Margins = new Margins(reportSettings.LeftMargin,reportSettings.RightMargin,reportSettings.TopMargin,reportSettings.BottomMargin); bool firstPage; if (this.currentPageNumber == 0) { @@ -313,9 +275,8 @@ namespace ICSharpCode.Reports.Core } else { firstPage = false; } - this.sectionBounds = new SectionBounds (reportSettings,firstPage); this.currentPageNumber ++; - ISinglePage sp = new SinglePage(this.sectionBounds,0); + ISinglePage sp = new SinglePage(new SectionBounds (reportSettings,firstPage),0); PrintHelper.InitPage(sp,this.reportSettings); sp.PageNumber = this.currentPageNumber; reportDocument.SinglePage = sp; @@ -334,90 +295,36 @@ namespace ICSharpCode.Reports.Core #endregion - #region property's - public ReportDocument ReportDocument - { - get { - return reportDocument; - } - } - + public ReportDocument ReportDocument {get {return this.reportDocument;}} - public ReportSettings ReportSettings - { - get { - return reportSettings; - } - } + public ReportSettings ReportSettings {get {return reportSettings;}} - public ReportSectionCollection Sections - { - get { - return sections; - } - } + public ReportSectionCollection Sections {get {return this.sections;}} - public bool Cancel - { - get { - return cancel; - } - set { - cancel = value; - } - } - public ISinglePage SinglePage { - get { return this.reportDocument.SinglePage; } - } + public bool Cancel {get;set;} - protected int SectionInUse - { - get { - return sectionInUse; - } - set { - sectionInUse = value; - } - } + public ISinglePage SinglePage {get { return this.reportDocument.SinglePage; }} + + protected int CurrentRow {get;set;} - protected int CurrentRow { - get { return currentRow; } - set { currentRow = value; } - } + protected BaseSection CurrentSection {get;set;} - protected BaseSection CurrentSection - { - get { - return (BaseSection)sections[sectionInUse]; - } - } + protected SectionBounds SectionBounds { get {return this.SinglePage.SectionBounds;}} - protected SectionBounds SectionBounds - { - get { - return sectionBounds; - } - set { - sectionBounds = value; - } - } - - protected IExpressionEvaluatorFacade ExpressionFassade { - get { return expressionFassade; } - } + protected IExpressionEvaluatorFacade ExpressionFassade {get { return expressionFassade; }} + - protected ILayouter Layout - {get {return this.layout;}} + protected ILayouter Layout {get {return this.layout;}} #endregion diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/RenderDataReport.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/RenderDataReport.cs index ff4681266e..bd7aed0854 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/RenderDataReport.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/Printing/RenderDataReport.cs @@ -160,7 +160,7 @@ namespace ICSharpCode.Reports.Core { if (rpea.SinglePage.PageNumber == 1) { tableContainer.StartLayoutAt(base.Sections[2]); } else { - tableContainer.StartLayoutAt(base.Sections[1]); + tableContainer.StartLayoutAt(base.Sections[0]); } tableContainer.RenderTable(base.CurrentSection,this.SectionBounds,rpea,this.Layout); diff --git a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/ReportViewer/ReportViewer.cs b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/ReportViewer/ReportViewer.cs index 8d2d16d012..a00e8e9b9a 100644 --- a/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/ReportViewer/ReportViewer.cs +++ b/src/AddIns/Misc/SharpReport/ICSharpCode.Reports.Core/Project/ReportViewer/ReportViewer.cs @@ -233,7 +233,7 @@ namespace ICSharpCode.Reports.Core.ReportViewer } private void PushPrinting (object sender, SectionRenderEventArgs e ) { -// Console.WriteLine ("ReportViewer - SectionRenderEventargs from <{0}> with {1} items ",e.Section.Name,e.Section.Items.Count); + Console.WriteLine ("ReportViewer - SectionRenderEventargs from <{0}> with {1} item ",e.Section.Name,e.Section.Items.Count); EventHelper.Raise(SectionRendering,this,e); }