I have a table in SQL that contains clock times gathered from the one clock-in point. The times appear in the table like so:
pkClockingTime dtDateTime fkEmployee
1 2017-02-06, 07:59:00.000 49
2 2017-02-06, 08:00:00.000 50
3 2017-02-06, 12:00:00.000 49
32 2017-02-06, 12:01:00.000 50
33 2017-02-06, 13:00:00.000 50
34 2017-02-06, 13:04:00.000 49
35 2017-02-06, 17:30:00.000 50
36 2017-02-06, 17:32:00.000 49
and so on; this is just an example of two peoples clock times on a typical day with clock-in at 8, clock-out for lunch at 12, clock back in at 1, then going home at 5:30.
If anyone can help or offer any advice that would be amazing!
What I have tried:
At the moment I have it displaying the times in order of Employee and date by creating a DataTable from the TableAdapter and attaching that to a BindingSource which is bound to the DataGridView, but it has 2 lines per employee in the DataGridView, one for each Clock In/Out where as i would like all 4 times on one line.
I was hoping it can be modified to output all 4 times from the Employee on the same date on 1 line
The code i have so far for creating the DataTable which outputs 2 lines per Employee is as follows:
Private Function FormatedClockingTimes() As DataTable
Dim dtResults As New DataTable
dtResults.Columns.Add("EmployeeID", GetType(Integer))
dtResults.Columns.Add("Date", GetType(Date))
dtResults.Columns.Add("ClockIn", GetType(DateTime))
dtResults.Columns.Add("ClockOut", GetType(DateTime))
Dim intLastEmployee As Integer = 0
Dim intClockCounter As Integer = 0
Dim drLastRow As DataRow
Dim dtCurrentDate As Date
Dim dtPreviousDate As Date
For Each drSourceRow As DataRow In TblAttendanceTimesTableAdapter.GetData()
intClockCounter += 1
dtCurrentDate = drSourceRow("dtDateTime").ToString
If (dtPreviousDate = Nothing) Then
dtPreviousDate = dtCurrentDate
End If
If ((drSourceRow("fkEmployee").ToString() = intLastEmployee Or intLastEmployee = 0) And dtCurrentDate.ToShortDateString = dtPreviousDate.ToShortDateString) Then
If (intClockCounter = 1) Then
dtResults.Rows.Add(drSourceRow("fkEmployee").ToString(), dtCurrentDate, drSourceRow("dtDateTime").ToString(), Nothing)
Else
drLastRow = dtResults.Rows(dtResults.Rows.Count - 1)
drLastRow("ClockOut") = drSourceRow("dtDateTime").ToString()
intClockCounter = 0
End If
Else
dtResults.Rows.Add(drSourceRow("fkEmployee").ToString(), dtCurrentDate.ToShortDateString, drSourceRow("dtDateTime").ToString(), Nothing)
intClockCounter = 1
End If
intLastEmployee = drSourceRow("fkEmployee").ToString()
dtPreviousDate = dtCurrentDate
Next
Return dtResults