Foxtable(狐表)用户栏目专家坐堂 → [求助]筛选数据统计


  共有1909人关注过本帖树形打印复制链接

主题:[求助]筛选数据统计

帅哥哟,离线,有人找我吗?
狐说八道
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:104 积分:1139 威望:0 精华:0 注册:2017/9/13 8:43:00
[求助]筛选数据统计  发帖心情 Post By: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
图片点击可在新窗口打开查看

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110750 积分:563676 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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()


 回到顶部
帅哥哟,离线,有人找我吗?
狐说八道
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:104 积分:1139 威望:0 精华:0 注册:2017/9/13 8:43:00
  发帖心情 Post By:2017/12/29 20:36:00 [只看该作者]

可以了,谢谢老师

 

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


 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110750 积分:563676 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2017/12/29 21:01:00 [只看该作者]

字符列要加单引号,不然超过单个数就有问题的

 回到顶部
帅哥哟,离线,有人找我吗?
狐说八道
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:104 积分:1139 威望:0 精华:0 注册:2017/9/13 8:43:00
  发帖心情 Post By:2017/12/29 21:26:00 [只看该作者]

明白,谢谢老师

 回到顶部