Index: ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.vb =================================================================== diff -u -r1682 -r1684 --- ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.vb (.../DataGridViewUserControl.vb) (revision 1682) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.vb (.../DataGridViewUserControl.vb) (revision 1684) @@ -1,5 +1,4 @@ -Imports System.ComponentModel -Imports ActiviteitenOpvolging.configs +Imports ActiviteitenOpvolging.configs Public Class DataGridViewUserControl Implements IDataGridUserControl @@ -39,30 +38,76 @@ 'Set label. GridLabel.Text = ConfigsLoader.GridLabelNames(_gridNumber) + 'Set properties of datagrid view. + WorkItemsDataGridView.AutoGenerateColumns = False + 'Load all work items. - LoadWorkItems() + Dim workItems = LoadWorkItems() + + 'Generate grid columns for the activities of the work items. + GenerateActivityColumns(workItems) + + 'Show the work items. + ShowWorkItems(workItems) Catch ex As Exception - Throw New InternalException($"Could not load {Me.Name}.{vbNewLine}{ex.Message}") + MessageBox.Show($"Could not load {Me.Name}.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub ''' - ''' Load and show work items. + ''' Load work items. ''' - Private Sub LoadWorkItems() + Private Function LoadWorkItems() As List(Of IWorkItem) Try - Dim workItems As List(Of IWorkItem) = _parentForm.GetWorkItems(_gridNumber) - ShowWorkItems(workItems) + Return _parentForm.GetWorkItems(_gridNumber) Catch ex As Exception - + Throw New Exception($"Could not load work items.{vbNewLine}{ex.Message}") End Try + End Function + + ''' + ''' Generate the columns for the activities. + ''' + ''' + Private Sub GenerateActivityColumns(workItems As List(Of IWorkItem)) + 'No work items need no extra columns. + If workItems.Count = 0 Then Return + + 'Get the first work item as this will provide all the necessary info. + Dim workItem = workItems.Item(0) + + For Each activity In workItem.Activities + 'Make a column for every activity with the necessary header text. + Dim column As New DataGridViewTextBoxColumn With { + .HeaderText = activity.Label + } + + WorkItemsDataGridView.Columns.Add(column) + Next End Sub ''' ''' Visualize work items in grid. ''' ''' Private Sub ShowWorkItems(workItems As List(Of IWorkItem)) + Try + For Each workItem In workItems + 'Loop through each work item. + 'Load normal parameters. + Dim data As New List(Of String) From { + workItem.BatchVisual, + workItem.EndTimeStamp, + workItem.ProductGroup, + workItem.DeliverToResource, + workItem.Remark + } + data.AddRange(workItem.Activities.Select(Function(activity) activity.QuantityToProduce.ToString())) + WorkItemsDataGridView.Rows.Add(data.ToArray()) + Next + Catch ex As Exception + Throw New Exception($"Could not show work items.{vbNewLine}{ex.Message}") + End Try 'Color the work items. ColorWorkItems(workItems) End Sub Index: ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.Designer.vb =================================================================== diff -u -r1682 -r1684 --- ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.Designer.vb (.../DataGridViewUserControl.Designer.vb) (revision 1682) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.Designer.vb (.../DataGridViewUserControl.Designer.vb) (revision 1684) @@ -72,7 +72,7 @@ ' 'DeliverToResource ' - Me.DeliverToResource.HeaderText = "Aan" + Me.DeliverToResource.HeaderText = "Naar" Me.DeliverToResource.Name = "DeliverToResource" ' 'Remark