/// <summary> /// Get the strings for csv file for different data types. /// </summary> /// <param name="type">DatabaseType</param> /// <param name="cellValue">string</param> /// <param name="col">ReportColumn</param> /// <returns>string</returns> public static string GetCsvCellValue(DatabaseType type, string cellValue, ReportColumn col) { //convert cell value to its particular type object value = DatabaseTypeHelper.ConvertFromString(type, cellValue); if (cellValue == null) { return(""); } if (type is BoolType) { return(GetBooleanCellValue(( bool )value)); } if (type is AutoIncrementType) { return(DatabaseTypeHelper.ConvertToString(type, value, col.AutoNumberDisplayPattern)); } if (type is DateType || type is DateTimeType) { return(cellValue); } if (type is TimeType) { return((( DateTime )value).ToUniversalTime( ).TimeOfDay.ToString( )); } if (type is StructureLevelsType) { return(GetStructureLevelCellValue(cellValue, false)); } return(value.ToString( )); }
/// <summary> /// Get the formatted cell value for the different data types. /// </summary> public static string GetFormattedCellValue(DatabaseType type, string cellValue, ReportColumn col) { string result; //convert cell value to its particular type object value = DatabaseTypeHelper.ConvertFromString(type, cellValue); if (cellValue == null) { return(""); } if (type is BoolType) { result = GetBooleanCellValue(( bool )value); return(result); } if (type is AutoIncrementType) { result = DatabaseTypeHelper.ConvertToString(type, value, col.AutoNumberDisplayPattern); return(result); } if (type is DateType) { return((( DateTime )value).ToString("d/MM/yyyy")); } if (type is TimeType) { return((( DateTime )value).ToUniversalTime( ).ToString("h:mm tt")); } if (type is DateTimeType) { return((( DateTime )value).ToString("d/MM/yyyy h:mm tt")); } if (type is Int32Type) { return(Convert.ToInt32(value).ToString("#,##0")); } if (type is DecimalType) { long? decimalPlaces = col.DecimalPlaces; NumberFormatInfo numberFormatInfo = new CultureInfo("en-US", false).NumberFormat; numberFormatInfo.NumberDecimalDigits = decimalPlaces != null?Convert.ToInt32(decimalPlaces) : 3; decimal temp = Convert.ToDecimal(value); return(temp.ToString("N", numberFormatInfo)); } if (type is CurrencyType) { long? decimalPlaces = col.DecimalPlaces; NumberFormatInfo numberFormatInfo = new CultureInfo("en-US", false).NumberFormat; numberFormatInfo.CurrencyDecimalDigits = decimalPlaces != null?Convert.ToInt32(decimalPlaces) : 2; numberFormatInfo.CurrencySymbol = "$"; numberFormatInfo.CurrencyNegativePattern = 1; decimal temp = Convert.ToDecimal(value); return(temp.ToString("C", numberFormatInfo)); } if (type is StructureLevelsType) { return(GetStructureLevelCellValue(cellValue, true)); } result = value.ToString( ); return(result); }