Hi Greg, thanks for jumping in
.
I went a 3rd route and did the following keeping in mind future enhancements or needs:
1- Create a new table using the Computer Name as the PK, in my case the application can only be open once per workstation, so I also wanted to know in which computer was this user logged, I have other fields like the UserLogged, UserPK DisplayName and LoggedOnAt which are self explanatory.
2- In the new table's BO I added a method that will set the UserLogged True/False for the current Workstation Name (Environment.MachnineName), here is the code, pretty basic
'''
''' Set the UserLogged True/False for the current workstation.
''' '''
True when the user is currently logged, False otherwise.
'''
Called from the frmMainForm.vb Public Sub SetCurrentUserLoggedStatus(ByVal LoggedStatus As Boolean)
Me.FillByPrimaryKey(Environment.MachineName)
If Me.Count = 0 Then
Me.NewRow()
End If
If Me.Count > 0 Then
Dim currentUserDisplayName As String = String.Empty
If SecurityBasics.CurrentUser.UserName.Equals("Administrator", StringComparison.CurrentCultureIgnoreCase) Then
currentUserDisplayName = SecurityBasics.CurrentUser.UserName
Else
currentUserDisplayName = MicroFour.StrataFrame.Security.BusinessObjects.SFSUsersBO.RetrieveDisplayName(SecurityBasics.CurrentUser.UserPK)
End If
Me.UserLogged = LoggedStatus
Me.LoggedOnAt = Now
Me.LoggedUserDisplayName = currentUserDisplayName
Me.Save()
End If
End Sub
3- I have a MainForm which is always open, so I added 2 events handles to detect when a user has logged and when the form is closing to call my code above.
AddHandler MicroFour.StrataFrame.Security.SecurityBasics.CurrentUserChanged, AddressOf UpdateCurrentUserInfo
AddHandler Me.FormClosed, AddressOf HandleFormClosed
Of course in the delegate methods above you need to call SetCurrentUserLoggedStatus(True/False) to do the trick.
This was a very quick code, so if I am missing something or you guys see where to enhance it, please let us know.
Edhy Rijo