Imports System.Windows.Navigation
Imports ProductiePitching.configs
Public Class EmployeeDetailUserControl
Implements IEmployeeDetailUserControl
Private ReadOnly _parentUserControl As IEmployeeDetailParentUserControl
Private Sub New()
' This call is required by the designer.
InitializeComponent()
End Sub
'''
''' Initialises the user form.
'''
''' The form containing this user control
Sub New(parentForm As IEmployeeUserControl)
'Call base constructor.
Me.New()
'Set parameters.
'Parent form.
'Value can't be Nothing.
If parentForm Is Nothing Then Throw New InternalException($"The parent user control can't be 'Nothing' in a {Me.Name}.")
_parentUserControl = parentForm
End Sub
Private Sub EmployeeUserControl_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Try
'Set back color corresponding to the employee index.
BackColor = Color.White
ForeColor = Color.Black
'Set border colors of the buttons.
StartButton.BackColor = ConfigsLoader.ColorsActivities(ActivityStateEnum.Started)
StopButton.BackColor = ConfigsLoader.ColorsActivities(ActivityStateEnum.Stopped)
FinishButton.BackColor = ConfigsLoader.ColorsActivities(ActivityStateEnum.Finished)
'Fetch and show the employee.
LoadEmployee()
Catch ex As Exception
MessageBox.Show($"Could not load {Me.Name}.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
'''
Public Function RefreshData() As Boolean Implements IEmployeeDetailUserControl.RefreshData
Try
LoadEmployee()
Return True
Catch ex As Exception
Return False
End Try
End Function
'''
''' Load the employee
'''
Private Sub LoadEmployee()
'Fetch the employee.
Dim employee = _parentUserControl.FetchEmployee()
'If employee is nothing, do nothing.
if employee is Nothing then Return
'Show all information on screen.
NameLabel.Text = $"{employee.FirstName} {employee.LastName}"
Try
ImagePictureBox.Load(employee.Picture)
Catch ex As Exception
'Default image.
ImagePictureBox.Image = My.Resources.user
End Try
'If activity is Nothing, empty the labels.
If IsNothing(employee.CurrentActivity) Then
'Nothing, empty or hide labels.
BatchVisualLabel.Visible = False
ActivityVisualLabel.Visible = False
StatusLabel.Text = String.Empty
BatchLabel.Text = String.Empty
ActivityNameLabel.Text = String.Empty
Else
'Show visual labels.
BatchVisualLabel.Visible = True
ActivityVisualLabel.Visible = True
Dim activity = employee.CurrentActivity
'Set activity status according to state.
Select Case activity.Status
Case ActivityStateEnum.Started
StatusLabel.Text = "Gestart"
Case ActivityStateEnum.Finished
StatusLabel.Text = "Afgewerkt"
Case ActivityStateEnum.Stopped
StatusLabel.Text = "Onderbroken"
Case ActivityStateEnum.Defaulted
StatusLabel.Text = "Beschikbaar"
End Select
BatchLabel.Text = activity.WorkItem.BatchVisual
ActivityNameLabel.Text = activity.Label
End If
'Get the activity selected in one of the grids.
Dim currentlySelectedActivity = _parentUserControl.GetCurrentlySelectedActivity()
'Update enable status of buttons.
If IsNothing(employee.CurrentActivity) Then
'No current activity.
StopButton.visible = False
FinishButton.visible = False
'Start button visible when the selected activity can be started (you shouldn't be able to select an activity that can't be started).
StartButton.visible = Not IsNothing(currentlySelectedActivity)
Else
'An activity in progress can be stopped or finished.
StartButton.visible = False
StopButton.visible = True
FinishButton.visible = True
End If
End Sub
Private Sub RemoveEmployeeButton_Click(sender As Object, e As EventArgs) Handles RemoveEmployeeButton.Click
Try
_parentUserControl.DeselectEmployee()
Catch ex As Exception
MessageBox.Show($"Could not remove user.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub StartButton_Click(sender As Object, e As EventArgs) Handles StartButton.Click
Try
_parentUserControl.StartActivity()
Catch ex As Exception
MessageBox.Show($"Could not start activity.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub StopButton_Click(sender As Object, e As EventArgs) Handles StopButton.Click
Try
_parentUserControl.StopActivity()
Catch ex As Exception
MessageBox.Show($"Could not stop activity.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Private Sub FinishButton_Click(sender As Object, e As EventArgs) Handles FinishButton.Click
Try
_parentUserControl.FinishActivity()
Catch ex As Exception
MessageBox.Show($"Could not stop activity.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class