以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 流水账加入按年的为计算的代码 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=184890) |
-- 作者:sjf0823 -- 发布时间:2023/1/13 10:21:00 -- 流水账加入按年的为计算的代码 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 老师,我要加一个按年度来做库存计算节点,比如2022年的库存截止2022年结束,2023年对应的库存重新开始流水记算,代码需要怎么加?
|
-- 作者:有点蓝 -- 发布时间:2023/1/13 10:34:00 -- 增加一个年份列,然后增加一个年份条件即可,比如 Filter = "[_SortKey] >= " & e.DataRow("_SortKey") & " And [产品] = \'" & e.DataRow("产品") & "\' and 年份=" & e.DataRow("年份") |