/// <summary> /// wandelt bexis primardaten (rows) in bexis 2 datatuples um /// </summary> /// <param name="data"></param> /// <param name="dataStructureId"></param> /// <param name="observationIndex"></param> /// <returns></returns> public DataTuple XmlRowReader(XmlDocument data, long dataStructureId, int observationIndex) { DataStructureManager dataStructureManager = new DataStructureManager(); DataTuple dataRow = new DataTuple(); StructuredDataStructure dataStructure = dataStructureManager.StructuredDataStructureRepo.Get(dataStructureId); this.StructuredDataStructure = dataStructure; List<VariableIdentifier> variableIdentifierList = new List<VariableIdentifier>(); foreach (Variable variable in dataStructure.Variables) { VariableIdentifier vi = new VariableIdentifier(); vi.id = variable.Id; vi.name = variable.Label; vi.systemType = variable.DataAttribute.DataType.SystemType.ToString(); variableIdentifierList.Add(vi); } this.SubmitedVariableIdentifiers = variableIdentifierList; List<string> dataList = XmlRowToStringList(data, variableIdentifierList); int startRow = 0; int indexOfRow = startRow + observationIndex; //List<Error> errors = ValidateRow(dataList, indexOfRow); //if (errors.Count == 0) { dataRow = ReadRow(dataList, indexOfRow); } return dataRow; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="worksheetPart"></param> /// <param name="startRow"></param> /// <param name="endRow"></param> /// <returns></returns> private List<VariableIdentifier> getVariableIdentifiers(WorksheetPart worksheetPart, int startRow, int endRow) { //NEW OPENXMLREADER if (this.VariableIdentifiers == null || this.VariableIdentifiers.Count == 0) { OpenXmlReader reader = OpenXmlReader.Create(worksheetPart); int rowNum = 0; // read variable rows to get name and id from area variable while (reader.Read()) { if (reader.ElementType == typeof(Row)) { do { if (reader.HasAttributes) rowNum = Convert.ToInt32(reader.Attributes.First(a => a.LocalName == "r").Value); if (rowNum >= startRow && rowNum <= endRow) { Row row = (Row)reader.LoadCurrentElement(); if (row.Hidden == null) VariableIdentifierRows.Add(rowToList(row)); else if (row.Hidden != true) VariableIdentifierRows.Add(rowToList(row)); } } while (reader.ReadNextSibling() && rowNum < endRow); // Skip to the next row break; } } // convert variable rows to VariableIdentifiers if (VariableIdentifierRows != null) { foreach (List<string> l in VariableIdentifierRows) { //create headerVariables if (VariableIdentifiers.Count == 0) { foreach (string s in l) { VariableIdentifier hv = new VariableIdentifier(); hv.name = s; VariableIdentifiers.Add(hv); } } else { foreach (string s in l) { int id = Convert.ToInt32(s); int index = l.IndexOf(s); VariableIdentifiers.ElementAt(index).id = id; } } } } } if (this.VariableIdentifiers != null) return this.VariableIdentifiers; else return null; }
/// <summary> /// Get VariableUsage based on VariableIdentifer /// </summary> /// <remarks></remarks> /// <param name="hv"></param> /// <returns></returns> private Variable getVariableUsage(VariableIdentifier hv) { Variable sdvu = new Variable(); if (hv.id != 0) { var dsVar = (from v in this.StructuredDataStructure.Variables where v.Id == hv.id && v.Label == hv.name select v).FirstOrDefault(); if (dsVar != null) sdvu = dsVar; } else { var dsVar = (from v in this.StructuredDataStructure.Variables where v.Label == hv.name select v).FirstOrDefault(); if (dsVar != null) sdvu = dsVar; } return sdvu; }
/// <summary> /// Convert a list of variable names to /// VariableIdentifiers /// </summary> /// <seealso cref="VariableIdentifier"/> /// <param name="variablesRow"></param> private void convertAndAddToSubmitedVariableIdentifier() { if (VariableIdentifierRows != null) { foreach (List<string> l in VariableIdentifierRows) { //create headerVariables if (SubmitedVariableIdentifiers.Count == 0) { foreach (string s in l) { VariableIdentifier hv = new VariableIdentifier(); hv.name = s; SubmitedVariableIdentifiers.Add(hv); } } else { foreach (string s in l) { int id = Convert.ToInt32(s); int index = l.IndexOf(s); SubmitedVariableIdentifiers.ElementAt(index).id = id; } } } } }