Foxtable(狐表)用户栏目专家坐堂 → 关于水流帐问题


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

主题:关于水流帐问题

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


加好友 发短信
等级:五尾狐 帖子:1152 积分:7712 威望:0 精华:0 注册:2019/6/13 9:57:00
关于水流帐问题  发帖心情 Post By:2020/4/27 16:07:00 [只看该作者]

更多的时候,流水账是区分产品的,例如下图的库存表:

图片点击可在新窗口打开查看

此类流水账的设计方法要复杂一些,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



如何用流水帐,实现如图功能:

1.表首行是“期初数”,固定,而且不参加计算;

2,每个月月未或每月25日,自动进行月未结算,本月合计,和本年合计;

3,第二个月,第一行是本月的“期初数”(上个月,第一个月的本月合计数);

4,本月合计和本年合计的行,都用红色框框起来。如何代码实现?请老师,指导,谢谢!


图片点击可在新窗口打开查看此主题相关图片如下:流水帐.jpg
图片点击可在新窗口打开查看









 回到顶部
总数 13 1 2 下一页