|
|
|
@ -14,162 +14,138 @@ using System.Globalization;
@@ -14,162 +14,138 @@ using System.Globalization;
|
|
|
|
|
/// Type and DbValue
|
|
|
|
|
/// </summary>
|
|
|
|
|
namespace SharpReportCore { |
|
|
|
|
public class StandartFormatter : object { |
|
|
|
|
|
|
|
|
|
public class StandardFormatter : object { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public StandartFormatter() { |
|
|
|
|
public StandardFormatter() { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///<summary>Looks witch formatting Class to use, call the approbiate formatter
|
|
|
|
|
/// and update the DbValue with the formatted String value
|
|
|
|
|
/// </summary>
|
|
|
|
|
///<param name="item">A ReportDataItem</param>
|
|
|
|
|
///
|
|
|
|
|
public string FormatItem (BaseDataItem item) { |
|
|
|
|
public string FormatItem (string valueToFormat,string formatString, |
|
|
|
|
TypeCode typeCode,string nullValue) { |
|
|
|
|
string retValue = String.Empty; |
|
|
|
|
|
|
|
|
|
if (item == null) { |
|
|
|
|
throw new ArgumentNullException("item"); |
|
|
|
|
if (String.IsNullOrEmpty(formatString)) { |
|
|
|
|
retValue = valueToFormat; |
|
|
|
|
return retValue; |
|
|
|
|
} |
|
|
|
|
string retValue = String.Empty; |
|
|
|
|
|
|
|
|
|
switch (item.DataType) { |
|
|
|
|
|
|
|
|
|
case "System.DateTime" : |
|
|
|
|
retValue = DateValues(item.DbValue,item.FormatString); |
|
|
|
|
switch (typeCode) { |
|
|
|
|
case TypeCode.Int16: |
|
|
|
|
case TypeCode.Int32: |
|
|
|
|
retValue = IntegerValues (valueToFormat,formatString); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "System.Int16": |
|
|
|
|
retValue = IntegerValues ("16",item.DbValue,item.FormatString); |
|
|
|
|
case TypeCode.DateTime: |
|
|
|
|
retValue = DateValues(valueToFormat,formatString); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "System.Int32" : |
|
|
|
|
retValue = IntegerValues ("32",item.DbValue,item.FormatString); |
|
|
|
|
case TypeCode.Boolean: |
|
|
|
|
retValue = BoolValue (valueToFormat,formatString); |
|
|
|
|
break; |
|
|
|
|
case "System.Decimal": |
|
|
|
|
retValue = DecimalValues (item.DbValue,item.FormatString); |
|
|
|
|
case TypeCode.Decimal: |
|
|
|
|
retValue = DecimalValues (valueToFormat,formatString); |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case "System.Boolean": |
|
|
|
|
retValue = BoolValue (item.DbValue,item.FormatString); |
|
|
|
|
|
|
|
|
|
case TypeCode.Double: |
|
|
|
|
case TypeCode.Single: |
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
case TypeCode.String: |
|
|
|
|
case TypeCode.Char: |
|
|
|
|
retValue = valueToFormat; |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
retValue = item.DbValue; |
|
|
|
|
retValue = valueToFormat; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return retValue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///<summary>Looks witch formatting Class to use, call the approbiate formatter
|
|
|
|
|
/// and update the DbValue with the formatted String value
|
|
|
|
|
/// </summary>
|
|
|
|
|
///<param name="item">A ReportDataItem</param>
|
|
|
|
|
///
|
|
|
|
|
public string FormatItem (BaseDataItem item) { |
|
|
|
|
|
|
|
|
|
if (item == null) { |
|
|
|
|
throw new ArgumentNullException("item"); |
|
|
|
|
} |
|
|
|
|
return FormatItem(item.DbValue,item.FormatString, |
|
|
|
|
Type.GetTypeCode( Type.GetType(item.DataType)), |
|
|
|
|
item.NullValue); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string BoolValue (string toFormat, string format){ |
|
|
|
|
private string BoolValue (string toFormat, string format){ |
|
|
|
|
string str = String.Empty; |
|
|
|
|
if (StandartFormatter.CheckFormat(format) == true) { |
|
|
|
|
|
|
|
|
|
if (StandartFormatter.CheckValue (toFormat)) { |
|
|
|
|
try { |
|
|
|
|
bool b = bool.Parse (toFormat); |
|
|
|
|
str = b.ToString (CultureInfo.CurrentCulture); |
|
|
|
|
|
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
try { |
|
|
|
|
bool b = bool.Parse (toFormat); |
|
|
|
|
str = b.ToString (CultureInfo.CurrentCulture); |
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
// string s = String.Format("\tBool Value < {0} > {1}",toFormat,e.Message);
|
|
|
|
|
// System.Console.WriteLine("\t\t{0}",s);
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
str = toFormat; |
|
|
|
|
} |
|
|
|
|
return str; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string IntegerValues(string valueType,string toFormat, string format) { |
|
|
|
|
private string IntegerValues(string toFormat, string format) { |
|
|
|
|
string str = String.Empty; |
|
|
|
|
if (StandartFormatter.CheckFormat(format) == true) { |
|
|
|
|
if (StandartFormatter.CheckValue (toFormat)) { |
|
|
|
|
try { |
|
|
|
|
int number; |
|
|
|
|
switch (valueType) { |
|
|
|
|
case "16": |
|
|
|
|
number = Int16.Parse (toFormat, |
|
|
|
|
System.Globalization.NumberStyles.Any, |
|
|
|
|
CultureInfo.CurrentCulture.NumberFormat); |
|
|
|
|
break; |
|
|
|
|
case "32" : |
|
|
|
|
number = Int32.Parse (toFormat, |
|
|
|
|
System.Globalization.NumberStyles.Any, |
|
|
|
|
CultureInfo.CurrentCulture.NumberFormat); |
|
|
|
|
break; |
|
|
|
|
default: |
|
|
|
|
throw new ArgumentException("DefaultFormater:IntegerValues Unknown intType "); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
str = number.ToString (format,CultureInfo.CurrentCulture); |
|
|
|
|
|
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
if (StandardFormatter.CheckValue (toFormat)) { |
|
|
|
|
try { |
|
|
|
|
int number = Int32.Parse (toFormat, |
|
|
|
|
System.Globalization.NumberStyles.Any, |
|
|
|
|
CultureInfo.CurrentCulture.NumberFormat); |
|
|
|
|
|
|
|
|
|
str = number.ToString (format,CultureInfo.CurrentCulture); |
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
// string s = String.Format("\tDecimalValue < {0} > {1}",toFormat,e.Message);
|
|
|
|
|
// System.Console.WriteLine("\t{0}",s);
|
|
|
|
|
} |
|
|
|
|
return str; |
|
|
|
|
} else { |
|
|
|
|
str = (0.0M).ToString(CultureInfo.CurrentCulture); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return str; |
|
|
|
|
} else { |
|
|
|
|
str = toFormat; |
|
|
|
|
str = (0.0M).ToString(CultureInfo.CurrentCulture); |
|
|
|
|
} |
|
|
|
|
return str; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string DecimalValues(string toFormat, string format) { |
|
|
|
|
private string DecimalValues(string toFormat, string format) { |
|
|
|
|
string str = String.Empty; |
|
|
|
|
if (StandartFormatter.CheckFormat(format) == true) { |
|
|
|
|
|
|
|
|
|
if (StandartFormatter.CheckValue (toFormat)) { |
|
|
|
|
try { |
|
|
|
|
decimal dec = Decimal.Parse(toFormat, |
|
|
|
|
System.Globalization.NumberStyles.Any, |
|
|
|
|
CultureInfo.CurrentCulture.NumberFormat); |
|
|
|
|
str = dec.ToString (format,CultureInfo.CurrentCulture); |
|
|
|
|
|
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
if (StandardFormatter.CheckValue (toFormat)) { |
|
|
|
|
try { |
|
|
|
|
decimal dec = Decimal.Parse(toFormat, |
|
|
|
|
System.Globalization.NumberStyles.Any, |
|
|
|
|
CultureInfo.CurrentCulture.NumberFormat); |
|
|
|
|
str = dec.ToString (format,CultureInfo.CurrentCulture); |
|
|
|
|
|
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
// string s = String.Format("\tDecimalValue < {0} > {1}",toFormat,e.Message);
|
|
|
|
|
// System.Console.WriteLine("\t{0}",s);
|
|
|
|
|
} |
|
|
|
|
return str; |
|
|
|
|
} else { |
|
|
|
|
str = (0.0M).ToString(CultureInfo.CurrentCulture); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return str; |
|
|
|
|
} else { |
|
|
|
|
str = toFormat; |
|
|
|
|
str = (0.0M).ToString(CultureInfo.CurrentCulture); |
|
|
|
|
} |
|
|
|
|
return str; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public string DateValues(string toFormat, string format) { |
|
|
|
|
|
|
|
|
|
if (StandartFormatter.CheckFormat(format) == true) { |
|
|
|
|
try { |
|
|
|
|
DateTime date = DateTime.Parse (toFormat.Trim(), |
|
|
|
|
CultureInfo.CurrentCulture.DateTimeFormat); |
|
|
|
|
string str = date.ToString(format, |
|
|
|
|
DateTimeFormatInfo.CurrentInfo); |
|
|
|
|
|
|
|
|
|
return str.Trim(); |
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
private string DateValues(string toFormat, string format) { |
|
|
|
|
try { |
|
|
|
|
DateTime date = DateTime.Parse (toFormat.Trim(), |
|
|
|
|
CultureInfo.CurrentCulture.DateTimeFormat); |
|
|
|
|
string str = date.ToString(format, |
|
|
|
|
DateTimeFormatInfo.CurrentInfo); |
|
|
|
|
|
|
|
|
|
return str.Trim(); |
|
|
|
|
} catch (System.FormatException) { |
|
|
|
|
// string s = String.Format("< {0} > {1}",toFormat,e.Message);
|
|
|
|
|
// System.Console.WriteLine("\t\tDateValue {0}",s);
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
return toFormat.Trim(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return toFormat.Trim(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static bool CheckFormat (string format) { |
|
|
|
|
if (String.IsNullOrEmpty(format)) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static bool CheckValue (string toFormat) { |
|
|
|
|
if (String.IsNullOrEmpty(toFormat)) { |
|
|
|
|
return false; |
|
|
|
|