以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  求助统计-有实例  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=81054)

--  作者:卖糕的
--  发布时间:2016/2/17 16:22:00
--  求助统计-有实例

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:异常统计.rar

 

需要对异常表做一个统计,之前直接用一个交叉表生成的临时表,现在需要做成数据表,要求:

按照异常统计表的格式,每个评审交期的出货异常要对应相应的生产中心笔数进行统计,自己试

了好久都统计成了总笔数,希望大神帮忙,谢谢了


 


--  作者:大红袍
--  发布时间:2016/2/17 17:34:00
--  

Dim dt1 As DataTable = DataTables("销售订单出货异常明细表")
Dim dt2 As DataTable = DataTables("异常责任统计表")

Dim dic As new Dictionary(Of String ,Integer)
For Each dr As DataRow In dt2.Select("")
    For Each dc As DataCol In dt2.DataCols
        If dc.name Like "评审日期_*" Then
            If dr("责任生管") = "合计" Then
                If dic.ContainsKey(dc.name) Then
                    dr(dc.name) = dic(dc.name)
                Else
                    dr(dc.name) = 0
                End If
            Else
                dr(dc.name) = Nothing
            End If
        End If
    Next
    Dim count As Integer = 0
    For Each cdr As DataRow In dt1.Select("责任生管 = \'" & dr("责任生管") & "\' and 制造中心 = \'" & dr("制造中心") & "\'")
        Dim d As Integer = cdr("评审日期").Day
        If dt2.DataCols.Contains("评审日期_" & d) Then
            If dic.ContainsKey("评审日期_" & d) = False Then dic.Add("评审日期_" & d, 0)
            dr("评审日期_" & d) = val(dr("评审日期_" & d)) + 1
            count += 1
            dic("评审日期_" & d) += 1
        End If
    Next
    dr("合计") = count
Next


--  作者:卖糕的
--  发布时间:2016/2/18 13:27:00
--  
谢谢大红袍大神指导,上面还有一个小小的问题,最右下角的总Total没有计算,代码应该怎么加
--  作者:大红袍
--  发布时间:2016/2/18 14:33:00
--  
Dim dt1 As DataTable = DataTables("销售订单出货异常明细表")
Dim dt2 As DataTable = DataTables("异常责任统计表")
Dim acount As Integer = 0
Dim dic As new Dictionary(Of String ,Integer)
For Each dr As DataRow In dt2.Select("")
    For Each dc As DataCol In dt2.DataCols
       
        If dc.name Like "评审日期_*"  Then
            If dr("责任生管") = "合计" Then
                If dic.ContainsKey(dc.name) Then
                    dr(dc.name) = dic(dc.name)
                Else
                    dr(dc.name) = 0
                End If
            Else
                dr(dc.name) = Nothing
            End If
        Else If dc.name = "合计"
            If dr("责任生管") = "合计" Then
                dr(dc.name) = acount
            Else
                dr(dc.name) = 0
            End If
        End If
    Next
    Dim count As Integer = 0
    For Each cdr As DataRow In dt1.Select("责任生管 = \'" & dr("责任生管") & "\' and 制造中心 = \'" & dr("制造中心") & "\'")
        Dim d As Integer = cdr("评审日期").Day
        If dt2.DataCols.Contains("评审日期_" & d) Then
            If dic.ContainsKey("评审日期_" & d) = False Then dic.Add("评审日期_" & d, 0)
            dr("评审日期_" & d) = val(dr("评审日期_" & d)) + 1
            count += 1
            dic("评审日期_" & d) += 1
        End If
    Next
    dr("合计") += count
    acount += count
Next

--  作者:卖糕的
--  发布时间:2016/2/18 20:45:00
--  
多谢解惑!