Index: ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj =================================================================== diff -u -r1674 -r1677 --- ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj (.../ActiviteitenOpvolging.vbproj) (revision 1674) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj (.../ActiviteitenOpvolging.vbproj) (revision 1677) @@ -75,6 +75,10 @@ + + + + @@ -87,6 +91,7 @@ + True @@ -135,5 +140,6 @@ + \ No newline at end of file Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/IWorkItem.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/IWorkItem.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/IWorkItem.vb (revision 1677) @@ -0,0 +1,13 @@ +Public Interface IWorkItem + 'Fixed fields. + Property BatchVisual As Integer + 'Optional fields. + Property DeliverToResource As String + Property ProductGroup As String + Property Remark As String + Property StartBeforeTimestamp As TimeSpan + Property StartAlmostTimeStamp As TimeSpan + Property StartTimeStamp As TimeSpan + Property EndTimeStamp As TimeSpan + Property Activities As List(Of IActivity) +End Interface Index: ActiviteitenOpvolging/ActiviteitenOpvolging/Form1.vb =================================================================== diff -u -r1673 -r1677 --- ActiviteitenOpvolging/ActiviteitenOpvolging/Form1.vb (.../Form1.vb) (revision 1673) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/Form1.vb (.../Form1.vb) (revision 1677) @@ -25,6 +25,11 @@ userControls.Add(userControl) Me.FlowLayoutPanel1.Controls.Add(userControl) Next + + dim datas = CacheMapper.GetData(0) + for each dataqs In datas + + Next End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Index: ActiviteitenOpvolging/ActiviteitenOpvolging/mappers/CacheMapper.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/mappers/CacheMapper.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/mappers/CacheMapper.vb (revision 1677) @@ -0,0 +1,121 @@ +Imports System.Data.Odbc +Imports ActiviteitenOpvolging.configs + +Module CacheMapper + Private _sqlConnection As OdbcConnection + +#Region "Help functions" + ''' + ''' Helpfunction to open SQL connection to Caché. + ''' + Private Sub ConnectToCache() + Try + If _sqlConnection Is Nothing Then + 'Build connection string. Looks something like this "DSN=...; DRIVER={InterSystems ODBC}; SERVER=CACHE01;DATABASE=ADMIN1;UID=...;PWD=..." + Dim connectionString = $"DSN={My.Resources.CacheSQLConnection}; DRIVER=" & "{InterSystems ODBC}" & + $"; SERVER=CACHE01;DATABASE=ADMIN1;UID={My.Resources.CacheUsername};PWD={My.Resources.CachePassword}" + 'Initialise connection. + _sqlConnection = New OdbcConnection(connectionString) + End If + 'Check if connection state is already open. + If Not _sqlConnection.State = ConnectionState.Open Then + 'If not, open the connection. + _sqlConnection.Open() + End If + Catch ex As Exception + Throw New Exception($"Can't reach the Caché database: {vbNewLine}{ex.Message}") + End Try + End Sub + + ''' + ''' Fetch all the work items for a workpost. + ''' The corresponding query will get fetched in here. + ''' + ''' The index of the workpost, 0 based + ''' A list of all the work items with their activities + Public Function GetData(workPostIndex As Integer) As List(Of IWorkItem) + 'Fetch the query. + Dim query As String = FetchQuery(workPostIndex) + + 'Initialise the list with work items. + Dim workItems As New List(Of IWorkItem) + Try + 'Execute query and store datareader. + Dim dr = ExecuteIntoDataReader(query) + + 'Loop through every (result) record. + While dr.Read() + 'Read values of one result (line/record). + Dim workItem As New WorkItem + With workItem + .BatchVisual = ExtractItemFromDataReader(Of Integer)(dr, "BatchVisual", 0) + .DeliverToResource = ExtractItemFromDataReader(Of String)(dr, "skrr", String.Empty) + End With + + 'Add to the result list. + workItems.Add(workItem) + End While + + 'Close connection. + dr.Close() + + 'Return the list. + Return workItems + Catch ex As Exception + Throw New Exception($"An error occured while fetching the work items from Caché.{vbNewLine}{ex.Message}") + End Try + End Function + + ''' + ''' Get the correct query. + ''' + ''' + ''' + Private Function FetchQuery(workPostIndex As Integer) As String + 'Fetch queries from config. + Dim sqlQueries = ConfigsLoader.SqlQueries() + 'Check if index is valid. + If workPostIndex >= sqlQueries.Count Or workPostIndex < 0 Then + Throw New InternalException($"Can't fetch a Caché query with this work post index: {workPostIndex}") + End If + 'If so, return correct query. + Return sqlQueries.Item(workPostIndex) + End Function + + ''' + ''' Execution of a query into a data reader. + ''' + ''' The query + ''' The ODBC data reader + Private Function ExecuteIntoDataReader(query As String) As OdbcDataReader + Try + ConnectToCache() + Return New OdbcCommand(query, _sqlConnection).ExecuteReader() + Catch ex As Exception + Throw New Exception($"Could not get data reader from the Caché database.{vbNewLine}{ex.Message}") + End Try + End Function + + Private Function ExtractItemFromDataReader(Of T)(ByRef dr As OdbcDataReader, key As String, Optional defaultValue As T = Nothing) As T + Dim value As Object + Try + 'Extract the value with the key. + value = dr.Item(key) + 'Check if the value is DBNull or normal Nothing. + If IsDBNull(value) Or value Is Nothing Then + 'If so, return default value. + Return defaultValue + End If + Catch ex As Exception + Throw New Exception($"A value for a work item can't be fetched from the data reader. The key is '{key}'.") + End Try + Try + 'Do the conversion explicitly, so exceptions can be caught. + Return CType(value, T) + Catch ex As Exception + Throw New Exception($"A value for a work item can't be converted to the specified type. The key is '{key}', the type is {NameOf(T)}, the value is {value}.") + End Try + End Function + +#End Region +End Module Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/WorkItem.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/WorkItem.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/WorkItem.vb (revision 1677) @@ -0,0 +1,13 @@ +Public Class WorkItem + implements IWorkItem + + Public Property BatchVisual As Integer Implements IWorkItem.BatchVisual + Public Property DeliverToResource As String Implements IWorkItem.DeliverToResource + Public Property ProductGroup As String Implements IWorkItem.ProductGroup + Public Property Remark As String Implements IWorkItem.Remark + Public Property StartBeforeTimestamp As TimeSpan Implements IWorkItem.StartBeforeTimestamp + Public Property StartAlmostTimeStamp As TimeSpan Implements IWorkItem.StartAlmostTimeStamp + Public Property StartTimeStamp As TimeSpan Implements IWorkItem.StartTimeStamp + Public Property EndTimeStamp As TimeSpan Implements IWorkItem.EndTimeStamp + Public Property Activities As List(Of IActivity) Implements IWorkItem.Activities +End Class Index: ActiviteitenOpvolging/ActiviteitenOpvolging/My Project/Resources.resx =================================================================== diff -u -r1670 -r1677 --- ActiviteitenOpvolging/ActiviteitenOpvolging/My Project/Resources.resx (.../Resources.resx) (revision 1670) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/My Project/Resources.resx (.../Resources.resx) (revision 1677) @@ -118,15 +118,15 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + fixed The password for the Caché database Cache01Admin1 The name of the connection for the Caché database - + ICT_READONLY The username for the Caché database Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/IActivity.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/IActivity.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/IActivity.vb (revision 1677) @@ -0,0 +1,8 @@ +Public Interface IActivity + Property Id As String + Property QuantityToProduce As Integer + Property Label As String + Property Status As ActivityStateEnum + Property User As String + Property IsReadOnly As Boolean +End interface Index: ActiviteitenOpvolging/ActiviteitenOpvolging/configs/ConfigsTextmapper.vb =================================================================== diff -u -r1669 -r1677 --- ActiviteitenOpvolging/ActiviteitenOpvolging/configs/ConfigsTextmapper.vb (.../ConfigsTextmapper.vb) (revision 1669) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/configs/ConfigsTextmapper.vb (.../ConfigsTextmapper.vb) (revision 1677) @@ -74,8 +74,8 @@ If (m.Success) Then 'If successful, overwrite each multiline from the groups as one line, without the seperator symbols 'µ'. For Each group In m.Groups - 'Remove newLines. - Dim onelineString = group.Value.Replace(vbCr, String.Empty).Replace(vbLf, String.Empty) + 'Remove newLines, replace by space. + Dim onelineString = group.Value.Replace(vbCr, " ").Replace(vbLf, " ") 'Remove special characters. onelineString = onelineString.Replace("__", String.Empty) 'Overwrite multiline entry in text. Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/Activity.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/Activity.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/Activity.vb (revision 1677) @@ -0,0 +1,9 @@ +Public Class Activity + implements IActivity + Public Property Id As String Implements IActivity.Id + Public Property QuantityToProduce As Integer Implements IActivity.QuantityToProduce + Public Property Label As String Implements IActivity.Label + Public Property Status As ActivityStateEnum Implements IActivity.Status + Public Property User As String Implements IActivity.User + Public Property IsReadOnly As Boolean Implements IActivity.IsReadOnly +End Class Index: ActiviteitenOpvolging/ActiviteitenOpvolging/My Project/Resources.Designer.vb =================================================================== diff -u -r1670 -r1677 --- ActiviteitenOpvolging/ActiviteitenOpvolging/My Project/Resources.Designer.vb (.../Resources.Designer.vb) (revision 1670) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/My Project/Resources.Designer.vb (.../Resources.Designer.vb) (revision 1677) @@ -61,7 +61,7 @@ End Property ''' - ''' Looks up a localized string similar to . + ''' Looks up a localized string similar to fixed. ''' Friend ReadOnly Property CachePassword() As String Get @@ -79,7 +79,7 @@ End Property ''' - ''' Looks up a localized string similar to . + ''' Looks up a localized string similar to ICT_READONLY. ''' Friend ReadOnly Property CacheUsername() As String Get