以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  一条关于统计的代码,为何统计不出来呢  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=37132)

--  作者:lc_guo
--  发布时间:2013/7/1 10:11:00
--  一条关于统计的代码,为何统计不出来呢

      我写了一条代码,希望在输入数据的时候,在另一个表中进行数量和金额的统计,如果统计表中没有相应行,

就增加行,若有,则统计出数量,但是,现在的问题是无法将数量和金额的数据统计显示出来。请大家帮忙看一下是

哪里出了问题

 

Dim d As Date = e.DataRow("入库日期")
Dim month As Integer = d.month
Dim year As Integer = d.year
If e.DataCol.name="数量" Then
    If e.DataRow.IsNull("材料名称")=False AndAlso e.DataRow.IsNull("入库日期")=False Then
        Dim dr As DataRow = DataTables("辅助生产材料月报表").Find("材料名称=\'" & e.DataRow("材料名称") & "\' and 报表年份=" & d.year & " And 报表月份=" & d.month )
        If dr IsNot Nothing Then
            dr("本月购置_数量")=DataTables("辅助生产材料月报表").Compute("sum(本月购置_数量)","材料名称=\'" & e.DataRow("材料名称") & "\' and 报表年份=" & d.year & " And 报表月份=" & d.month )
        End If
    End If
End If
If e.DataCol.name="金额" Then
    If e.DataRow.IsNull("材料名称")=False AndAlso e.DataRow.IsNull("入库日期")=False Then
        Dim dr As DataRow = DataTables("辅助生产材料月报表").Find("材料名称=\'" & e.DataRow("材料名称") & "\' and 报表年份=" & d.year & " And 报表月份=" & d.month )
        If dr IsNot Nothing Then
            dr("本月购置_金额")=DataTables("辅助生产材料月报表").Compute("sum(本月购置_金额)","材料名称=\'" & e.DataRow("材料名称") & "\' and 报表年份=" & d.year & " And 报表月份=" & d.month )
        End If
    End If
End If
If e.DataCol.name="材料名称" OrElse e.DataCol.name="入库日期" Then
    If e.DataRow.IsNull("材料名称")=False AndAlso e.DataRow.IsNull("入库日期")=False Then
        Dim dr As DataRow = DataTables("辅助生产材料月报表").Find("材料名称=\'" & e.DataRow("材料名称") & "\' and 报表年份=" & d.year & " And 报表月份=" & d.month )
        If dr Is Nothing Then
            Dim dr2 As DataRow =  DataTables("辅助生产材料月报表").AddNew
            dr2("本月购置_金额")=e.DataRow("金额")
            dr2("本月购置_数量")=e.DataRow("数量")
            dr2("材料名称")=e.DataRow("材料名称")
            dr2("报表年份")= d.year
            dr2("报表月份")= d.month
        End If
    End If
End If


--  作者:Bin
--  发布时间:2013/7/1 10:13:00
--  
最好能上个例子,能测试分析直观一点. 慢慢看代码有点费时间!