diff --git a/MultiTool.Shared/Documents/DocumentLoader.vb b/MultiTool.Shared/Documents/DocumentLoader.vb index 9d4b6cb..e0ed847 100644 --- a/MultiTool.Shared/Documents/DocumentLoader.vb +++ b/MultiTool.Shared/Documents/DocumentLoader.vb @@ -153,46 +153,79 @@ Namespace Documents Where(Function(t) t.Name = oTopLevelElement.Name). FirstOrDefault() - For Each oSubElement As XElement In oSubElements - Dim oSchemaField = oTable.Columns. - Where(Function(c) c.Name = oSubElement.Name). + For Each oColumn In oTable.Columns + Dim oSubElement = oSubElements. + Where(Function(e) e.Name = oColumn.Name). SingleOrDefault() - Dim oRequired = oSchemaField.IsRequired - Dim oValue = oSubElement.Value.Trim() + If oSubElement IsNot Nothing Then + Dim oRequired = oColumn.IsRequired + Dim oValue = oSubElement.Value.Trim() - ' TODO: Needed when we have time for date times - 'If oSchemaField.DataType = Constants.ColumnType.Date Then - ' Dim oDate = Date.ParseExact(oValue, "yyyy-MM-dd", CultureInfo.InvariantCulture) - ' oValue = oDate.ToString("d") - 'End If + ' TODO: Needed when we have time for date times + 'If oSchemaField.DataType = Constants.ColumnType.Date Then + ' Dim oDate = Date.ParseExact(oValue, "yyyy-MM-dd", CultureInfo.InvariantCulture) + ' oValue = oDate.ToString("d") + 'End If - oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With { - .Original = oValue, - .Final = oValue, - .DataType = oSchemaField.DataType, - .Required = oRequired - }) + oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With { + .Original = oValue, + .Final = oValue, + .DataType = oColumn.DataType, + .Required = oRequired + }) + Else + Dim oColumnError = DocumentRow.FieldError.None + If oColumn.Config?.IsRequired Then + oColumnError = DocumentRow.FieldError.MissingValue + End If + oFields.Add(oColumn.Name, New DocumentRow.FieldValue With { + .[Error] = oColumnError + }) + End If Next - ' All fields in the schema are generated, - ' only creating the ones with values leads to wrong visual cues when asking for - ' docs/rows/fields with errors - For Each oColumn In oTable.Columns - If oFields.ContainsKey(oColumn.Name) Then - Continue For - End If + 'For Each oSubElement As XElement In oSubElements + ' Dim oSchemaField = oTable.Columns. + ' Where(Function(c) c.Name = oSubElement.Name). + ' SingleOrDefault() - Dim oColumnError = DocumentRow.FieldError.None - If oColumn.Config?.IsRequired Then - oColumnError = DocumentRow.FieldError.MissingValue - End If + ' Dim oRequired = oSchemaField.IsRequired + ' Dim oValue = oSubElement.Value.Trim() - oFields.Add(oColumn.Name, New DocumentRow.FieldValue With { - .[Error] = oColumnError - }) - Next + ' ' TODO: Needed when we have time for date times + ' 'If oSchemaField.DataType = Constants.ColumnType.Date Then + ' ' Dim oDate = Date.ParseExact(oValue, "yyyy-MM-dd", CultureInfo.InvariantCulture) + ' ' oValue = oDate.ToString("d") + ' 'End If + + ' oFields.Add(oSubElement.Name.ToString, New DocumentRow.FieldValue With { + ' .Original = oValue, + ' .Final = oValue, + ' .DataType = oSchemaField.DataType, + ' .Required = oRequired + ' }) + + 'Next + + '' All fields in the schema are generated, + '' only creating the ones with values leads to wrong visual cues when asking for + '' docs/rows/fields with errors + 'For Each oColumn In oTable.Columns + ' If oFields.ContainsKey(oColumn.Name) Then + ' Continue For + ' End If + + ' Dim oColumnError = DocumentRow.FieldError.None + ' If oColumn.Config?.IsRequired Then + ' oColumnError = DocumentRow.FieldError.MissingValue + ' End If + + ' oFields.Add(oColumn.Name, New DocumentRow.FieldValue With { + ' .[Error] = oColumnError + ' }) + 'Next ' Create a DocumentRow object for each Top Level Element Dim oRow = New DocumentRow With { diff --git a/MultiTool.Shared/Documents/DocumentRow.vb b/MultiTool.Shared/Documents/DocumentRow.vb index c5fded6..137b902 100644 --- a/MultiTool.Shared/Documents/DocumentRow.vb +++ b/MultiTool.Shared/Documents/DocumentRow.vb @@ -60,7 +60,9 @@ Public ReadOnly Property HasError As Boolean Get - Return [Error] <> FieldError.None Or (Required = True And Final = String.Empty) + Return Required = True And ( + [Error] <> FieldError.None Or Final = String.Empty + ) End Get End Property