protected string GetFormatedValue(object value, Dlm.Entities.DataStructure.DataType datatype, string format) { string tmp = value.ToString(); if (DataTypeUtility.IsTypeOf(value, datatype.SystemType)) { //Type type = Type.GetType("System." + datatype.SystemType); switch (DataTypeUtility.GetTypeCode(datatype.SystemType)) { case DataTypeCode.Int16: case DataTypeCode.Int32: case DataTypeCode.Int64: { Int64 newValue = Convert.ToInt64(tmp); return(newValue.ToString(format)); } case DataTypeCode.UInt16: case DataTypeCode.UInt32: case DataTypeCode.UInt64: { UInt64 newValue = Convert.ToUInt64(tmp); return(newValue.ToString(format)); } case DataTypeCode.Decimal: case DataTypeCode.Double: { Double newValue = Convert.ToDouble(tmp); return(newValue.ToString(format)); } case DataTypeCode.DateTime: { DateTime dateTime; return(IOUtility.ExportDateTimeString(value.ToString(), format, out dateTime)); } default: return(tmp); } } return(""); }
/// <summary> /// List of used datatypes and /// the maxvalue of the datatypes /// </summary> /// <returns></returns> private static List <string> CompareValues(StructuredDataStructure dataStructure) { List <string> cv = new List <string>(); if (dataStructure != null) { foreach (var variable in dataStructure.Variables) { StringBuilder sb = new StringBuilder(); foreach (var missingValue in variable.MissingValues) { if (DataTypeUtility.GetTypeCode(variable.DataAttribute.DataType.SystemType) == DataTypeCode.DateTime && DataTypeDisplayPattern.Materialize(variable.DataAttribute.DataType.Extra) != null) { DataTypeDisplayPattern ddp = DataTypeDisplayPattern.Materialize(variable.DataAttribute.DataType.Extra); DateTime dateTime; if (DateTime.TryParse(missingValue.Placeholder, new CultureInfo("en-US", false), DateTimeStyles.NoCurrentDateDefault, out dateTime)) { sb.Append(missingValue.DisplayName + "|" + dateTime.ToString(ddp.StringPattern) + "#%#");; } } else { sb.Append(missingValue.DisplayName + "|" + missingValue.Placeholder + "#%#"); } } //add also the case of the optional field //replace the value with EMPTY String sb.Append(" |" + getMaxvalueOfType(variable.DataAttribute.DataType.SystemType)); cv.Add(sb.ToString()); } } return(cv); }
protected string GetFormatedValue(object value, Dlm.Entities.DataStructure.DataType datatype, string format) { string tmp = value.ToString(); if (DataTypeUtility.IsTypeOf(value, datatype.SystemType)) { //Type type = Type.GetType("System." + datatype.SystemType); switch (DataTypeUtility.GetTypeCode(datatype.SystemType)) { case DataTypeCode.Int16: case DataTypeCode.Int32: case DataTypeCode.Int64: { Int64 newValue = Convert.ToInt64(tmp); return(newValue.ToString(format)); } case DataTypeCode.UInt16: case DataTypeCode.UInt32: case DataTypeCode.UInt64: { UInt64 newValue = Convert.ToUInt64(tmp); return(newValue.ToString(format)); } case DataTypeCode.Decimal: case DataTypeCode.Double: { Double newValue = Convert.ToDouble(tmp); return(newValue.ToString(format)); } case DataTypeCode.DateTime: { DateTime dateTime; if (DateTime.TryParse(tmp, out dateTime)) { return(dateTime.ToString(format)); } if (DateTime.TryParse(tmp, new CultureInfo("de-DE", false), DateTimeStyles.None, out dateTime)) { return(dateTime.ToString(format)); } if (DateTime.TryParse(tmp, new CultureInfo("en-US", false), DateTimeStyles.None, out dateTime)) { return(dateTime.ToString(format)); } if (DateTime.TryParse(tmp, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime)) { return(dateTime.ToString(format)); } return(tmp); ; } default: return(tmp); } } return(""); }