Browse Source

FormatVisitor, format all elements in one pass after ExpressionVisitor

reports
Peter Forstmeier 12 years ago
parent
commit
014e277c76
  1. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/ICSharpCode.Reporting.csproj
  2. 52
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/FormatVisitor.cs
  3. 9
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs
  4. 2
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs
  5. 150
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StandardFormatter.cs
  6. 67
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/TypeHelper.cs
  7. 5
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs
  8. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/BasePageBuilder.cs
  9. 11
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/DataPageBuilder.cs
  10. 4
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportText.cs
  11. 1
      src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd

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

@ -60,6 +60,7 @@ @@ -60,6 +60,7 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Presentation">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
@ -105,6 +106,7 @@ @@ -105,6 +106,7 @@
<Compile Include="Src\Exporter\Visitors\CanvasExtension.cs" />
<Compile Include="Src\Exporter\Visitors\CanvasHelper.cs" />
<Compile Include="Src\Exporter\Visitors\ExpressionVisitor.cs" />
<Compile Include="Src\Exporter\Visitors\FormatVisitor.cs" />
<Compile Include="Src\Exporter\WpfExporter.cs" />
<Compile Include="Src\Exporter\Visitors\AbstractVisitor.cs" />
<Compile Include="Src\Exporter\Visitors\IAcceptor.cs" />
@ -127,7 +129,9 @@ @@ -127,7 +129,9 @@
<Compile Include="Src\Factories\ReportCreatorFactory.cs" />
<Compile Include="Src\Globals\CreateGraphics.cs" />
<Compile Include="Src\Globals\MeasurementService.cs" />
<Compile Include="Src\Globals\StandardFormatter.cs" />
<Compile Include="Src\Globals\StringHelper.cs" />
<Compile Include="Src\Globals\TypeHelper.cs" />
<Compile Include="Src\Interfaces\Data\IDataViewHandling.cs" />
<Compile Include="Src\Interfaces\Export\IExportColumn.cs" />
<Compile Include="Src\Interfaces\Export\IExportContainer.cs" />

52
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Exporter/Visitors/FormatVisitor.cs

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.ObjectModel;
using ICSharpCode.Reporting.Globals;
using ICSharpCode.Reporting.PageBuilder.ExportColumns;
namespace ICSharpCode.Reporting.Exporter.Visitors
{
/// <summary>
/// Description of FormatVisitor.
/// </summary>
public class FormatVisitor: AbstractVisitor
{
readonly Collection<ExportPage> pages;
public FormatVisitor(Collection<ExportPage> pages)
{
if (pages == null)
throw new ArgumentNullException("pages");
this.pages = pages;
Console.WriteLine("Start FormatVisitor");
}
public override void Visit(ICSharpCode.Reporting.PageBuilder.ExportColumns.ExportPage page)
{
foreach (var element in page.ExportedItems) {
var ac = element as IAcceptor;
ac.Accept(this);
}
}
public override void Visit(ICSharpCode.Reporting.PageBuilder.ExportColumns.ExportContainer exportColumn)
{
foreach (var element in exportColumn.ExportedItems) {
var ac = element as IAcceptor;
ac.Accept(this);
}
}
public override void Visit(ICSharpCode.Reporting.PageBuilder.ExportColumns.ExportText exportColumn)
{
if (!String.IsNullOrEmpty(exportColumn.FormatString)) {
Console.WriteLine("Format {0} - {1}",exportColumn.Name,exportColumn.Text);
exportColumn.Text = StandardFormatter.FormatOutput(exportColumn.Text,
exportColumn.FormatString,
"System.Int16",
"no format");
}
}
}
}

9
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Ast/GlobalsNode.cs

