Permalink
Browse files

Create empty FormSheetreport from File/New

  • Loading branch information...
1 parent 61f3091 commit 24034c318bdc924f6a9c725fef2d2e6b7fb46e59 @PeterForstmeier PeterForstmeier committed Apr 3, 2014
@@ -82,6 +82,8 @@
<Folder Include="src\Designer" />
<Folder Include="src\Globals" />
<Folder Include="src\DesignableItems" />
+ <Folder Include="src\Factory" />
+ <Folder Include="src\Wizard" />
<Folder Include="src\Toolbox" />
<Folder Include="src\TypeProvider" />
<Folder Include="src\XML" />
@@ -109,6 +111,7 @@
<Compile Include="src\Designer\RootReportModel.cs" />
<Compile Include="src\Designer\SectionDesigner.cs" />
<Compile Include="src\Designer\TextItemDesigner.cs" />
+ <Compile Include="src\Factory\CreateFormSheetFromModel.cs" />
<Compile Include="src\Globals\DesignerGlobals.cs" />
<Compile Include="src\Globals\StringWriterWithEncoding.cs" />
<Compile Include="src\Services\DefaultMemberRelationshipService.cs" />
@@ -21,10 +21,6 @@ public class CreateDesignerCommand : AbstractMenuCommand
{
readonly OpenedFile openedFile;
- public CreateDesignerCommand() {
- MessageService.ShowMessage("Not implemented at the moment","Reporting");
- }
-
public CreateDesignerCommand (OpenedFile openedFile) {
if (openedFile == null)
throw new ArgumentNullException("openedFile");
@@ -9,10 +9,14 @@
using System;
using System.IO;
+using System.Xml;
using ICSharpCode.Core;
+using ICSharpCode.Reporting.Factories;
+using ICSharpCode.Reporting.Items;
using ICSharpCode.SharpDevelop;
using ICSharpCode.SharpDevelop.Workbench;
using ICSharpCode.Reporting.Addin.Commands;
+using ICSharpCode.Reporting.Addin.Factory;
namespace ICSharpCode.Reporting.Addin.DesignerBinding {
@@ -41,20 +45,30 @@ public double AutoDetectFileContent(FileName fileName, System.IO.Stream fileCont
public IViewContent CreateContentForFile(OpenedFile file)
{
if (file.IsDirty) {
- MessageService.ShowMessage("ReportWizard not available at the Moment","New ReportDesigner");
- return null;
- // var cmd = new ReportWizardCommand(file);
- // cmd.Run();
- // if (cmd.Canceled) {
- // return null;
- // }
- // file.SetData(cmd.GeneratedReport.ToArray());
+
+ var reportModel = ReportModelFactory.Create();
+
+ var reportFactory = new CreateFormSheetFromModel();
+ var xml = reportFactory.ToXml(reportModel);
+
+ var doc = new XmlDocument();
+ doc.LoadXml(xml.ToString());
+ var ar = XmlToArray(doc);
+ file.SetData(ar);
}
var viewCmd = new CreateDesignerCommand(file);
viewCmd.Run();
LoggingService.Info("return DesignerView");
return viewCmd.DesignerView;
}
+
+ static byte[] XmlToArray(XmlDocument doc)
+ {
+ using (var stream = new MemoryStream()) {
+ doc.Save(stream);
+ return stream.ToArray();
+ }
+ }
}
}
@@ -0,0 +1,71 @@
+/*
+ * Created by SharpDevelop.
+ * User: Peter Forstmeier
+ * Date: 03.04.2014
+ * Time: 19:55
+ *
+ * To change this template use Tools | Options | Coding | Edit Standard Headers.
+ */
+using System;
+using System.Drawing;
+using System.IO;
+using ICSharpCode.Reporting.Interfaces;
+using ICSharpCode.Reporting.Addin.DesignableItems;
+using ICSharpCode.Reporting.Addin.Globals;
+using ICSharpCode.Reporting.Addin.XML;
+
+namespace ICSharpCode.Reporting.Addin.Factory
+{
+ /// <summary>
+ /// Description of CreateFormSheetReport.
+ /// </summary>
+ class CreateFormSheetFromModel
+ {
+
+
+ public StringWriter ToXml(IReportModel reportModel) {
+ int locY = reportModel.ReportSettings.TopMargin;
+
+ foreach (var section in reportModel.SectionCollection)
+ {
+ section.Location = new Point(reportModel.ReportSettings.LeftMargin,locY);
+ section.Size = new Size(reportModel.ReportSettings.PageSize.Width - reportModel.ReportSettings.LeftMargin - reportModel.ReportSettings.RightMargin,
+ 70);
+ locY = locY + section.Size.Height + DesignerGlobals.GabBetweenSection;
+ }
+
+
+ var xml = ToXmlInternal(reportModel);
+ return xml;
+ }
+
+ StringWriter ToXmlInternal(IReportModel model)
+ {
+ var writer = new StringWriterWithEncoding(System.Text.Encoding.UTF8);
+ var xml = XmlHelper.CreatePropperWriter(writer);
+
+ var reportDesignerWriter = new ReportDesignerWriter();
+ XmlHelper.CreatePropperDocument(xml);
+
+
+ reportDesignerWriter.Save(model.ReportSettings,xml);
+
+ xml.WriteEndElement();
+ xml.WriteStartElement("SectionCollection");
+
+ // we look only for Sections
+ foreach (var section in model.SectionCollection) {
+ reportDesignerWriter.Save(section,xml);
+ }
+
+ //SectionCollection
+ xml.WriteEndElement();
+ //Reportmodel
+ xml.WriteEndElement();
+ xml.WriteEndDocument();
+ xml.Close();
+ return writer;
+ }
+
+ }
+}
@@ -382,7 +382,7 @@ void SetupSecondaryView()
}
- public override void Load(OpenedFile file, System.IO.Stream stream)
+ public override void Load(OpenedFile file, Stream stream)
{
LoggingService.Debug("ReportDesigner: Load from: " + file.FileName);
base.Load(file, stream);
@@ -27,7 +27,7 @@ namespace ICSharpCode.Reporting.Factories
/// <summary>
/// Description of ReportCreatorFactory.
/// </summary>
- internal class ReportCreatorFactory {
+ static class ReportCreatorFactory {
public static IReportCreator ExporterFactory(IReportModel reportModel)
{
@@ -7,6 +7,7 @@
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
+using System.Drawing;
using ICSharpCode.Reporting.Globals;
using ICSharpCode.Reporting.Items;
@@ -19,11 +20,17 @@ public static class ReportModelFactory
{
public static ReportModel Create()
{
- ReportModel m = new ReportModel();
- foreach (GlobalEnums.ReportSection sec in Enum.GetValues(typeof(GlobalEnums.ReportSection))) {
- m.SectionCollection.Add (SectionFactory.Create(sec.ToString()));
+ var reportModel = new ReportModel();
+ foreach (var sec in Enum.GetValues(typeof(GlobalEnums.ReportSection))) {
+ reportModel.SectionCollection.Add (SectionFactory.Create(sec.ToString()));
}
- return m;
+
+ foreach (var section in reportModel.SectionCollection) {
+ section.Size = new Size(reportModel.ReportSettings.PageSize.Width - reportModel.ReportSettings.LeftMargin - reportModel.ReportSettings.RightMargin,
+ GlobalValues.DefaultSectionHeight);
+ }
+
+ return reportModel;
}
}
}
@@ -14,12 +14,9 @@ namespace ICSharpCode.Reporting.Factories
/// <summary>
/// Description of SectionFactory.
/// </summary>
- sealed class SectionFactory
+ static class SectionFactory
{
- private SectionFactory ()
- {
-
- }
+
public static BaseSection Create(string name) {
if (name == null)
throw new ArgumentNullException("name");
@@ -18,6 +18,7 @@
using System;
using System.Drawing;
+using System.Drawing.Printing;
namespace ICSharpCode.Reporting.Globals
{
/// <summary>
@@ -48,5 +49,9 @@ public static Font DefaultFont
public static Size PreferedSize {get {return new Size(100,20);}}
+
+ public static Margins DefaultPageMargin {get {return new Margins(50,50,50,50);}}
+
+ public static int DefaultSectionHeight {get {return 60;}}
}
}
@@ -17,7 +17,6 @@
// DEALINGS IN THE SOFTWARE.
using System;
-using System.Collections.Generic;
using System.Collections.ObjectModel;
using ICSharpCode.Reporting.Items;
@@ -31,7 +30,6 @@ public interface IReportModel
{
ReportSettings ReportSettings {get;set;}
Collection<BaseSection> SectionCollection {get;}
-
IReportContainer ReportHeader {get;}
IReportContainer PageHeader {get;}
IReportContainer DetailSection {get;}
@@ -19,8 +19,6 @@
using System;
using System.Collections.ObjectModel;
-using ICSharpCode.Reporting.Factories;
-using ICSharpCode.Reporting.Globals;
using ICSharpCode.Reporting.Interfaces;
namespace ICSharpCode.Reporting.Items
@@ -33,65 +31,38 @@ public class ReportModel :IReportModel
public ReportModel() {
SectionCollection = new Collection<BaseSection>();
+ ReportSettings = new ReportSettings();
}
#region Sections
- public IReportContainer ReportHeader
- {
- get {
- return (BaseSection)SectionCollection[0];
- }
+ public IReportContainer ReportHeader {
+ get {return (BaseSection)SectionCollection[0];}
}
- public IReportContainer PageHeader
- {
- get {
- return (BaseSection)SectionCollection[1];
- }
+ public IReportContainer PageHeader {
+ get {return (BaseSection)SectionCollection[1];}
}
- public IReportContainer DetailSection
- {
- get {
- return (BaseSection)SectionCollection[2];
- }
+ public IReportContainer DetailSection {
+ get {return (BaseSection)SectionCollection[2];}
}
- public IReportContainer PageFooter
- {
- get {
- return (BaseSection)SectionCollection[3];
- }
+ public IReportContainer PageFooter {
+ get {return (BaseSection)SectionCollection[3];}
}
- public IReportContainer ReportFooter
- {
- get {
- return (BaseSection)SectionCollection[4];
- }
+
+ public IReportContainer ReportFooter {
+ get {return (BaseSection)SectionCollection[4];}
}
#endregion
-
- ReportSettings reportSettings ;
-
- public ReportSettings ReportSettings
- {
- get {
- if (this.reportSettings == null) {
- this.reportSettings = new ReportSettings();
- }
- return reportSettings;
- }
- set {
- reportSettings = value;
- }
- }
+ public ReportSettings ReportSettings{get;set;}
public Collection<BaseSection> SectionCollection {get; private set;}
}
@@ -73,10 +73,10 @@ void BaseValues()
// this.ConnectionString = String.Empty;
// this.CommandText = String.Empty;
//
-// this.TopMargin = GlobalValues.DefaultPageMargin.Left;
-// this.BottomMargin = GlobalValues.DefaultPageMargin.Bottom;
-// this.LeftMargin = GlobalValues.DefaultPageMargin.Left;
-// this.RightMargin = GlobalValues.DefaultPageMargin.Right;
+ this.TopMargin = GlobalValues.DefaultPageMargin.Left;
+ this.BottomMargin = GlobalValues.DefaultPageMargin.Bottom;
+ this.LeftMargin = GlobalValues.DefaultPageMargin.Left;
+ this.RightMargin = GlobalValues.DefaultPageMargin.Right;
//
// this.availableFields = new AvailableFieldsCollection();
// this.groupingsCollection = new GroupColumnCollection();

0 comments on commit 24034c3

Please sign in to comment.