Foxtable(狐表)用户栏目专家坐堂 → 一条关于统计的代码,为何统计不出来呢


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

主题:一条关于统计的代码,为何统计不出来呢

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


加好友 发短信
等级:婴狐 帖子:74 积分:678 威望:0 精华:0 注册:2012/10/31 10:58:00
一条关于统计的代码,为何统计不出来呢  发帖心情 Post By: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
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:35433 积分:178524 威望:0 精华:3 注册:2013/3/30 16:36:00
  发帖心情 Post By:2013/7/1 10:13:00 [只看该作者]

最好能上个例子,能测试分析直观一点. 慢慢看代码有点费时间!

 回到顶部