Foxtable(狐表)用户栏目专家坐堂 → 汇总本月数


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

主题:汇总本月数

帅哥,在线噢!
有点蓝
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:112375 积分:572137 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/9/1 8:47:00 [显示全部帖子]

Dim Dowss As List(of DataRow) = e.DataTable.find("摘要 = '本月合计'")
For Each dr As DataRow In Dowss
    Dim year As Integer = dr("日期").Year
    Dim month As Integer = dr("日期").Month
    Dim Date1 As Date = new Date(year,month,1)
    Dim Date2 As Date = new Date(year,month,Date.DaysInMonth(year,month))
    For Each c As DataCol In e.DataTable.DataCols
        
        dr(c.name) = e.DataTable.Compute("sum(" & c.name & ")","日期 >= '" & Date1 & "' and 日期 <= '" & Date2 & "'")
    Next
Next

这种直接用汇总或者分组统计好了


 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:112375 积分:572137 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/9/1 14:26:00 [显示全部帖子]

If e.DataCol.Name = "摘要" AndAlso e.DataRow("摘要") = "本月合计" Then
    Dim Dowss As List(of DataRow) = e.DataTable.Select("摘要 = '本月合计'")
    For Each dr As DataRow In Dowss
        Dim year As Integer = dr("日期").Year
        Dim month As Integer = dr("日期").Month
        Dim Date1 As Date = new Date(year,month,1)
        Dim Date2 As Date = new Date(year,month,Date.DaysInMonth(year,month))
        For Each c As DataCol In e.DataTable.DataCols
            If c.IsNumeric Then
                'msgbox(Date1)
                'msgbox(Date2)
                'dr(c.name) = e.DataTable.Compute("sum(" & c.name & ")","日期 >= '" & Date1 & "' and 日期 <= '" & Date2 & "'and 摘要 <> '本月合计'")
                dr(c.name) = Nothing
                dr(c.name) = e.DataTable.Compute("sum(" & c.name & ")","日期 >= '" & Date1 & "' and 日期 <= '" & Date2 & "' ")
            End If
        Next
    Next
End If

 回到顶部
帅哥,在线噢!
有点蓝
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:112375 积分:572137 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/9/1 16:53:00 [显示全部帖子]

摘要 <> '本月合计'是会排除空值的,

Select Case e.DataCol.Name
    Case "汇总_借方金额","汇总_贷方金额"
        For Each dr As DataRow In e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"))
            Dim Val1 As Double = e.DataTable.Compute("Sum(汇总_借方金额)","[_SortKey] <= " & dr("_SortKey") & " And  (摘要 <> '本月合计'or 摘要 is null)")
msgbox(val1)
            Dim Val2 As Double = e.DataTable.Compute("Sum(汇总_贷方金额)","[_SortKey] <= " & dr("_SortKey") & " And 
 (摘要 <> '本月合计'or 摘要 is null)")

           dr("汇总_余额") = Val1 + Val2
        Next
End Select


 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:112375 积分:572137 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/9/2 9:36:00 [显示全部帖子]

Select Case  e.DataCol.Name
    Case "摘要"
        Select Case e.DataRow("摘要")
            Case "本月合计","本年累计"
                Dim Dowss As List(of DataRow) = e.DataTable.Select("摘要 = '本月合计'")
                For Each dr As DataRow In Dowss
                    Dim year As Integer = dr("日期").Year
                    Dim month As Integer = dr("日期").Month
                    Dim Date1 As Date = new Date(year,month,1)
                    Dim Date2 As Date = new Date(year,month,Date.DaysInMonth(year,month))
                    For Each c As DataCol In e.DataTable.DataCols
                        If c.IsNumeric AndAlso e.DataCol.name <> "汇总_余额" Then
                            dr(c.name) = Nothing
                            dr(c.name) = e.DataTable.Compute("sum(" & c.name & ")","日期 >= '" & Date1 & "' and 日期 <= '" & Date2 & "' and 摘要 is null")
                        End If
                    Next
                Next
                
                Dowss = e.DataTable.Select("摘要 = '本年累计'")
                For Each dr As DataRow In Dowss
                    Dim year As Integer = dr("日期").Year
                    Dim month As Integer = dr("日期").Month
                    Dim Date1 As Date = new Date(year,1,1)
                    Dim Date2 As Date = new Date(year,month,Date.DaysInMonth(year,month))
                    For Each c As DataCol In e.DataTable.DataCols
                        If c.IsNumeric AndAlso e.DataCol.name <> "汇总_余额" Then
                            dr(c.name) = Nothing
                            dr(c.name) = e.DataTable.Compute("sum(" & c.name & ")","日期 >= '" & Date1 & "' and 日期 <= '" & Date2 & "'and 摘要 = '本月合计'")
                        End If
                    Next
                Next
        End Select
    Case "汇总_借方金额","汇总_贷方金额"
        If e.DataRow("摘要") = "本月合计" OrElse e.DataRow("摘要") ="本年累计" Then Return
        For Each dr As DataRow In e.DataTable.Select("[_SortKey] >= " & e.DataRow("_SortKey"))
            Dim Val1 As Double = e.DataTable.Compute("Sum(汇总_借方金额)","[_SortKey] <= " & dr("_SortKey") & " And  (摘要 <> '本月合计'or 摘要 is null)")
            'msgbox(val1)
            Dim Val2 As Double = e.DataTable.Compute("Sum(汇总_贷方金额)","[_SortKey] <= " & dr("_SortKey") & " And  (摘要 <> '本月合计'or 摘要 is null)")
            dr("汇总_余额") = Val1 + Val2
        Next
End Select

 回到顶部
帅哥,在线噢!
有点蓝
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:112375 积分:572137 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2016/9/3 8:59:00 [显示全部帖子]

看8楼

 回到顶部