Index: ActiviteitenOpvolging/ActiviteitenOpvolging/grids/custom controls/BorderCell.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/grids/custom controls/BorderCell.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/grids/custom controls/BorderCell.vb (revision 1696) @@ -0,0 +1,31 @@ +Public Class BorderCell + Inherits DataGridViewTextBoxCell + + Protected Overrides Sub Paint(graphics As Graphics, clipBounds As Rectangle, cellBounds As Rectangle, rowIndex As Integer, cellState As DataGridViewElementStates, value As Object, formattedValue As Object, errorText As String, cellStyle As DataGridViewCellStyle, advancedBorderStyle As DataGridViewAdvancedBorderStyle, paintParts As DataGridViewPaintParts) + MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts) + + 'Ignore if thickness is too small. + if _borderThickness = 0 Then Return + + 'Specify size and position of the border. + Dim borderRect = New Rectangle(cellBounds.X + 1, cellBounds.Y + 1, cellBounds.Width - 4, cellBounds.Height - 4) + 'Draw border with specified thickness. + graphics.DrawRectangle(New Pen(BorderColor, _borderThickness), borderRect) + + 'Create spacing between text and border. + Me.Style.Padding = New Padding(1) + End Sub + + Private _borderThickness As Integer = 1 + Property BorderThickness As Integer + Set(thickness As Integer) + If thickness < 0 Then Throw New Exception($"Border thickness of {Me.GetType().Name} can't be smaller than 0.") + _borderThickness = thickness + End Set + Get + Return _borderThickness + End Get + End Property + + Public Property BorderColor As Color = Drawing.Color.Black +End Class Index: ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.vb =================================================================== diff -u -r1695 -r1696 --- ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.vb (.../DataGridViewUserControl.vb) (revision 1695) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/grids/DataGridViewUserControl.vb (.../DataGridViewUserControl.vb) (revision 1696) @@ -92,6 +92,7 @@ column.ReadOnly = True Next + WorkItemsDataGridView.Refresh() Catch ex As Exception MessageBox.Show($"Could not load {Me.Name}.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally @@ -153,6 +154,7 @@ Dim activity = workItem.Activities(i) 'Make a column for every activity with the necessary header text. Dim column As New DataGridViewTextBoxColumn With { + .CellTemplate = New BorderedTextFigureCell(), .Name = $"{activity.Label}ActivityColumn", .HeaderText = activity.Label, .DisplayIndex = presentColumns + i - 3 'Update the display index. Up the index for every column. -3 because of the other columns present. @@ -197,31 +199,60 @@ ''' Private Sub ColorWorkItems(workItems As List(Of IWorkItem)) 'Loop for every work item (need access to index because of row index in data grid) - For i = 0 To workItems.Count - 1 + For Each row As DataGridViewRow In WorkItemsDataGridView.Rows 'Get the work item. - Dim workItem = workItems.Item(i) - 'Update due out color. - UpdateDueOutCellColor(workItem, i) + Dim workItem = workItems.Item(row.Index) + 'Update the colors of the activities. + UpdateActivityCells(workItem, row) Next End Sub ''' - ''' Update the color of a cell in the due out column. + ''' Update the color of the cells for each activity. ''' - ''' - ''' - Private Sub UpdateDueOutCellColor(workItem As IWorkItem, index As Integer) - 'Fetch the right cell. - Dim cell = WorkItemsDataGridView.Rows.Item(index).Cells(DueOut.Index) + Private Sub UpdateActivityCells(workItem As IWorkItem, row As DataGridViewRow) + 'Calculate the index of the first activity column. + Dim firstActivityCellIndex = row.Cells.Count - workItem.Activities.Count + 'Loop for every activity. + For activityIndex As Integer = 0 To workItem.Activities.Count - 1 + Dim activity = workItem.Activities.Item(activityIndex) + 'Fetch the right cell. Based on the activity, the offset is the index of the first activity. + Dim cell = row.Cells.Item(activityIndex + firstActivityCellIndex) + UpdateActivityCell(activity, cell) + Next + End Sub - 'If all activities of a batch have status "F" (excluding ReadOnly Activities) => AgColorDueOutDefault - If workItem.Activities.All(Function(activity) activity.Status = ActivityStateEnum.Finished And activity.IsReadOnly = False) Then - 'todo cell.Style.BackColor = ConfigsLoader.ColorsDueOut(DueOutStateEnum.Defaulted) + ''' + ''' Update the color and border of the cell of an activity. + ''' + ''' + ''' + Private Sub UpdateActivityCell(activity As IActivity, dataGridViewCell As DataGridViewCell) + 'Only this type of cell is supported. + If Not TypeOf dataGridViewCell Is BorderedTextFigureCell Then Throw New InternalException($"Only cells of type {TypeName(New BorderedTextFigureCell)} are supported when updating the cell for an activity.") + + 'Cast cell as right type. + Dim cell As BorderedTextFigureCell = dataGridViewCell + + 'Remove border. + cell.BorderThickness = 0 + + 'Undefined start timestamp is ignored. + If activity.StartTimeStamp = DateTime.MinValue Then + cell.Figure = Nothing Return End If - 'If the StartBefore, StartAlmost and Start timestamps are not present in any of the activities, no colors are used. + If activity.StartBeforeTimestamp < DateTime.Now Then + cell.Figure = ConfigsLoader.ActivityBeforeStatusImage + ElseIf activity.StartAlmostTimeStamp < DateTime.Now Then + cell.Figure = ConfigsLoader.ActivityAlmostStatusImage + ElseIf activity.StartTimeStamp < DateTime.Now Then + 'todo conDueOutStart + Else + cell.Figure = Nothing + End If End Sub ''' Index: ActiviteitenOpvolging/ActiviteitenOpvolging/grids/custom controls/BorderedTextFigureCell.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/grids/custom controls/BorderedTextFigureCell.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/grids/custom controls/BorderedTextFigureCell.vb (revision 1696) @@ -0,0 +1,15 @@ +Public Class BorderedTextFigureCell + Inherits BorderCell + + Protected Overrides Sub Paint(graphics As Graphics, clipBounds As Rectangle, cellBounds As Rectangle, rowIndex As Integer, elementState As DataGridViewElementStates, value As Object, formattedValue As Object, errorText As String, cellStyle As DataGridViewCellStyle, advancedBorderStyle As DataGridViewAdvancedBorderStyle, paintParts As DataGridViewPaintParts) + MyBase.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts) + + If Figure IsNot Nothing Then + Dim imageSize = cellBounds.Height - BorderThickness - 3 + Dim imagePos As New Rectangle(cellBounds.Right - BorderThickness - imageSize - 2, cellBounds.Y + BorderThickness, imageSize, imageSize) + graphics.DrawImage(Figure, imagePos) + End If + End Sub + + Property Figure As Image +End Class Index: ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj =================================================================== diff -u -r1695 -r1696 --- ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj (.../ActiviteitenOpvolging.vbproj) (revision 1695) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj (.../ActiviteitenOpvolging.vbproj) (revision 1696) @@ -91,6 +91,8 @@ Form + + @@ -142,8 +144,6 @@ - - - + \ No newline at end of file