From 1952fc35562e2d87dfec408dfb8dceffaa38ec7e Mon Sep 17 00:00:00 2001 From: Peter Forstmeier Date: Sun, 26 Apr 2015 19:15:21 +0200 Subject: [PATCH] Rendering: Nested Containers are detected, Format of double, some cleanup --- .../ICSharpCode.Reporting.addin | 4 +- .../src/Commands/FormsCommands.cs | 25 +++---- .../src/Commands/ViewCommands.cs | 5 +- .../src/DesignerBinding/DesignerBinding.cs | 21 ++---- .../src/Globals/DesignerGlobals.cs | 18 ----- .../src/Globals/GlobalLists.cs | 3 +- .../Src/BaseClasses/TextDrawer.cs | 4 +- .../Listhandling/CollectionDataSource.cs | 10 ++- .../Src/DataSource/ReflectionExtension.cs | 6 -- .../Src/Exporter/Visitors/FormatVisitor.cs | 6 ++ .../Src/Globals/StandardFormatter.cs | 65 +++++++------------ .../Src/Items/ReportSettings.cs | 5 ++ .../Src/Pdf/PdfExporter.cs | 1 + .../Src/Wpf/PreviewViewModel.cs | 2 +- .../Src/Wpf/Visitor/WpfVisitor.cs | 2 +- 15 files changed, 69 insertions(+), 108 deletions(-) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.addin b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.addin index e2632686af..4f492dd1c7 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.addin +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/ICSharpCode.Reporting.addin @@ -106,7 +106,9 @@ - + diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/FormsCommands.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/FormsCommands.cs index 8f724d87ff..de240973cd 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/FormsCommands.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/FormsCommands.cs @@ -10,7 +10,6 @@ using System; using System.ComponentModel.Design; using ICSharpCode.Core; using ICSharpCode.SharpDevelop; -using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.Reporting.Addin.Views; namespace ICSharpCode.Reporting.Addin.Commands @@ -19,16 +18,16 @@ namespace ICSharpCode.Reporting.Addin.Commands /// Description of FormsCommands. /// - public abstract class AbstractFormsDesignerCommand : AbstractMenuCommand - { + public abstract class AbstractFormsDesignerCommand : AbstractMenuCommand{ + public abstract CommandID CommandID { get; } protected virtual bool CanExecuteCommand(IDesignerHost host) - { - return true; - } + {return true;} + + protected static DesignerView ReportDesigner { get { @@ -41,8 +40,7 @@ namespace ICSharpCode.Reporting.Addin.Commands } - public override void Run() - { + public override void Run(){ var formDesigner = ReportDesigner; if (formDesigner != null && CanExecuteCommand(formDesigner.Host)) { var menuCommandService = (IMenuCommandService)formDesigner.Host.GetService(typeof(IMenuCommandService)); @@ -50,8 +48,7 @@ namespace ICSharpCode.Reporting.Addin.Commands } } - internal virtual void CommandCallBack(object sender, EventArgs e) - { + internal virtual void CommandCallBack(object sender, EventArgs e){ Run(); } } @@ -61,14 +58,10 @@ namespace ICSharpCode.Reporting.Addin.Commands public class ViewCode : AbstractFormsDesignerCommand { public override CommandID CommandID { - get { - return StandardCommands.ViewCode; - } + get {return StandardCommands.ViewCode;} } - public override void Run() - { -// var window = WorkbenchSingleton.Workbench.ActiveWorkbenchWindow; + public override void Run(){ var window = SD.Workbench; if (window == null) { return; diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/ViewCommands.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/ViewCommands.cs index d1c6b03aea..e58710b869 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/ViewCommands.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Commands/ViewCommands.cs @@ -17,8 +17,8 @@ namespace ICSharpCode.Reporting.Addin.Commands /// /// Description of ViewCommands. /// - public class CreateDesignerCommand : AbstractMenuCommand - { + public class CreateDesignerCommand : AbstractMenuCommand{ + readonly OpenedFile openedFile; public CreateDesignerCommand (OpenedFile openedFile) { @@ -29,7 +29,6 @@ namespace ICSharpCode.Reporting.Addin.Commands public override void Run(){ var generator = new DesignerGenerator(); - DesignerView = new DesignerView(openedFile, generator); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs index 97feded12c..b6944d545b 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/DesignerBinding/DesignerBinding.cs @@ -11,8 +11,6 @@ using System; using System.IO; using System.Xml; using ICSharpCode.Core; -using ICSharpCode.Reporting.Factories; -using ICSharpCode.Reporting.Items; using ICSharpCode.SharpDevelop.Workbench; using ICSharpCode.Reporting.Addin.Commands; using ICSharpCode.Reporting.Addin.Factory; @@ -20,30 +18,24 @@ using ICSharpCode.Reporting.Addin.ReportWizard; namespace ICSharpCode.Reporting.Addin.DesignerBinding { - public class ReportDesignerBinding:IDisplayBinding { - - public bool IsPreferredBindingForFile(FileName fileName) - { + public bool IsPreferredBindingForFile(FileName fileName){ return true; } - public bool CanCreateContentForFile(FileName fileName) - { + public bool CanCreateContentForFile(FileName fileName){ return Path.GetExtension(fileName).Equals(".srd", StringComparison.OrdinalIgnoreCase); } - public double AutoDetectFileContent(FileName fileName, System.IO.Stream fileContent, string detectedMimeType) - { - throw new System.NotImplementedException(); + public double AutoDetectFileContent(FileName fileName, System.IO.Stream fileContent, string detectedMimeType){ + throw new NotImplementedException(); } - public IViewContent CreateContentForFile(OpenedFile file) - { + public IViewContent CreateContentForFile(OpenedFile file){ if (file.IsDirty) { var cmd = new ReportWizardCommand(); cmd.Run(); @@ -67,8 +59,7 @@ namespace ICSharpCode.Reporting.Addin.DesignerBinding { } - static byte[] XmlToArray(XmlDocument doc) - { + static byte[] XmlToArray(XmlDocument doc){ using (var stream = new MemoryStream()) { doc.Save(stream); return stream.ToArray(); diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/DesignerGlobals.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/DesignerGlobals.cs index 032e07d4c4..2f1c63a7e0 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/DesignerGlobals.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/DesignerGlobals.cs @@ -29,23 +29,5 @@ namespace ICSharpCode.Reporting.Addin.Globals public static int GabBetweenSection{ get {return 15;} } - - /* - public static void DrawString(Graphics graphics,string text, - Font font,Brush brush, - RectangleF rectangle, - StringFormat format) - { - if (graphics == null) { - throw new ArgumentNullException("graphics"); - } - - graphics.DrawString(text, - font, - brush, - rectangle, - format); - } - */ } } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs index 684d501278..70916267da 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting.Addin/src/Globals/GlobalLists.cs @@ -17,8 +17,7 @@ namespace ICSharpCode.Reporting.Addin.Globals { #region DataTypes - public static string[] DataTypeList () - { + public static string[] DataTypeList (){ return (string[])dataTypeList.Clone(); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/TextDrawer.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/TextDrawer.cs index ccd2668d51..861b046f03 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/TextDrawer.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/BaseClasses/TextDrawer.cs @@ -34,7 +34,8 @@ namespace ICSharpCode.Reporting.BaseClasses format); } - +// http://stackoverflow.com/questions/14932063/convert-code-of-a-user-control-from-vb-net-to-c-sharp +//https://mightycoco.wordpress.com/2009/09/22/getstringformatfromcontentallignment-converting-contentallignment-data-into-stringformat-data/ public static StringFormat BuildStringFormat(StringTrimming stringTrimming,TextAlignment alignment){ StringFormat format = StringFormat.GenericTypographic; format.Trimming = stringTrimming; @@ -65,6 +66,7 @@ namespace ICSharpCode.Reporting.BaseClasses } return format; } + /* public static StringFormat BuildStringFormat(StringTrimming stringTrimming,ContentAlignment alignment) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs index f5008d188d..00feb39976 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataManager/Listhandling/CollectionDataSource.cs @@ -191,8 +191,14 @@ namespace ICSharpCode.Reporting.DataManager.Listhandling string ReadValueFromProperty (string columnName) { var propertyPath = Current.ParsePropertyPath(columnName); - var val = propertyPath.Evaluate(Current); - return val.ToString(); + try { + var val = propertyPath.Evaluate(Current); + return val.ToString(); + } catch (Exception e) { + Console.WriteLine(" Cant' find <{0}",columnName); +// throw e; + } + return String.Empty; } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ReflectionExtension.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ReflectionExtension.cs index cd9695c18a..e67c42fad9 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ReflectionExtension.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/DataSource/ReflectionExtension.cs @@ -22,13 +22,7 @@ using System.Reflection; namespace ICSharpCode.Reporting.DataSource { - /// - /// Description of ReflectionExtension. - /// - /// - - public static class ReflectionExtensions { public static PropertyPath ParsePropertyPath(this object target,string propertyPath) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/FormatVisitor.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/FormatVisitor.cs index c60ce00cce..03d7e53fab 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/FormatVisitor.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/FormatVisitor.cs @@ -33,6 +33,11 @@ namespace ICSharpCode.Reporting.Exporter.Visitors public override void Visit(ExportContainer exportContainer) { foreach (var element in exportContainer.ExportedItems) { + var container = element as ExportContainer; + if (container != null) { + Visit(container); + } + var te = element as ExportText; if (te != null) { Visit(te); @@ -43,6 +48,7 @@ namespace ICSharpCode.Reporting.Exporter.Visitors public override void Visit(ExportText exportColumn) { + Console.WriteLine(exportColumn.Text); if (!String.IsNullOrEmpty(exportColumn.FormatString)) { StandardFormatter.FormatOutput(exportColumn); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StandardFormatter.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StandardFormatter.cs index a55304f600..8622ee8c92 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StandardFormatter.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StandardFormatter.cs @@ -25,39 +25,22 @@ namespace ICSharpCode.Reporting.Globals /// /// Description of StandardFormatter. /// - class StandardFormatter + static class StandardFormatter { public static void FormatOutput (IExportText textColumn) { + if (String.IsNullOrWhiteSpace(textColumn.Text)) { + return; + } if (!String.IsNullOrEmpty(textColumn.FormatString)) { TypeCode typeCode = TypeHelper.TypeCodeFromString(textColumn.DataType); textColumn.Text = FormatItem(textColumn.Text,textColumn.FormatString,typeCode); } } - /* - public static string FormatOutput(string valueToFormat,string format, - string dataType, string nullValue ) - { - if (String.IsNullOrEmpty(format)) { - return valueToFormat; - } - - if (String.IsNullOrEmpty(valueToFormat)) { - return nullValue; - } - - TypeCode typeCode = TypeHelper.TypeCodeFromString(dataType); - return FormatItem(valueToFormat,format,typeCode,nullValue); - } - */ + + static string FormatItem (string valueToFormat,string format,TypeCode typeCode) { -// private static string FormatItem (string valueToFormat,string format, -// TypeCode typeCode,string nullValue) - static string FormatItem (string valueToFormat,string format, - TypeCode typeCode) - { string retValue = String.Empty; - switch (typeCode) { case TypeCode.Int16: case TypeCode.Int32: @@ -74,6 +57,8 @@ namespace ICSharpCode.Reporting.Globals break; case TypeCode.Double: + retValue = FormatDecimal (valueToFormat,format); + break; case TypeCode.Single: break; @@ -85,13 +70,12 @@ namespace ICSharpCode.Reporting.Globals retValue = valueToFormat; break; } - return retValue; } - static string FormatBool (string toFormat) - { + static string FormatBool (string toFormat){ + if (CheckValue(toFormat)) { bool b = bool.Parse (toFormat); return b.ToString (CultureInfo.CurrentCulture); @@ -100,11 +84,11 @@ namespace ICSharpCode.Reporting.Globals } - static string FormatIntegers(string toFormat, string format) - { + static string FormatIntegers(string toFormat, string format){ + string str = String.Empty; if (CheckValue (toFormat)) { - int number = Int32.Parse(toFormat, System.Globalization.NumberStyles.Any, CultureInfo.CurrentCulture.NumberFormat); + int number = Int32.Parse(toFormat, NumberStyles.Any, CultureInfo.CurrentCulture.NumberFormat); str = number.ToString(format, CultureInfo.CurrentCulture); return str; } else { @@ -114,15 +98,15 @@ namespace ICSharpCode.Reporting.Globals } - static string FormatDecimal(string toFormat, string format) - { + static string FormatDecimal(string toFormat, string format){ + string str = String.Empty; if (CheckValue (toFormat)) { try { - decimal dec = Decimal.Parse(toFormat, - System.Globalization.NumberStyles.Any, + decimal number = Decimal.Parse(toFormat, + NumberStyles.Any, CultureInfo.CurrentCulture.NumberFormat); - str = dec.ToString (format,CultureInfo.CurrentCulture); + str = number.ToString (format,CultureInfo.CurrentCulture); } catch (FormatException) { throw ; @@ -136,8 +120,8 @@ namespace ICSharpCode.Reporting.Globals // http://stackoverflow.com/questions/4710455/i-need-code-to-validate-any-time-in-c-sharp-in-hhmmss-format - static string FormatDate(string toFormat, string format) - { + static string FormatDate(string toFormat, string format){ + DateTime date; if (DateTime.TryParse(toFormat, out date)) { @@ -158,12 +142,9 @@ namespace ICSharpCode.Reporting.Globals } - static bool CheckValue (string toFormat) - { - if (String.IsNullOrEmpty(toFormat)) { - return false; - } - return true; + static bool CheckValue (string toFormat){ + + return String.IsNullOrEmpty(toFormat) ? false : true; } } } 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 264ca621a1..d62ca39e40 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/ReportSettings.cs @@ -55,6 +55,11 @@ namespace ICSharpCode.Reporting.Items { this.pageSize = GlobalValues.DefaultPageSize; BaseValues(); + var x = PdfSharp.PageSizeConverter.ToSize(PdfSharp.PageSize.A4); + //http://www.sizepaper.com/a-series/a4 +// http://www.sizepaper.com/american-loose + System.Drawing.Printing.PageSettings paperProp = new System.Drawing.Printing.PageSettings(); + var p = paperProp.PaperSize.PaperName.ToString(); } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Pdf/PdfExporter.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Pdf/PdfExporter.cs index 1ee1b452f5..184aa0bf23 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Pdf/PdfExporter.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Pdf/PdfExporter.cs @@ -49,6 +49,7 @@ namespace ICSharpCode.Reporting.Pdf if (show) { Process.Start(fileName); } + } diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/PreviewViewModel.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/PreviewViewModel.cs index 10eb532ca6..d49f616d8a 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/PreviewViewModel.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/PreviewViewModel.cs @@ -46,7 +46,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer var wpfExporter = new WpfExporter(pages); wpfExporter.Run(); - this.document = wpfExporter.Document; + this.Document = wpfExporter.Document; } static FixedDocument CreateFixedDocument(ReportSettings reportSettings) diff --git a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs index 5d5c2935ff..fc22ba0860 100644 --- a/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs +++ b/src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Wpf/Visitor/WpfVisitor.cs @@ -115,7 +115,7 @@ namespace ICSharpCode.Reporting.WpfReportViewer.Visitor return graphCanvas; } - +// http://stackoverflow.com/questions/25308612/vertical-alignment-with-drawingcontext-drawtext public override void Visit(ExportText exportColumn){ var formattedText = FixedDocumentCreator.CreateFormattedText((ExportText)exportColumn);