试试
Dim y As integer = e.Sender.Selectedvalue
Dim tb1 As Table = Tables(e.Form.name & "_table1")
Dim tb2 As Table = Tables(e.Form.name & "_table2")
tb1.DataTable.StopRedraw()
tb1.DataTable.dataRows.clear()
For m As Integer = 1 To 12
Dim Days As Integer = Date.DaysInMonth(y,m)
Dim fd As Date = New Date(y,m,1) '获得该月的第一天
Dim ld As Date = New Date(y,m,Days) '获得该月的最后一天
tb2.DataTable.LoadFilter = "date_fr >= '" & fd & "' And date_to <= '" & ld & "' and leave_type = 02"
tb2.DataTable.load()
Dim name As new List(of String)
name = tb2.DataTable.GetValues("emp_no")
For Each names As String In name
Dim dr As DataRow = tb1.DataTable.addnew
dr("第一列") = names
dr("第四列") = m
Next
Dim d1,d2 As Date
Dim i,j, sum As String
For Each dr As DataRow In tb1.DataTable.Select("第四列 = '" & m & "'")
j = 0
i = 0
sum = "0"
For Each lts As DataRow In tb2.DataTable.Select("emp_no = '" & dr("第一列") & "'")
j += 1
d1 = lts("date_fr")
d2 = lts("date_to")
If d1 = d2 Then
If d1.DayOfWeek = 6 Then
sum = sum + lts("leave_time") + 8
Else
sum = sum + lts("leave_time")
End If
Else
Do While d1 <> d2
If d1.DayOfWeek = 6 Then
i += 1
End If
d1 = d1.adddays(1)
Loop
If d2.DayOfWeek = 6 Then
i += 1
End If
sum = sum + lts("leave_time") + i * 8
End If
Next
dr("第二列") = j
dr("第三列") = sum
Next
Next
tb1.DataTable.ResumeRedraw()