以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  条件判断求和  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=137555)

--  作者:有点蓝
--  发布时间:2019/7/9 16:19:00
--  
麻烦以后发帖改文字的颜色,不要设置背景色,看的眼花。

dv("需求数量") = dq.SQLCompute("sum(当日数量)", "发货日期 >= \'" & dw1  & "\' and 发货日期 <= \'" & dw2 & "\' and 材料编码 = \'" & e.newvalue & "\'  And 申请下达 is null")

--  作者:狐狸爸爸
--  发布时间:2019/7/9 17:12:00
--  
算不出来,就是条件不符合,导致代码没有执行,自己调试分析一下:
http://www.foxtable.com/webhelp/topics/1485.htm


If e.DataRow("库位") = "包装箱"   Then
    MessageBox.show("我执行了1")
    Dim d As Integer = Date.Today.Year
    Dim f As Integer = Date.Today.Month
    Dim dr1 As New Date(d, f, 1)
    Dim do2 As New Date(d, f, Date.DaysInMonth(d, f)) \'获取本月的最后一天
    Dim g As Integer = Date.Today.Year
    Dim n As Integer = Date.Today.Month
    Dim dw1 As New Date(g, n, 1)
    Dim dw2 As New Date(g, n, Date.DaysInMonth(g, n)) \'获取本月的最后一天
    Dim dv As DataRow = e.DataRow
    Dim dq As DataTable =DataTables("销售发货明细")
    If e.DataCol.Name = "成品编码"  Then
        MessageBox.show("我执行了2")
        dv("需求数量") = dq.SQLCompute("sum(当日数量)", "发货日期 >= \'" & dw1  & "\' and 发货日期 <= \'" & dw2 & "\' and 材料编码 = \'" & e.newvalue & "\'  And 申请下达 = nothing")
    Else
        MessageBox.show("我什么都没干1")
    End If
Else
    MessageBox.show("我执行了3")
    If e.DataCol.Name  = "成品编码"
        MessageBox.show("我执行了4")
        Dim Filter As String = "[材料编码] = \'" & e.DataRow("成品编码") & "\'"
        e.DataRow("需求数量") = DataTables("材料需求明细").SQLCompute("Sum(未发数量)", Filter)
    Else
        MessageBox.show("我什么都没干2")
    End If
End If

--  作者:有点蓝
--  发布时间:2019/7/9 20:50:00
--  
这个意思?

If e.DataCol.Name  = "成品编码"
    If e.DataRow("库位") = "包装箱"   Then
        Dim d As Integer = Date.Today.Year
        Dim f As Integer = Date.Today.Month
        Dim dr1 As New Date(d, f, 1)
        Dim do2 As New Date(d, f, Date.DaysInMonth(d, f)) \'获取本月的最后一天
        Dim g As Integer = Date.Today.Year
        Dim n As Integer = Date.Today.Month
        Dim dw1 As New Date(g, n, 1)
        Dim dw2 As New Date(g, n, Date.DaysInMonth(g, n)) \'获取本月的最后一天
        Dim dv As DataRow = e.DataRow
        Dim dq As DataTable =DataTables("销售发货明细")
        If e.DataCol.Name = "成品编码"  Then
            dv("需求数量") = dq.SQLCompute("sum(当日数量)", "发货日期 >= \'" & dw1  & "\' and 发货日期 <= \'" & dw2 & "\' and 材料编码 = \'" & e.newvalue & "\'  And 申请下达 is null")
        End If
    Else
        Dim Filter As String = "[材料编码] = \'" & e.DataRow("成品编码") & "\'"
        e.DataRow("需求数量") = DataTables("材料需求明细").SQLCompute("Sum(未发数量)", Filter)
    End If
End If

--  作者:有点蓝
--  发布时间:2019/7/9 21:23:00
--  
If e.DataCol.Name  = "成品编码" orelse e.DataCol.Name  = "库位"
    If e.DataRow("库位") = "包装箱"   Then
        Dim d As Integer = Date.Today.Year
        Dim f As Integer = Date.Today.Month
        Dim dr1 As New Date(d, f, 1)
        Dim do2 As New Date(d, f, Date.DaysInMonth(d, f)) \'获取本月的最后一天
        Dim g As Integer = Date.Today.Year
        Dim n As Integer = Date.Today.Month
        Dim dw1 As New Date(g, n, 1)
        Dim dw2 As New Date(g, n, Date.DaysInMonth(g, n)) \'获取本月的最后一天
        Dim dv As DataRow = e.DataRow
        Dim dq As DataTable =DataTables("销售发货明细")
        If e.DataCol.Name = "成品编码"  Then
            dv("需求数量") = dq.SQLCompute("sum(当日数量)", "发货日期 >= \'" & dw1  & "\' and 发货日期 <= \'" & dw2 & "\' and 材料编码 = \'" & e.DataRow("成品编码") & "\'  And 申请下达 is null")
        End If
    Else
        Dim Filter As String = "[材料编码] = \'" & e.DataRow("成品编码") & "\'"
        e.DataRow("需求数量") = DataTables("材料需求明细").SQLCompute("Sum(未发数量)", Filter)
    End If
End If

--  作者:有点蓝
--  发布时间:2019/7/9 22:39:00
--  
点击全部这个按钮有结果呀?或者说什么样的结果才是对的?
--  作者:有点蓝
--  发布时间:2019/7/10 9:50:00
--  
If e.DataCol.Name  = "成品编码" OrElse e.DataCol.Name  = "库位"
    If e.DataRow.IsNull("库位") = False AndAlso e.DataRow.IsNull("成品编码") = False
        If e.DataRow("库位") = "包装箱"   Then
            Dim d As Integer = Date.Today.Year
            Dim f As Integer = Date.Today.Month
            Dim dr1 As New Date(d, f, 1)
            Dim do2 As New Date(d, f, Date.DaysInMonth(d, f)) \'获取本月的最后一天
            Dim g As Integer = Date.Today.Year
            Dim n As Integer = Date.Today.Month
            Dim dw1 As New Date(g, n, 1)
            Dim dw2 As New Date(g, n, Date.DaysInMonth(g, n)) \'获取本月的最后一天
            Dim dv As DataRow = e.DataRow
            Dim dq As DataTable =DataTables("销售发货明细")
            dv("需求数量") = dq.Compute("sum(当日数量)", "发货日期 >= \'" & dw1  & "\' and 发货日期 <= \'" & dw2 & "\' and 材料编码 = \'" & e.DataRow("成品编码") & "\'  And 发箱人员 is null")
        Else
            Dim Filter As String = "[材料编码] = \'" & e.DataRow("成品编码") & "\'"
            e.DataRow("需求数量") = DataTables("材料需求明细").Compute("Sum(需求数量)", Filter)
        End If
    End If
End If