以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  “流水账“例子中,在区分“产品”的同时想区分“日期”该怎么做?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=161139)

--  作者:lnjzxz
--  发布时间:2021/3/7 23:20:00
--  “流水账“例子中,在区分“产品”的同时想区分“日期”该怎么做?

“流水账“例子中,在区分“产品”的同时想区分“日期”该怎么做?谢谢!


下面是帮助中区分“产品”的例子


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
Select Case e.DataCol.Name
    Case
"产品","入库",
"出库"
       
Dim drs As List(of DataRow)
        Dim Filter As String
        Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [产品] = \'" & e.DataRow("产品") & "\'"
        drs = e.DataTable.Select(Filter)
        For Each dr As DataRow In drs
            Filter = "[_SortKey] <= " & dr("_SortKey") & " And [产品] = \'" & dr("产品") & "\'"
            Dim Val1 As Double = e.DataTable.Compute("Sum(入库)",Filter)
            Dim Val2 As Double = e.DataTable.Compute("Sum(出库)",Filter)
            dr("库存") = Val1 - Val2
        Next
        If e.DataCol.Name = "产品" AndAlso e.OldValue IsNot Nothing AndAlso e.OldValue <> e.NewValue Then
            Filter = "[_SortKey] > " & e.DataRow("_SortKey") & " And [产品] = \'" & e.OldValue & "\'"
            drs = e.DataTable.Select(Filter)
            For Each dr As DataRow In drs
                Filter = "[_SortKey] <= " & dr("_SortKey") & " And [产品] = \'" & dr("产品") & "\'"
                Dim Val1 As Double = e.DataTable.Compute("Sum(入库)",Filter)
                Dim Val2 As Double = e.DataTable.Compute("Sum(出库)",Filter)
                dr("库存") = Val1 - Val2
            Next
        End If
End
Select

--  作者:有点蓝
--  发布时间:2021/3/8 8:42:00
--  
加多一个日期做条件:

...... And [产品] = \'" & e.DataRow("产品") & "\' and 日期=\'" & e.DataRow("日期") & "\'"

--  作者:lnjzxz
--  发布时间:2021/3/10 21:14:00
--  
谢谢!完美解决