Index: ActiviteitenOpvolging/ActiviteitenOpvolging/screens/IActivityMainForm.vb =================================================================== diff -u --- ActiviteitenOpvolging/ActiviteitenOpvolging/screens/IActivityMainForm.vb (revision 0) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/screens/IActivityMainForm.vb (revision 1726) @@ -0,0 +1,7 @@ +Public Interface IActivityMainForm + ''' + ''' Gets the currently selected activity. + ''' + ''' + Function GetCurrentlySelectedActivity As IActivity +End Interface Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/Employee.vb =================================================================== diff -u -r1724 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/Employee.vb (.../Employee.vb) (revision 1724) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/implementations/Employee.vb (.../Employee.vb) (revision 1726) @@ -7,7 +7,7 @@ Public Property FirstName As String Implements IEmployee.FirstName Public Property LastName As String Implements IEmployee.LastName Public Property Initials As String Implements IEmployee.Initials - Public Property currentActivity As IActivity Implements IEmployee.currentActivity + Public Property CurrentActivity As IActivity Implements IEmployee.CurrentActivity Public Overrides Function Equals(obj As Object) As Boolean Implements IEmployee.Equals If Not TypeOf obj Is IEmployee Then Index: ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/IEmployee.vb =================================================================== diff -u -r1724 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/IEmployee.vb (.../IEmployee.vb) (revision 1724) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/domain/classes/IEmployee.vb (.../IEmployee.vb) (revision 1726) @@ -5,7 +5,7 @@ Property LastName As String Property Initials As String - Property currentActivity As IActivity + Property CurrentActivity As IActivity Function Equals(obj As Object) As Boolean End Interface Index: ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/details/EmployeeDetailUserControl.vb =================================================================== diff -u -r1725 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/details/EmployeeDetailUserControl.vb (.../EmployeeDetailUserControl.vb) (revision 1725) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/details/EmployeeDetailUserControl.vb (.../EmployeeDetailUserControl.vb) (revision 1726) @@ -64,13 +64,13 @@ NameLabel.Text = $"{employee.FirstName} {employee.LastName}" 'If activity is Nothing, empty the labels. - If IsNothing(employee.currentActivity) Then + If IsNothing(employee.CurrentActivity) Then 'Nothing, empty labels. StatusLabel.Text = String.Empty BatchLabel.Text = String.Empty ActivityNameLabel.Text = String.Empty Else - Dim activity = employee.currentActivity + Dim activity = employee.CurrentActivity 'Set activity status according to state. Select Case activity.Status Case ActivityStateEnum.Started @@ -82,12 +82,26 @@ Case ActivityStateEnum.Defaulted StatusLabel.Text = "Beschikbaar" End Select - ' BatchLabel.Text = activity.bat + BatchLabel.Text = activity.WorkItem.BatchVisual ActivityNameLabel.Text = activity.Label End If + 'Get the activity selected in one of the grids. + Dim currentlySelectedActivity = _parentUserControl.GetCurrentlySelectedActivity() - 'todo enable status of buttons. + '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 Index: ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/details/IEmployeeDetailParentUserControl.vb =================================================================== diff -u -r1721 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/details/IEmployeeDetailParentUserControl.vb (.../IEmployeeDetailParentUserControl.vb) (revision 1721) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/details/IEmployeeDetailParentUserControl.vb (.../IEmployeeDetailParentUserControl.vb) (revision 1726) @@ -1,4 +1,7 @@ Public Interface IEmployeeDetailParentUserControl + + Function GetCurrentlySelectedActivity() As IActivity + ''' ''' Get the employee. ''' Index: ActiviteitenOpvolging/ActiviteitenOpvolging/screens/IEmployeesMainForm.vb =================================================================== diff -u -r1721 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/screens/IEmployeesMainForm.vb (.../IEmployeesMainForm.vb) (revision 1721) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/screens/IEmployeesMainForm.vb (.../IEmployeesMainForm.vb) (revision 1726) @@ -1,4 +1,5 @@ Public Interface IEmployeesMainForm + Inherits IActivityMainForm ''' ''' Gets all the employees. ''' Index: ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/IEmployeeUserControl.vb =================================================================== diff -u -r1717 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/IEmployeeUserControl.vb (.../IEmployeeUserControl.vb) (revision 1717) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/IEmployeeUserControl.vb (.../IEmployeeUserControl.vb) (revision 1726) @@ -1,7 +1,11 @@ Public Interface IEmployeeUserControl ''' - ''' Refresh the data of the employee. + ''' Triggered when the selected activity changes. ''' - ''' Whether or not it was successful - Function RefreshData() As Boolean + Sub SelectedActivityChanged() + + ''' + ''' Triggered when the amount of selected user changes. + ''' + Sub SelectedEmployeeChanged() End Interface Index: ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolgingForm.vb =================================================================== diff -u -r1723 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolgingForm.vb (.../ActiviteitenOpvolgingForm.vb) (revision 1723) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolgingForm.vb (.../ActiviteitenOpvolgingForm.vb) (revision 1726) @@ -68,8 +68,11 @@ Return _domainController.GiveWorkItems(gridNumber) End Function + Private _selectedActivity As IActivity ''' Public Sub ChangeSelectedActivity(activity As IActivity, gridNumber As Integer) Implements IWorkItemsMainForm.ChangeSelectedActivity + 'Store the activity. + _selectedActivity = activity 'If the activity is Nothing, no activity was selected, meaning that everything should be cleared. If activity Is Nothing Then 'Clear selection for every grid user control. @@ -81,8 +84,15 @@ If Not control.GridNumber = gridNumber Then control.RemoveSelection() Next End If + 'Update employee user controls. + _employeeUserControls.ForEach(Sub(employeeUserControl) employeeUserControl.SelectedActivityChanged()) End Sub + ''' + Public Function GetCurrentlySelectedActivity() As IActivity Implements IActivityMainForm.GetCurrentlySelectedActivity + Return _selectedActivity + End Function + Private Sub RefreshButton_Click(sender As Object, e As EventArgs) Handles RefreshButton.Click RefreshButton.Enabled = False RefreshUserGridsData() @@ -145,20 +155,21 @@ Public Sub SelectEmployee(employeeIndex As Integer, employee As IEmployee) Implements IEmployeesMainForm.SelectEmployee 'Call function in dc. _domainController.SelectEmployee(employeeIndex, employee) - 'Update all employee user controls. - _employeeUserControls.ForEach(Sub(employeeUserControl) employeeUserControl.RefreshData()) + 'Send message that the selected employee changed to all user controls. + _employeeUserControls.ForEach(Sub(employeeUserControl) employeeUserControl.SelectedEmployeeChanged()) End Sub ''' Public Sub DeselectEmployee(employeeIndex As Integer) Implements IEmployeesMainForm.DeselectEmployee _domainController.DeselectEmployee(employeeIndex) - 'Update all employee user controls. - _employeeUserControls.ForEach(Sub(employeeUserControl) employeeUserControl.RefreshData()) + 'Send message that the selected employee changed to all user controls. + _employeeUserControls.ForEach(Sub(employeeUserControl) employeeUserControl.SelectedEmployeeChanged()) End Sub ''' Public Function GetSelectedEmployee(employeeIndex As Integer) As IEmployee Implements IEmployeesMainForm.GetSelectedEmployee Return _domainController.GetSelectedEmployee(employeeIndex) End Function + #End Region End Class Index: ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj =================================================================== diff -u -r1721 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj (.../ActiviteitenOpvolging.vbproj) (revision 1721) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/ActiviteitenOpvolging.vbproj (.../ActiviteitenOpvolging.vbproj) (revision 1726) @@ -126,6 +126,7 @@ + Index: ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/EmployeeUserControl.vb =================================================================== diff -u -r1723 -r1726 --- ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/EmployeeUserControl.vb (.../EmployeeUserControl.vb) (revision 1723) +++ ActiviteitenOpvolging/ActiviteitenOpvolging/screens/employee/EmployeeUserControl.vb (.../EmployeeUserControl.vb) (revision 1726) @@ -54,26 +54,13 @@ 'Border color. Dim borderColor = ConfigsLoader.ColorsUsers(EmployeeIndex) 'Border thickness. - Dim borderThickness = 5I + Const borderThickness As Integer = 5I 'Border rectangle. Dim borderRectangle = Me.ClientRectangle 'Draw the border. e.Graphics.DrawRectangle(New Pen(borderColor, borderThickness), borderRectangle) End Sub - ''' - Public Function RefreshData() As Boolean Implements IEmployeeUserControl.RefreshData - Try - 'Refresh the data on the current user control. - _currentUserControl.RefreshData() - 'Refresh succesfull. - Return True - Catch ex As Exception - 'Failed to retrieve update with data. - Return False - End Try - End Function - #Region "Employee picking" ''' Public Function GetAllEmployees() As ICollection(Of IEmployee) Implements IEmployeePickerParentUserControl.GetAllEmployees @@ -92,9 +79,22 @@ End Try End Sub + ''' + Public Sub SelectedEmployeeChanged() Implements IEmployeeUserControl.SelectedEmployeeChanged + Try + 'If the current user control is to select the employee, make it refresh. + If TypeOf _currentUserControl Is EmployeePickerUserControl Then + _currentUserControl.RefreshData() + End If + Catch ex As Exception + MessageBox.Show($"Could not update after employee selection changed.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error) + End Try + End Sub + #End Region #Region "Employee details" + ''' Public Function FetchEmployee() As IEmployee Implements IEmployeeDetailParentUserControl.FetchEmployee Return _parentForm.GetSelectedEmployee(EmployeeIndex) @@ -107,13 +107,30 @@ _parentForm.DeselectEmployee(EmployeeIndex) 'Switch to employee picker user control. - SwitchUserControl(new EmployeePickerUserControl(Me)) + SwitchUserControl(New EmployeePickerUserControl(Me)) Catch ex As Exception MessageBox.Show($"Could not deselect employee.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub ''' + Public Sub SelectedActivityChanged() Implements IEmployeeUserControl.SelectedActivityChanged + Try + 'If the current user control is to select the employee, make it refresh. + If TypeOf _currentUserControl Is EmployeeDetailUserControl Then + _currentUserControl.RefreshData() + End If + Catch ex As Exception + MessageBox.Show($"Could not update after activity selection changed.{vbNewLine}{ex.Message}", "An error occured...", MessageBoxButtons.OK, MessageBoxIcon.Error) + End Try + End Sub + + ''' + Public Function GetCurrentlySelectedActivity() As IActivity Implements IEmployeeDetailParentUserControl.GetCurrentlySelectedActivity + Return _parentForm.GetCurrentlySelectedActivity() + End Function + + ''' Public Sub StartActivity() Implements IEmployeeDetailParentUserControl.StartActivity Throw New NotImplementedException End Sub @@ -130,8 +147,9 @@ #End Region ''' - ''' Swtich to another user control on the screen. + ''' Switch to another user control on the screen. ''' + ''' Must be a refreshable user control ''' Private Sub SwitchUserControl(Of T As {IRefreshableUserControl, UserControl})(userControl As T) 'Set current user control.