Hello,
I'm stuck with what I'm sure, is a very simple problem.
I'm trying to save an employee's login time, login date, and logout time into a database. So far what I'm doing is, when the employee first logs in it saves their login time and date, but obviously not their logout time since they haven't logged out yet. Next when the main form is closing, it needs to record their logout time and update their existing record to complete it.
Okay so what I have so far is:
It will record the login time and login date correctly.
And it will record the logout time correctly and I have the code necessary to record it into an existing record.
But, my main problem is how do I pull back up that existing record in the first place?
While creating the new login record I tried to use a variable to save the LoginDataID so it can be passed onto the main form to bring the LoginDataRecord up by its ID when closing. This part, I can't seem to get to work.
Basically, what I'm asking is will anyone help me find a way to capture the ID of the new LoginDataRecord that is created when the employee first logs in, so it can be used when I query the LoginDataRecord, using LINQ, to find their LoginDataRecord and update it with the logout time when the main form is closing?
Also at the moment, I'm strictly a Visual Basic programmer. I'm still in college, and my skills with Java and C# are very, very basic and I can't really do much in them.
Anyways, thanks for any and all help.
Here's the code for the Login Form.
Imports NEIPurchasingDAL.PurchasingDatabaseEntities
Imports System.Data.Objects
Public Class LoginForm
Private PE As NEIPurchasingDAL.PurchasingDatabaseEntities = New NEIPurchasingDAL.PurchasingDatabaseEntities
Public LoginID As String
Private Sub btnLogin_Click(sender As System.Object, e As System.EventArgs) Handles btnLogin.Click
Dim MyUser As String = My.User.Name
Dim LoginDate As String = Today.ToShortDateString
Dim LoginTime As String = Now.ToLongTimeString
Dim MyUserName As String = Replace(MyUser, "NEIHERRIN\", "")
MyUserName = My.User.Name
Dim LoginDataRecord As New NEIPurchasingDAL.LoginData
With LoginDataRecord
.Username = MyUserName
.LoginTime = LoginTime
.LoginDate = LoginDate
End With
PE.AddToLoginDatas(LoginDataRecord)
LoginID = LoginDataRecord.LoginID
PE.SaveChanges()
MainForm.Show()
Me.Visible = False
End Sub
End Class
And here's the code for the Main Form
Imports NEIPurchasingDAL.PurchasingDatabaseEntities
Imports System.Data.Objects
Public Class MainForm
Private PE As NEIPurchasingDAL.PurchasingDatabaseEntities = New NEIPurchasingDAL.PurchasingDatabaseEntities
Private MyUser As String = My.User.Name
Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles_ Me.FormClosing
Dim LogoutTime As String = Now.ToLongTimeString
Try
Dim LoginData As NEIPurchasingDAL.LoginData
LoginData = (From LoginDatas In PE.LoginDatas
Where LoginDatas.LoginID = LoginForm.LoginID
Select LoginDatas)
LoginData.LogoutTime = LogoutTime
PE.SaveChanges()
Catch ex As Exception
MessageBox.Show(ex.Message, ex.GetType.ToString)
End Try
LoginForm.Visible = True
End Sub
End Class
The problem is that I can't get the Public variable LoginID to store the LoginID on the actual entity and then use it for comparison on the Main Form. Assuming it is possible.