Private Sub TimeOut()
Try
If String.IsNullOrEmpty(instructorID) Then
MessageBox.Show(“Please log in to continue”, “Warning”, MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
Dim currentDate As String = DateTime.Now.ToString(“yyyy-MM-dd”)
' Retrieve the start and end times for the instructor's schedule on the current day
Dim startTime As String = ""
Dim endTime As String = ""
' Query the database to retrieve the start and end times
Dim query As String = "SELECT START, END FROM table_schedule WHERE INSTRUCTOR_ID = @instructorID AND DAY = @day"
Dim parameters As New List(Of MySqlParameter)
parameters.Add(New MySqlParameter("@instructorID", instructorID))
parameters.Add(New MySqlParameter("@day", DateTime.Now.DayOfWeek.ToString))
Using connection As New MySqlConnection("server=localhost;user id=root;database=instructorsdb")
connection.Open()
Dim command As New MySqlCommand(query, connection)
command.Parameters.AddRange(parameters.ToArray())
Dim reader As MySqlDataReader = command.ExecuteReader()
If reader.HasRows Then
reader.Read()
startTime = If(reader.IsDBNull(0), "", reader.GetString(0))
endTime = If(reader.IsDBNull(1), "", reader.GetString(1))
End If
reader.Close()
End Using
If startTime = "" Or endTime = "" Then
MessageBox.Show("No schedule found for today.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
updatesLogged("UPDATE table_attendance SET TIMEOUT = '" & DateTime.Now.ToString("HH:mm:ss") & "', PM_STATUS = 'Time Out', TOTALHOURS = TIMEOUT- TIMEIN WHERE INSTRUCTOR_ID = '" & instructorID & "' AND LOGDATE = '" & currentDate & "' AND AM_STATUS = 'Time In'")
Dim formattedTimeOut As String = DateTime.Now.ToString("HH':'mm':'ss")
MessageBox.Show("Successfully Timed Out. Time Out: " & formattedTimeOut, "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End If
ReloadAttendance()
Catch ex As Exception
MessageBox.Show("Error: " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
To get the totalhours of the instructor there all i did is just subtracting the time in and time out but what i want to happen is to get only the duration of work of the instructor based on his schedule ex. the instructor had multiple schedule for today that start 07:00 end 10:00, start 12:00 end 14:00 then the instructor time in at 06:30 time out at 14:50 so for totalhours will be 4 hours because that is the maximum hours of his schedule for today but if the instructor time out at 09:30 then the totalhours should be 2 hours and 30 minutes
Ggggggg is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.