@ -23,13 +23,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast @@ -23,13 +23,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast
var nodes = treeNode.GetMappedChildNodes();
globalNode = AddChild("Args", nodes[2]);
}
/*
"=Globals!PageNumber",
"=Globals!TotalPages",
"=Globals!ExecutionTime",
"=Globals!ReportFolder",
"=Globals!ReportName"};
*/
protected override object DoEvaluate(ScriptThread thread)
{
@ -38,7 +32,6 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast @@ -38,7 +32,6 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Ast
var test = globalNode.AsString.ToLower();
if ( test == "pagenumber") {
Console.WriteLine("pagenumberr");
return pi.PageNumber;
} else if (test == "pages") {
return pi.TotalPages;

2
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Expressions/Irony/Imports/ImportAggregates.cs

@ -35,7 +35,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports @@ -35,7 +35,7 @@ namespace ICSharpCode.Reporting.Expressions.Irony.Imports
var curpos = dataSource.CurrentPosition;
dataSource.CurrentPosition = 0;
if (FieldExist(dataSource.Current,fieldName)) {
do {
var current = dataSource.Current;

150
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/StandardFormatter.cs

@ -0,0 +1,150 @@ @@ -0,0 +1,150 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Globalization;
namespace ICSharpCode.Reporting.Globals
{
/// <summary>
/// Description of StandardFormatter.
/// </summary>
class StandardFormatter
{
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);
}
private static string FormatItem (string valueToFormat,string format,
TypeCode typeCode,string nullValue)
{
string retValue = String.Empty;
switch (typeCode) {
case TypeCode.Int16:
case TypeCode.Int32:
retValue = FormatIntegers (valueToFormat,format);
break;
case TypeCode.DateTime:
retValue = FormatDate(valueToFormat,format);
break;
case TypeCode.Boolean:
retValue = FormatBool (valueToFormat,format);
break;
case TypeCode.Decimal:
retValue = FormatDecimal (valueToFormat,format);
break;
case TypeCode.Double:
case TypeCode.Single:
break;
case TypeCode.String:
case TypeCode.Char:
retValue = valueToFormat;
break;
default:
retValue = valueToFormat;
break;
}
return retValue;
}
private static string FormatBool (string toFormat, string format)
{
if (CheckValue(toFormat)) {
bool b = bool.Parse (toFormat);
return b.ToString (CultureInfo.CurrentCulture);
}
return toFormat;
}
private static string FormatIntegers(string toFormat, string format)
{
string str = String.Empty;
if (CheckValue (toFormat)) {
try {
int number = Int32.Parse (toFormat,
System.Globalization.NumberStyles.Any,
CultureInfo.CurrentCulture.NumberFormat);
str = number.ToString (format,CultureInfo.CurrentCulture);
} catch (System.FormatException e) {
throw e;
}
return str;
} else {
str = (0.0M).ToString(CultureInfo.CurrentCulture);
}
return str;
}
private static string FormatDecimal(string toFormat, string format)
{
string str = String.Empty;
if (CheckValue (toFormat)) {
try {
decimal dec = Decimal.Parse(toFormat,
System.Globalization.NumberStyles.Any,
CultureInfo.CurrentCulture.NumberFormat);
str = dec.ToString (format,CultureInfo.CurrentCulture);
} catch (System.FormatException e) {
throw e;
}
return str;
} else {
str = (0.0M).ToString(CultureInfo.CurrentCulture);
}
return str;
}
// http://stackoverflow.com/questions/4710455/i-need-code-to-validate-any-time-in-c-sharp-in-hhmmss-format
private static string FormatDate(string toFormat, string format)
{
DateTime date;
if (DateTime.TryParse(toFormat, out date))
{
string str = date.ToString(format,
DateTimeFormatInfo.CurrentInfo);
return str.Trim();
}
TimeSpan time;
bool valid = TimeSpan.TryParseExact(toFormat,
"g",
CultureInfo.CurrentCulture,
out time);
if (valid) {
return time.ToString("g");
}
return toFormat;
}
private static bool CheckValue (string toFormat)
{
if (String.IsNullOrEmpty(toFormat)) {
return false;
}
return true;
}
}
}

67
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Globals/TypeHelper.cs

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Data;
namespace ICSharpCode.Reporting.Globals
{
/// <summary>
/// Description of TypeHelper.
/// </summary>
class TypeHelper
{
public static DbType DbTypeFromStringRepresenation(string type)
{
switch (type.ToLower())
{
case "int":
return DbType.Int16;
case "int16":
return DbType.Int16;
case "int32":
return DbType.Int32;
case "int64":
return DbType.Int64;
case "uint16":
return DbType.UInt16;
case "uint32":
return DbType.UInt32;
case "uint64":
return DbType.UInt64;
case "single":
return DbType.Single;
case "double":
return DbType.Double;
case "decimal":
return DbType.Decimal;
case "datetime" :
return DbType.DateTime;
case "datetime2" :
return DbType.DateTime2;
case "boolean" :
return DbType.Boolean;
case "nvarchar":
return DbType.String;
case "varchar":
return DbType.AnsiString;
case "binary":
return DbType.Binary;
case "currency":
return DbType.Currency;
case "guid":
return DbType.Guid;
case "xml":
return DbType.Xml;
default:
return DbType.Object;
}
}
public static TypeCode TypeCodeFromString (string type) {
if (String.IsNullOrEmpty(type)) {
throw new ArgumentNullException("type");
}
return Type.GetTypeCode( Type.GetType(type));
}
}
}

5
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/Items/BaseTextItem.cs

@ -22,6 +22,7 @@ namespace ICSharpCode.Reporting.Items @@ -22,6 +22,7 @@ namespace ICSharpCode.Reporting.Items
{
Font Font {get;set;}
string Text {get;set;}
string FormatString {get;set;}
}
public class BaseTextItem:PrintableItem,ITextItem
@ -36,6 +37,8 @@ namespace ICSharpCode.Reporting.Items @@ -36,6 +37,8 @@ namespace ICSharpCode.Reporting.Items
public string Text {get;set;}
public string FormatString {get;set;}
public override IExportColumn CreateExportColumn()
{
var ex = new ExportText();
@ -47,6 +50,8 @@ namespace ICSharpCode.Reporting.Items @@ -47,6 +50,8 @@ namespace ICSharpCode.Reporting.Items
ex.Size = Size;
ex.Font = Font;
ex.Text = Text;
ex.FormatString = FormatString;
ex.CanGrow = CanGrow;
return ex;
}

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

@ -40,7 +40,7 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -40,7 +40,7 @@ namespace ICSharpCode.Reporting.PageBuilder
ReportModel = reportModel;
Pages = new Collection<ExportPage>();
Graphics = CreateGraphics.FromSize(reportModel.ReportSettings.PageSize);
ExpressionVisitor = new ExpressionVisitor(ReportModel.ReportSettings,null);
// ExpressionVisitor = new ExpressionVisitor(ReportModel.ReportSettings,null);
}
#region create Report Sections
@ -219,7 +219,7 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -219,7 +219,7 @@ namespace ICSharpCode.Reporting.PageBuilder
internal Point DetailEnds {get; private set;}
internal ExpressionVisitor ExpressionVisitor {get; private set;}
// internal ExpressionVisitor ExpressionVisitor {get; private set;}
internal Rectangle DetailsRectangle {
get {

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

@ -13,6 +13,7 @@ using System.Drawing; @@ -13,6 +13,7 @@ using System.Drawing;
using System.Linq;
using ICSharpCode.Reporting.DataManager.Listhandling;
using ICSharpCode.Reporting.Exporter.Visitors;
using ICSharpCode.Reporting.Interfaces;
using ICSharpCode.Reporting.Interfaces.Export;
using ICSharpCode.Reporting.PageBuilder.Converter;
@ -42,6 +43,12 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -42,6 +43,12 @@ namespace ICSharpCode.Reporting.PageBuilder
base.AddPage(CurrentPage);
UpdatePageInfo();
RunExpressions(ReportModel.ReportSettings,DataSource);
var formatVisitor = new FormatVisitor(Pages);
// formatVisitor.Run();
foreach (var element in Pages) {
formatVisitor.Visit(element);
}
}
@ -71,7 +78,7 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -71,7 +78,7 @@ namespace ICSharpCode.Reporting.PageBuilder
InsertExportRows(exportRows);
MeasureAndArrangeContainer(row);
exportRows.Clear();
ExpressionVisitor.Visit(CurrentPage);
// ExpressionVisitor.Visit(CurrentPage);
CurrentPage.PageInfo.PageNumber = Pages.Count + 1;
Pages.Add(CurrentPage);
@ -85,7 +92,7 @@ namespace ICSharpCode.Reporting.PageBuilder @@ -85,7 +92,7 @@ namespace ICSharpCode.Reporting.PageBuilder
}
row.ExportedItems.AddRange(convertedItems);
ExpressionVisitor.Visit(row as ExportContainer);
// ExpressionVisitor.Visit(row as ExportContainer);
exportRows.Add(row);
position = new Point(CurrentSection.Location.X,position.Y + row.DesiredSize.Height + 1);
}

4
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Src/PageBuilder/ExportColumns/ExportText.cs

@ -23,6 +23,7 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns @@ -23,6 +23,7 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
{
Font Font {get;set;}
string Text {get;set;}
string FormatString {get;set;}
}
@ -41,6 +42,9 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns @@ -41,6 +42,9 @@ namespace ICSharpCode.Reporting.PageBuilder.ExportColumns
public string Text {get;set;}
public string FormatString {get;set;}
public override ICSharpCode.Reporting.Arrange.IMeasurementStrategy MeasurementStrategy()
{

1
src/AddIns/Misc/Reporting/ICSharpCode.Reporting/Test/ICSharpCode.Reporting.Test/src/TestReports/FromList.srd

@ -83,6 +83,7 @@ @@ -83,6 +83,7 @@
<Size>100, 20</Size>
<BackColor>White</BackColor>
<Font>Segoe UI, 9pt</Font>
<FormatString>#,##0.00</FormatString>
<StringTrimming>None</StringTrimming>
<ContentAlignment>TopLeft</ContentAlignment>
<CanGrow>False</CanGrow>

Loading…
Cancel
Save