以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  汇总本月数  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=89890)

--  作者:kaituozhe
--  发布时间:2016/8/31 18:00:00
--  汇总本月数

For Each c As DataCol In e.DataTable.DataCols

Dim Dowss As DataRow (of List) = e.DataTable.Select("摘要 = \'本月合计\'")
        Dim year As Integer = e.DataTable.find("摘要 = \'本月合计\'")("日期").Year
        Dim month As Integer =e.DataTable.find("摘要 = \'本月合计\'")("日期").Month
        Dim Date1 As Date = new Date(year,month,1)
        Dim Date2 As Date = new Date(year,month,Date.DaysInMonth(year,month))
        msgbox(Date2)
        e.DataTable.find("摘要 = \'本月合计\'and 日期 = \'" & Date2 &"\'")(c.name) = e.DataTable.Compute("sum(c.name)","日期 >= \'" & Date1 & "\' and 日期 <= \'" & Date2 & "\'")
        msgbox(5)

next
以上代码是实现本月合计行对本月数据的合计


--  作者:有点蓝
--  发布时间: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

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


--  作者:kaituozhe
--  发布时间:2016/9/1 12:13: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) = e.DataTable.Compute("sum(" & c.name & ")","日期 >= \'" & Date1 & "\' and 日期 <= \'" & Date2 & "\'")
                msgbox(dr(c.name))
            End If
        Next
    Next
End If


--  作者:kaituozhe
--  发布时间:2016/9/1 12:13:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目16.foxdb


--  作者:kaituozhe
--  发布时间:2016/9/1 12:14:00
--  
\'dr(c.name) = e.DataTable.Compute("sum(" & c.name & ")","日期 >= \'" & Date1 & "\' and 日期 <= \'" & Date2 & "\'and 摘要 <> \'本月合计\'")换成此句代码时,值就为了零了,不知道什么原因?

--  作者:有点蓝
--  发布时间: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

--  作者:kaituozhe
--  发布时间:2016/9/1 16:33: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 摘要 <> \'本月合计\'")
msgbox(val1)
            Dim Val2 As Double = e.DataTable.Compute("Sum(汇总_贷方金额)","[_SortKey] <= " & dr("_SortKey") & " And 摘要 <> \'本月合计\'")
           dr("汇总_余额") = Val1 + Val2
        Next
End Select

以上代码是流水账代码,黄水代码错误在那里,为什么求不出来值?


--  作者:有点蓝
--  发布时间: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


--  作者:kaituozhe
--  发布时间:2016/9/1 20:18:00
--  
例子中的明细表,希望实现本年累计、本月合计及余额自动计算,里面怎么修改?
--  作者:kaituozhe
--  发布时间:2016/9/1 20:18:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目16.foxdb