|
|
|
@ -25,39 +25,22 @@ namespace ICSharpCode.Reporting.Globals
@@ -25,39 +25,22 @@ namespace ICSharpCode.Reporting.Globals
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Description of StandardFormatter.
|
|
|
|
|
/// </summary>
|
|
|
|
|
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|