Foxtable(狐表)用户栏目专家坐堂 → 流水账转账问题


  共有3406人关注过本帖平板打印复制链接

主题:流水账转账问题

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


加好友 发短信
等级:四尾狐 帖子:983 积分:7049 威望:0 精华:0 注册:2009/6/24 9:44:00
流水账转账问题  发帖心情 Post By:2023/2/5 9:07:00 [只看该作者]


此主题相关图片如下:qq截图20230125221036.jpg
按此在新窗口浏览图片

此类流水账的设计方法要复杂一些,DataColChanged事件代码为:

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

上述代码的3到12行很好理解,当我们修改产品、入库、出库三列内容后,即从此行开始重算同产品所有行的余额。
假定我们修改的是产品,例如将产品由PD01改为PD02,3到12行会从此行开始重算所有产品为PD02的行的余额;显然此行之后的产品为PD01的行的余额,也是应该重算的,于是就有了13到22行的代码,注意第14行在合成条件的时候,用e.OldValue取得原产品名称。

AfterMoveRow事件代码变化不大,条件表达式中加入产品比较即可:

Dim Key As Decimal
Dim
Index As Integer
Dim
Filter As String
Dim
r As Row
Index = Math.Min(e.OldIndex, e.NewIndex)
Key = e.
Table.Rows(Index)("_SortKey")
r = e.
Table.Rows(e.NewIndex)
Filter =
"[_SortKey] >= " & Key & " And [产品] = '" & r("产品") & "'"
e.
Table.DataTable.DataCols("入库"
).RaiseDataColChanged(Filter)

而DataRowDeleting事件代码则完全相同:

e.DataRow("入库") = 0
e.
DataRow("出库") = 0

 

 

这段代码如果我只有两种产品,pd01和pd02,出库时候都和原来一样,但是pd02入库的时候,是把pd01的库存数转到了pd02,相应的pd01也减少了库存,需要计算出pd02的实时库存,和pd01、pd02的总库存,请问这个怎么修改?


 回到顶部