-- 作者:狐说八道
-- 发布时间:2017/12/29 19:05:00
-- [求助]筛选数据统计
老师,我有个窗口,添加了一个ComboBox控件,用于选择年份,用于统计该年份的数据,两个table控件,table2类型是SQLQuery,从数据库加载数据进行统计,然后在SelectedIndexChanged事件写了如下代码:
Dim y As String = 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()
问题是统计完9月份之后就不统计了,麻烦老师帮忙看看。结果如下图
此主题相关图片如下:qq截图20171229190142.png
|