Expand|Select|Wrap|Line Numbers
- Private Sub CALCULATELOGINOITS()
- Dim HALFDAY1 As Integer = 0
- Dim HALFDAY2 As Integer = 0
- Dim NOOFLOGS As Integer = 0
- Dim j As Integer = 0
- Dim dh As Integer = 0
- Dim dsp As DataSet = DataLayer.ExecuateDataSet("select * from TIMEATENDENCEVIEW1 where eid=" & cmbemployee.SelectedValue & " order by orderno")
- If dsp.Tables(0).Rows.Count > 0 Then
- For Each row As DataRow In dsp.Tables(0).Rows
- duty = duty & row("ScheduleFrom").ToString & " to " & row("ScheduleTO").ToString & " "
- gracetime = gracetime + row("gracetime")
- dh = DateDiff(DateInterval.Minute, row("ScheduleFrom"), row("ScheduleTO"))
- If dh < 0 Then dh = DateDiff(DateInterval.Minute, row("ScheduleFrom"), DateAdd(DateInterval.Day, 1, row("ScheduleTO")))
- dutyhours = dutyhours + dh
- j = j + 1
- ListBox1.Items.Add(row("ScheduleFrom"))
- ListBox2.Items.Add(row("ScheduleTO"))
- Next
- gracetime = gracetime / j
- lblgraceperiod.Text = gracetime
- lbldayschedule.Text = duty
- lbldutyhours.Text = CInt(dutyhours / 60)
- HALFDAY1 = CInt(Val(lbldutyhours.Text) * 0.33)
- HALFDAY2 = CInt(Val(lbldutyhours.Text) * 0.75)
- For i = 1 To 31
- Try
- Dim s1 As String = cmbmonth.SelectedIndex + 1 & "/" & i & "/" & txtyear.Text
- Dim dd As Date = Convert.ToDateTime(s1) 'cDate(txtyear.Text & "-" & cmbmonth.SelectedIndex + 1 & "-" & i & " 12:00:00")
- s1 = dd.DayOfWeek.ToString()
- DataGridView1.Rows.Add(s1.Substring(0, 3) & " " & cmbmonth.SelectedIndex + 1 & "-" & i & "-" & txtyear.Text, "", 0, 0, 0, 0, 0, 0)
- Catch ex As Exception
- End Try
- Next
- End If
- Dim logs As String = ""
- Dim HOURSWORKED As Integer = 0
- Dim latecomming As Integer = 0
- Dim TIME1 As String = ""
- Dim TIME2 As String = ""
- Dim date01 As Date
- Dim date02 As Date
- For z = 1 To 31
- date01 = Now
- date02 = Now
- Try
- date01 = CDate(cmbmonth.SelectedIndex + 1 & "/" & z & "/" & txtyear.Text.Trim & " 06:00:00")
- date02 = DateAdd(DateInterval.Hour, 23, date01)
- Catch ex As Exception
- Exit For
- End Try
- logs = ""
- HOURSWORKED = 0
- ''LOG IN OUT DETAILS CALCULATION
- Dim dsp02 As DataSet = DataLayer.ExecuateDataSet("select * from attendance where eid=" & cmbemployee.SelectedValue & " and pdate >='" & date01 & "' and pdate <= '" & date02 & "' order by pdate")
- If dsp02.Tables(0).Rows.Count > 0 Then
- Dim ZZZ As Integer = 0
- For Each row02 As DataRow In dsp02.Tables(0).Rows
- logs = logs & Format(DatePart(DateInterval.Hour, row02("pdate")), "00") & ":" & Format(DatePart(DateInterval.Minute, row02("pdate")), "00") & " "
- ZZZ = ZZZ + 1
- If (ZZZ = dsp02.Tables(0).Rows.Count) And (dsp02.Tables(0).Rows.Count Mod 2 <> 0) Then
- Dim ppp = Format(DatePart(DateInterval.Hour, row02("pdate")), "00") & ":" & Format(DatePart(DateInterval.Minute, row02("pdate")), "00") & " "
- ppp = DateDiff(DateInterval.Minute, CDate(ppp), CDate(ListBox2.Items(ListBox2.Items.Count - 1)))
- If ppp > 0 Then
- logs = logs & ListBox2.Items(ListBox2.Items.Count - 1).ToString.Substring(0, 5) & " "
- Else
- logs = logs.Substring(0, Len(logs) - 6)
- End If
- End If
- ZZZ = ZZZ - 1
- If ZZZ Mod 2 = 0 Then
- TIME1 = row02("pdate")
- TIME2 = ""
- Else
- TIME2 = row02("pdate")
- HOURSWORKED = HOURSWORKED + DateDiff(DateInterval.Minute, CDate(TIME1), CDate(TIME2))
- End If
- ZZZ = ZZZ + 1
- Next
- End If
- If logs <> "" Then
- HOURSWORKED = 0
- Dim logs2 = logs
- For i = 1 To (Len(logs) / 6)
- Try
- TIME1 = logs2.Substring(0, 5)
- TIME2 = logs2.Substring(6, 5)
- Try
- logs2 = logs2.Substring(12)
- Catch ex As Exception
- End Try
- If Hour(CDate(TIME1)) < 6 Then TIME1 = Now.Date & " " & TIME1 & ":00" Else TIME1 = DateAdd(DateInterval.Day, -1, Now.Date) & " " & TIME1 & ":00"
- If Hour(CDate(TIME2)) < 6 Then TIME2 = Now.Date & " " & TIME2 & ":00" Else TIME2 = DateAdd(DateInterval.Day, -1, Now.Date) & " " & TIME2 & ":00"
- HOURSWORKED = HOURSWORKED + DateDiff(DateInterval.Minute, CDate(TIME1), CDate(TIME2))
- Catch ex As Exception
- End Try
- i = i + 1
- Next
- DataGridView1.Rows(z - 1).Cells("DETAILS").Value = logs & " [" & CInt(HOURSWORKED / 60) & "]"
- End If
- DataGridView1.Rows(z - 1).Cells("WORK").Value = CInt(HOURSWORKED / 60)
- ''OVER TIME CALCULATION
- If HOURSWORKED <> 0 Then
- If (HOURSWORKED / 60) - Val(lbldutyhours.Text) > 0 Then
- DataGridView1.Rows(z - 1).Cells("ot").Value = (HOURSWORKED / 60) - Val(lbldutyhours.Text)
- Else
- DataGridView1.Rows(z - 1).Cells("ot").Value = 0
- End If
- If HOURSWORKED <= HALFDAY1 Then
- DataGridView1.Rows(z - 1).Cells("S").Value = "A"
- ElseIf HOURSWORKED >= HALFDAY1 And HOURSWORKED < HALFDAY2 Then
- DataGridView1.Rows(z - 1).Cells("S").Value = "H"
- Else
- DataGridView1.Rows(z - 1).Cells("S").Value = "P"
- End If
- Else
- DataGridView1.Rows(z - 1).Cells("ot").Value = 0
- DataGridView1.Rows(z - 1).Cells("S").Value = "A"
- End If
- NOOFLOGS = Len(logs.ToString) / 6
- Dim STR As String = logs
- Dim STR2 As String = ""
- Dim K As Integer = 0
- Dim P As Integer = 0
- Dim kk As Integer = 0
- Try
- For I = 1 To NOOFLOGS
- K = STR.IndexOf(" ")
- STR2 = STR.Substring(0, 5)
- STR = STR.Substring(K + 1)
- P = 0
- If I Mod 2 <> 0 Then
- If I = 1 Then
- Dim jj1
- Dim jj2
- If CDate(STR2) < "06:00" Then
- jj1 = CDate(DateAdd(DateInterval.Day, 1, Now.Date) & " " & STR2)
- Else
- jj1 = CDate(Now.Date & " " & STR2)
- End If
- If CDate(CDate(ListBox1.Items(0))) < "06:00" Then
- jj2 = CDate(DateAdd(DateInterval.Day, 1, Now.Date) & " " & CDate(ListBox1.Items(0)))
- Else
- jj2 = CDate(Now.Date & " " & CDate(ListBox1.Items(0)))
- End If
- P = DateDiff(DateInterval.Minute, jj2, jj1)
- If P >= 0 Then DataGridView1.Rows(z - 1).Cells("late").Value = DataGridView1.Rows(z - 1).Cells("late").Value + P
- End If
- Else
- If I = NOOFLOGS Then
- Dim jj1
- Dim jj2
- If CDate(STR2) < "06:00" Then
- jj1 = CDate(DateAdd(DateInterval.Day, 1, Now.Date) & " " & STR2)
- Else
- jj1 = CDate(Now.Date & " " & STR2)
- End If
- If CDate(CDate(ListBox2.Items(ListBox2.Items.Count - 1))) < "06:00" Then
- jj2 = CDate(DateAdd(DateInterval.Day, 1, Now.Date) & " " & CDate(ListBox2.Items(ListBox2.Items.Count - 1)))
- Else
- jj2 = CDate(Now.Date & " " & CDate(ListBox2.Items(ListBox2.Items.Count - 1)))
- End If
- P = DateDiff(DateInterval.Minute, jj1, jj2)
- If P >= 0 Then DataGridView1.Rows(z - 1).Cells("EARLY").Value = DataGridView1.Rows(z - 1).Cells("EARLY").Value + P
- End If
- kk = kk + 1
- End If
- Next
- Catch ex As Exception
- End Try
- Next
- End Sub