以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]筛选数据统计  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=111825)

--  作者:狐说八道
--  发布时间: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
图片点击可在新窗口打开查看

--  作者:有点蓝
--  发布时间:2017/12/29 20:15:00
--  
试试

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()


--  作者:狐说八道
--  发布时间:2017/12/29 20:36:00
--  

可以了,谢谢老师

 

我有个疑问就为什么字符型1-9都可以,而10之后就不行呢


--  作者:有点蓝
--  发布时间:2017/12/29 21:01:00
--  
字符列要加单引号,不然超过单个数就有问题的
--  作者:狐说八道
--  发布时间:2017/12/29 21:26:00
--  
明白,谢谢老师