/// <summary> /// Read Row and convert each value into a variableValue /// and each row to a Datatuple /// </summary> /// <param name="row">List of values in one row</param> /// <param name="indexOfRow">Currently row index</param> /// <returns>DataTuple</returns> public DataTuple ReadRow(List <string> row, int indexOfRow) { DataTuple dt = new DataTuple(); string value = ""; // convert row to List<VariableValue> for (int i = 0; i < row.Count(); i++) { VariableIdentifier variableIdentifier = this.SubmitedVariableIdentifiers.ElementAt(i); long variableId = 0; if (variableIdentifier.id > 0) { variableId = this.SubmitedVariableIdentifiers.ElementAt(i).id; } else { variableId = getVariableUsage(variableIdentifier).Id; } // if variable from systemtype datatime // maybee needs to convert into the default datetime culture format if (this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("DateTime")) { Dlm.Entities.DataStructure.DataType dataType = this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType; if (dataType != null && dataType.Extra != null) { DataTypeDisplayPattern dp = DataTypeDisplayPattern.Materialize(dataType.Extra); if (dp != null && !string.IsNullOrEmpty(dp.StringPattern)) { value = IOUtility.ConvertToDateUS(row[i], dp.StringPattern); } else { value = IOUtility.ConvertDateToCulture(row[i]); } } else { value = IOUtility.ConvertDateToCulture(row[i]); } } else { if (this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("Double") || this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("Decimal") || this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("Float")) { value = row[i]; if (Info.Decimal.Equals(DecimalCharacter.comma)) { if (value.Contains(".")) { value = value.Replace(".", ""); } if (value.Contains(",")) { value = value.Replace(',', '.'); } } if (Info.Decimal.Equals(DecimalCharacter.point)) { if (value.Contains(",")) { value = value.Remove(','); } } } else { value = row[i]; } } dt.VariableValues.Add(DatasetManager.CreateVariableValue(value, "", DateTime.Now, DateTime.Now, new ObtainingMethod(), variableId, new List <ParameterValue>())); } return(dt); }
/// <summary> /// Read Row and convert each value into a variableValue /// and each row to a Datatuple /// </summary> /// <param name="row">List of values in one row</param> /// <param name="indexOfRow">Currently row index</param> /// <returns>DataTuple</returns> public DataTuple ReadRow(List <string> row, int indexOfRow) { if (row == null) { return(null); } if (row.Count == 1 && string.IsNullOrEmpty(row.ElementAt(0))) { return(null); } if (row.Count > this.StructuredDataStructure.Variables.Count || row.Count < this.StructuredDataStructure.Variables.Count) { throw new Exception("Number of values different then the number of values."); } DataTuple dt = new DataTuple(); string value = ""; // convert row to List<VariableValue> for (int i = 0; i < row.Count(); i++) { VariableIdentifier variableIdentifier = this.SubmitedVariableIdentifiers.ElementAt(i); long variableId = 0; if (variableIdentifier.id > 0) { variableId = this.SubmitedVariableIdentifiers.ElementAt(i).id; } else { variableId = getVariableUsage(variableIdentifier).Id; } //if the value is a missing value get the placeholder ValueValidationManager validationManager = ValueValidationManagerDic[variableId]; if (!validationManager.ValueIsMissingValueGetPlaceHolder(row[i], i, out value)) // jump over this code if its a missing value { // if variable from systemtype datatime // maybee needs to convert into the default datetime culture format if (this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("DateTime")) { Dlm.Entities.DataStructure.DataType dataType = this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType; if (dataType != null && dataType.Extra != null) { DataTypeDisplayPattern dp = DataTypeDisplayPattern.Materialize(dataType.Extra); if (dp != null && !string.IsNullOrEmpty(dp.StringPattern)) { value = IOUtility.ConvertToDateUS(row[i], dp.StringPattern); } else { value = IOUtility.ConvertDateToCulture(row[i]); } } else { value = IOUtility.ConvertDateToCulture(row[i]); } } else { if (this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("Double") || this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("Decimal") || this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType.Equals("Float")) { var datatype = this.StructuredDataStructure.Variables.Where(p => p.Id.Equals(variableId)).FirstOrDefault().DataAttribute.DataType.SystemType; value = row[i]; if (Info.Decimal.Equals(DecimalCharacter.comma)) { if (value.Contains(".")) { value = value.Replace(".", ""); } if (value.Contains(",")) { value = value.Replace(',', '.'); } } if (Info.Decimal.Equals(DecimalCharacter.point)) { if (value.Contains(",")) { value = value.Remove(','); } } switch (datatype) { case "Double": { double tmp = 0; if (double.TryParse(value, NumberStyles.Any, new CultureInfo("en-US"), out tmp)) { value = tmp.ToString("G16", new CultureInfo("en-US")); } break; } case "Decimal": { decimal tmp = 0; if (decimal.TryParse(value, NumberStyles.Any, new CultureInfo("en-US"), out tmp)) { value = "" + tmp.ToString("G29", new CultureInfo("en-US")); } break; } case "Float": { float tmp = 0; if (float.TryParse(value, NumberStyles.Any, new CultureInfo("en-US"), out tmp)) { value = "" + tmp.ToString("G7", new CultureInfo("en-US")); } break; } } } else { value = row[i].Trim(); } } } dt.VariableValues.Add(DatasetManager.CreateVariableValue(value, "", DateTime.Now, DateTime.Now, new ObtainingMethod(), variableId, new List <ParameterValue>())); } return(dt); }