From 4a4ef4bfcbddefdd7939cca6b438ab756cb3374f Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sat, 6 Apr 2013 20:25:50 +0200 Subject: [PATCH] Sections in ReportModel.cs --- .../ICSharpCode.Reporting.csproj | 5 ++ .../Src/BaseClasses/Page.cs | 23 +++++++- .../Src/BaseClasses/PageInfo.cs | 59 +++++++++++++++++++ .../Src/Factories/SectionFactory.cs | 30 ++++++++++ .../Src/Globals/GlobalEnums.cs | 14 ++++- .../Src/Globals/GlobalValues.cs | 6 ++ .../Src/Interfaces/IReportCreator.cs | 1 + .../Src/Interfaces/IReportItem.cs | 29 +++++++++ .../Src/Interfaces/IReportModel.cs | 6 +- .../Src/Items/BaseSection.cs | 11 +++- .../Src/Items/ReportItem.cs | 27 +++++++++ .../Src/Items/ReportModel.cs | 43 ++++++-------- .../Src/Items/ReportSettings.cs | 24 +++++++- .../Src/PageBuilder/BasePageBuilder.cs | 16 ++++- .../Src/ReportingFactory.cs | 2 - .../src/PageBuilder/PageBuilderFixture.cs | 49 +++++++++++---- 16 files changed, 299 insertions(+), 46 deletions(-) create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/PageInfo.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/SectionFactory.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportItem.cs create mode 100644 src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportItem.cs diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj index 581d8e79cd..de04539749 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj @@ -56,12 +56,16 @@ + + + + @@ -77,6 +81,7 @@ + diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/Page.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/Page.cs index af07340394..7fb4437ead 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/Page.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/Page.cs @@ -14,14 +14,33 @@ namespace ICSharpCode.Reporting.BaseClasses /// Description of Page. /// /// + + + + + public interface IPage{ - + bool IsFirstPage {get;set;} + IPageInfo PageInfo {get;} } + + + public class Page:IPage { - public Page() + public Page(IPageInfo pageInfo) { + if (pageInfo == null) { + throw new ArgumentNullException("pageInfo"); + } + PageInfo = pageInfo; } + + public bool IsFirstPage {get;set;} + + + public IPageInfo PageInfo {get;private set;} + } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/PageInfo.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/PageInfo.cs new file mode 100644 index 0000000000..26fcb16930 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/PageInfo.cs @@ -0,0 +1,59 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 05.04.2013 + * Time: 19:50 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; + +namespace ICSharpCode.Reporting.BaseClasses +{ + /// + /// Description of PageInfo. + /// + /// + public interface IPageInfo + { + int PageNumber {get;set;} + int TotalPages {get;set;} + string ReportName {get;set;} + string ReportFileName {get;set;} + string ReportFolder {get;} + DateTime ExecutionTime {get;set;} +// System.Collections.Hashtable ParameterHash {get;set;} +// IDataNavigator IDataNavigator {get;set;} + } + + + public class PageInfo:IPageInfo + { + public PageInfo() + { + } + + public int PageNumber {get;set;} + + + + public int TotalPages {get;set;} + + + + public string ReportName {get;set;} + + + public string ReportFileName {get;set;} + + + public string ReportFolder { + get{ + return System.IO.Path.GetDirectoryName(this.ReportFileName); + } + } + + public DateTime ExecutionTime {get;set;} + + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/SectionFactory.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/SectionFactory.cs new file mode 100644 index 0000000000..84efdadced --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Factories/SectionFactory.cs @@ -0,0 +1,30 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 06.04.2013 + * Time: 20:08 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using ICSharpCode.Reporting.Items; + +namespace ICSharpCode.Reporting.Factories +{ + /// + /// Description of SectionFactory. + /// + internal sealed class SectionFactory + { + private SectionFactory () + { + + } + public static BaseSection Create(string sectionName) { + if (String.IsNullOrEmpty(sectionName)) { + throw new ArgumentException("sectionName"); + } + return new BaseSection(sectionName); + } + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs index 02928d6523..1df929de30 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalEnums.cs @@ -15,7 +15,7 @@ namespace ICSharpCode.Reporting.Globals /// public class GlobalEnums { - internal enum ReportSection { + public enum ReportSection { ReportHeader, ReportPageHeader, ReportDetail, @@ -34,5 +34,17 @@ namespace ICSharpCode.Reporting.Globals PullData, FormSheet } + + + /// + /// FormSheet means a blank form with Labels, Lines and Checkboxes + /// DataReport handles all Reports with Data + /// + public enum ReportType { + FormSheet, + DataReport, + } + + } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalValues.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalValues.cs index 3c045783c7..4b708593af 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalValues.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/GlobalValues.cs @@ -21,5 +21,11 @@ namespace ICSharpCode.Reporting.Globals public static Size DefaultPageSize {get {return new Size(827,1169);}} + public static string PlainFileName + { + get { + return DefaultReportName + ReportExtension; + } + } } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportCreator.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportCreator.cs index cec2a1ee24..b3e3e7b935 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportCreator.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportCreator.cs @@ -19,6 +19,7 @@ namespace ICSharpCode.Reporting.Interfaces { void BuildExportList (); List Pages {get;} + // PagesCollection Pages{get;} // event EventHandler PageCreated; // event EventHandler SectionRendering; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportItem.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportItem.cs new file mode 100644 index 0000000000..e88f10a3ae --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportItem.cs @@ -0,0 +1,29 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 06.04.2013 + * Time: 19:55 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; + +namespace ICSharpCode.Reporting.Interfaces +{ + /// + /// Description of IPrintObject. + /// + public interface IReportItem + { + string Name{get;set;} +// Size Size {get;set;} +// Point Location {get;set;} +// Font Font {get;set;} +//// bool VisibleInReport {get;set;} +// Color BackColor {get;set;} +// Color FrameColor {get;set;} +// int SectionOffset {get;set;} +// bool CanGrow {get;set;} +// bool CanShrink {get;set;} + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportModel.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportModel.cs index b6093d0e5e..fea77db5c1 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportModel.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Interfaces/IReportModel.cs @@ -7,6 +7,7 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Collections.Generic; using ICSharpCode.Reporting.Items; namespace ICSharpCode.Reporting.Interfaces @@ -17,15 +18,16 @@ namespace ICSharpCode.Reporting.Interfaces public interface IReportModel { ReportSettings ReportSettings {get;set;} + List SectionCollection {get;} /* BaseSection ReportHeader {get;} BaseSection PageHeader {get;} - BaseSection DetailSection {get;} + BasistSection DetailSection {get;} BaseSection PageFooter {get;} BaseSection ReportFooter {get;} GlobalEnums.PushPullModel DataModel {get;} - ReportSectionCollection SectionCollection {get;} + */ } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs index 6e33f5fee0..5df31f701f 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseSection.cs @@ -7,16 +7,25 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using ICSharpCode.Reporting.Interfaces; namespace ICSharpCode.Reporting.Items { /// /// Description of BaseSection. /// - public class BaseSection + public class BaseSection:ReportItem { + #region Constructors + public BaseSection() + {} + + public BaseSection (string sectionName) { + base.Name = sectionName; } + + #endregion } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportItem.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportItem.cs new file mode 100644 index 0000000000..755ff0b4f9 --- /dev/null +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportItem.cs @@ -0,0 +1,27 @@ +/* + * Created by SharpDevelop. + * User: Peter Forstmeier + * Date: 06.04.2013 + * Time: 20:15 + * + * To change this template use Tools | Options | Coding | Edit Standard Headers. + */ +using System; +using ICSharpCode.Reporting.Interfaces; + +namespace ICSharpCode.Reporting.Items +{ + /// + /// Description of ReportItem. + /// + public class ReportItem:IReportItem + { + public ReportItem() + { + } + + + public string Name {get;set;} + + } +} diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportModel.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportModel.cs index ab27724d83..30ffb8c5f5 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportModel.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportModel.cs @@ -7,6 +7,8 @@ * To change this template use Tools | Options | Coding | Edit Standard Headers. */ using System; +using System.Collections.Generic; +using ICSharpCode.Reporting.Factories; using ICSharpCode.Reporting.Globals; using ICSharpCode.Reporting.Interfaces; @@ -18,33 +20,20 @@ namespace ICSharpCode.Reporting.Items internal class ReportModel :IReportModel { -// ReportSectionCollection sectionCollection; - - - public static ReportModel Create() - { - var model = new ReportModel(); -// foreach (GlobalEnums.ReportSection sec in Enum.GetValues(typeof(GlobalEnums.ReportSection))) { -// m.SectionCollection.Add (SectionFactory.Create(sec.ToString())); -// } - return model; - } - - /* - public static ReportModel Create(GraphicsUnit graphicsUnit) - { - ReportModel m = Create(); - m.ReportSettings.GraphicsUnit = graphicsUnit; - return m; + public ReportModel() { + SectionCollection = new List(); + foreach (GlobalEnums.ReportSection sec in Enum.GetValues(typeof(GlobalEnums.ReportSection))) { + SectionCollection.Add (SectionFactory.Create(sec.ToString())); + } } - - + + #region Sections public BaseSection ReportHeader { get { - return (BaseSection)sectionCollection[0]; + return (BaseSection)SectionCollection[0]; } } @@ -52,7 +41,7 @@ namespace ICSharpCode.Reporting.Items public BaseSection PageHeader { get { - return (BaseSection)sectionCollection[1]; + return (BaseSection)SectionCollection[1]; } } @@ -60,7 +49,7 @@ namespace ICSharpCode.Reporting.Items public BaseSection DetailSection { get { - return (BaseSection)sectionCollection[2]; + return (BaseSection)SectionCollection[2]; } } @@ -68,19 +57,19 @@ namespace ICSharpCode.Reporting.Items public BaseSection PageFooter { get { - return (BaseSection)sectionCollection[3]; + return (BaseSection)SectionCollection[3]; } } public BaseSection ReportFooter { get { - return (BaseSection)sectionCollection[4]; + return (BaseSection)SectionCollection[4]; } } #endregion - */ + ReportSettings reportSettings ; @@ -96,5 +85,7 @@ namespace ICSharpCode.Reporting.Items reportSettings = value; } } + + public List SectionCollection {get; private set;} } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs index e540087f46..3b6a194ce8 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs @@ -8,6 +8,8 @@ */ using System; using System.Drawing; +using System.IO; + using ICSharpCode.Reporting.Globals; namespace ICSharpCode.Reporting.Items @@ -33,7 +35,7 @@ namespace ICSharpCode.Reporting.Items // this.GraphicsUnit = GraphicsUnit.Pixel; // this.Padding = new Padding(5); // this.DefaultFont = GlobalValues.DefaultFont; -// this.ReportType = GlobalEnums.ReportType.FormSheet; + this.ReportType = GlobalEnums.ReportType.FormSheet; // this.DataModel = GlobalEnums.PushPullModel.FormSheet; // @@ -74,6 +76,22 @@ namespace ICSharpCode.Reporting.Items } } + private string fileName; +// [Category("Base Settings")] +// [XmlIgnoreAttribute] + public string FileName + { + get { + if (String.IsNullOrEmpty(fileName)) { + fileName = GlobalValues.PlainFileName; + } + return Path.GetFullPath(fileName); + } + set { + fileName = value; + } + } + private Size pageSize; public Size PageSize { @@ -95,5 +113,9 @@ namespace ICSharpCode.Reporting.Items // [Category("Data")] public GlobalEnums.PushPullModel DataModel {get;set;} + + +// [Browsable(true), Category("Base Settings")] + public GlobalEnums.ReportType ReportType {get;set;} } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs index cff877f575..9cff6a13b4 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs @@ -31,11 +31,25 @@ namespace ICSharpCode.Reporting.PageBuilder protected IPage InitNewPage(){ - return new Page(); + var pi = CreatePageInfo(); + return new Page(pi); + } + + IPageInfo CreatePageInfo() + { + var pi = new PageInfo(); + pi.PageNumber = Pages.Count +1; + pi.ReportName = ReportModel.ReportSettings.ReportName; + pi.ReportFileName = ReportModel.ReportSettings.FileName; +// pi.ReportName = ReportModel.ReportSettings.ReportName; + return pi; } protected virtual void AddPage(IPage page) { + if (Pages.Count == 0) { + page.IsFirstPage = true; + } Pages.Add(page); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs index 775878976c..15fa6a1aac 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/ReportingFactory.cs @@ -35,9 +35,7 @@ namespace ICSharpCode.Reporting IReportModel reportModel = LoadReportModel (stream); IReportCreator builder = null; if (reportModel.ReportSettings.DataModel == GlobalEnums.PushPullModel.FormSheet) { -// builder = FormPageBuilder.CreateInstance(reportModel); builder = new FormPageBuilder(reportModel); - Console.WriteLine("aaaaaaaaaaaaaaaaa"); } // else { // CheckForParameters(reportModel,reportParameters); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageBuilderFixture.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageBuilderFixture.cs index 77603b2970..90b80ccf50 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageBuilderFixture.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/PageBuilder/PageBuilderFixture.cs @@ -10,7 +10,7 @@ using System; using System.IO; using System.Reflection; -using ICSharpCode.Reporting.BaseClasses; +using ICSharpCode.Reporting.Interfaces; using ICSharpCode.Reporting.PageBuilder; using NUnit.Framework; @@ -19,47 +19,76 @@ namespace ICSharpCode.Reporting.Test.PageBuilder [TestFixture] public class PageBuilderFixture { - private Stream stream; + + private IReportCreator reportCreator; [Test] public void CanCreateFormsPageBuilder() { - var reportingFactory = new ReportingFactory(); - var reportCreator = reportingFactory.ReportCreator(stream); Assert.IsNotNull(reportCreator); } [Test] public void PagesCountIsZero () { - var reportingFactory = new ReportingFactory(); - var reportCreator = reportingFactory.ReportCreator(stream); Assert.That(reportCreator.Pages.Count,Is.EqualTo(0)); } [Test] public void BuildExportPagesCountIsOne() { - var reportingFactory = new ReportingFactory(); - var reportCreator = reportingFactory.ReportCreator(stream); reportCreator.BuildExportList(); Assert.That(reportCreator.Pages.Count,Is.EqualTo(1)); } - + [Test] public void CurrentPageIsSet() { + System.Reflection.Assembly asm = Assembly.GetExecutingAssembly(); + var stream = asm.GetManifestResourceStream(TestHelper.PlainReportFileName); var reportingFactory = new ReportingFactory(); var reportCreator = (FormPageBuilder)reportingFactory.ReportCreator(stream); reportCreator.BuildExportList(); Assert.That(reportCreator.CurrentPage,Is.Not.Null); } + + [Test] + public void CurrentPageIsFirstPage() { + System.Reflection.Assembly asm = Assembly.GetExecutingAssembly(); + var stream = asm.GetManifestResourceStream(TestHelper.PlainReportFileName); + var reportingFactory = new ReportingFactory(); + var reportCreator = (FormPageBuilder)reportingFactory.ReportCreator(stream); + reportCreator.BuildExportList(); + Assert.That(reportCreator.CurrentPage.IsFirstPage,Is.True); + Assert.That(reportCreator.Pages[0].IsFirstPage,Is.True); + } + + + [Test] + public void PageInfoPageNumberIsOne() { + reportCreator.BuildExportList(); + var pi = reportCreator.Pages[0].PageInfo; + Assert.That(pi.PageNumber,Is.EqualTo(1)); + } + + + + [Test] + public void PageInfoReportName() { + reportCreator.BuildExportList(); + var pi = reportCreator.Pages[0].PageInfo; + Assert.That(pi.ReportName,Is.EqualTo("Report1")); + } + + [SetUp] public void LoadFromStream() { System.Reflection.Assembly asm = Assembly.GetExecutingAssembly(); - stream = asm.GetManifestResourceStream(TestHelper.PlainReportFileName); + var stream = asm.GetManifestResourceStream(TestHelper.PlainReportFileName); + var reportingFactory = new ReportingFactory(); + reportCreator = reportingFactory.ReportCreator(stream); } } }