以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  请教一下,多条件求和比较后填入信息的事件代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=189783)

--  作者:ganlan
--  发布时间:2023/12/25 19:24:00
--  请教一下,多条件求和比较后填入信息的事件代码
     表A中,想实现,明细中根据客户名称和账单月份,求和明细金额和明细已收金额,如果明细金额总和-明细已收金额总和>0,则月收款状态="未收完","已收完"。
请教一下,怎么写表的事件代码。


例子如下:
客户名   账单月份     金额       已收金额      月收款状态
A         23-11月      1000       900           未收完(说明:A客户23-11月总金额:1300-总已收1200=100)
B         23-11月      500       500           已收完 (说明:B客户23-11月总金额:500-总已收500=0) 
A         23-10月      1000       1000          已收完 (说明:A客户23-10月总金额:1000-总已收1000=0)   
A         23-11月      300       300            未收完(说明:A客户23-11月总金额:1300-总已收1200=100)
B         23-10月      1000       1000         已收完 (说明:B客户23-10月总金额:1600-总已收1600=0)     
B         23-10月      600       600           已收完 (说明:B客户23-10月总金额:1600-总已收1600=0)   
[此贴子已经被作者于2023/12/25 19:24:49编辑过]

--  作者:ganlan
--  发布时间:2023/12/25 19:25:00
--  
例子如下:
客户名   账单月份     金额      已收金额      月收款状态
A         23-11月      1000       900           未收完(说明:A客户23-11月总金额:1300-总已收1200=100)
B         23-11月      500       500           已收完 (说明:B客户23-11月总金额:500-总已收500=0) 
A         23-10月      1000       1000          已收完 (说明:A客户23-10月总金额:1000-总已收1000=0)   
A         23-11月      300       300            未收完(说明:A客户23-11月总金额:1300-总已收1200=100)
B         23-10月      1000       1000         已收完 (说明:B客户23-10月总金额:1600-总已收1600=0)     
B         23-10月      600       600           已收完 (说明:B客户23-10月总金额:1600-总已收1600=0)   

--  作者:ganlan
--  发布时间:2023/12/25 19:33:00
--  
If e.DataCol.Name = "bs0130" Then \'统计销售订单月收款状态
    If e.NewValue Is Nothing Then \'
       e.DataRow("bs0133") = Nothing \'
 
    Else
        Dim ddys As DataRow \'订单账单已收
        Dim ddje As DataRow \'订单账单金额

        
        ddje = DataTables("sdbs01").Compute("sum(bs0117)", "[bs01730] = \'" & e.NewValue & "\' and  bs0104 = \'" & e.DataRow("bs0104") & "\'")
        ddys = DataTables("sdbs01").Compute("sum(bs0141)", "[bs01730] = \'" & e.NewValue & "\' and  bs0104 = \'" & e.DataRow("bs0104") & "\'")

          
            If ddje > ddys Then
                
            e.DataRow("bs0133") = "未收完"
            Else
            e.DataRow("bs0133") = "已收完"
            End If 
            
            
    End If
End If



这样弄不成功
[此贴子已经被作者于2023/12/25 19:34:55编辑过]

--  作者:有点蓝
--  发布时间:2023/12/25 20:30:00
--  
Select Case e.DataCol.name
    Case "金额", "已收金额"
        If e.DataRow.IsNull("金额") OrElse e.DataRow.IsNull("已收金额") OrElse e.DataRow.IsNull("客户名") OrElse e.DataRow.IsNull("账单月份") Then
            e.DataRow("月收款状态") = Nothing
        Else
            Dim filter As String = "[客户名] = \'" & e.DataRow("客户名") & "\' and  账单月份 = \'" & e.DataRow("账单月份") & "\'"
            Dim ddje As Integer = e.DataTable.Compute("sum(金额)", filter)
            Dim ddys As Integer = e.DataTable.Compute("sum(已收金额)", filter)
            If ddje > ddys Then
                e.DataTable.replacefor("月收款状态", "未收完", filter)
            Else
                e.DataTable.replacefor("月收款状态", "已收完", filter)
            End If 
        End If
    Case "客户名"
        If e.NewValue > "" Then
            Dim filter As String = "[客户名] = \'" & e.NewValue & "\' and  账单月份 = \'" & e.DataRow("账单月份") & "\'"
            Dim ddje As Integer = e.DataTable.Compute("sum(金额)", filter)
            Dim ddys As Integer = e.DataTable.Compute("sum(已收金额)", filter)
            If ddje > ddys Then
                e.DataTable.replacefor("月收款状态", "未收完", filter)
            Else
                e.DataTable.replacefor("月收款状态", "已收完", filter)
            End If 
        End If
        If e.OldValue > "" Then
            Dim filter As String = "[客户名] = \'" & e.OldValue & "\' and  账单月份 = \'" & e.DataRow("账单月份") & "\'"
            Dim ddje As Integer = e.DataTable.Compute("sum(金额)", filter)
            Dim ddys As Integer = e.DataTable.Compute("sum(已收金额)", filter)
            If ddje > ddys Then
                e.DataTable.replacefor("月收款状态", "未收完", filter)
            Else
                e.DataTable.replacefor("月收款状态", "已收完", filter)
            End If 
        End If 
        
    Case "账单月份"
        If e.NewValue > "" Then
            Dim filter As String = "[客户名] = \'" & e.DataRow("客户名") & "\' and  账单月份 = \'" & e.NewValue & "\'"
            Dim ddje As Integer = e.DataTable.Compute("sum(金额)", filter)
            Dim ddys As Integer = e.DataTable.Compute("sum(已收金额)", filter)
            If ddje > ddys Then
                e.DataTable.replacefor("月收款状态", "未收完", filter)
            Else
                e.DataTable.replacefor("月收款状态", "已收完", filter)
            End If 
        End If
        If e.OldValue > "" Then
            Dim filter As String = "[客户名] = \'" & e.DataRow("客户名") & "\' and  账单月份 = \'" & e.OldValue & "\'"
            Dim ddje As Integer = e.DataTable.Compute("sum(金额)", filter)
            Dim ddys As Integer = e.DataTable.Compute("sum(已收金额)", filter)
            If ddje > ddys Then
                e.DataTable.replacefor("月收款状态", "未收完", filter)
            Else
                e.DataTable.replacefor("月收款状态", "已收完", filter)
            End If 
        End If 
End Select

--  作者:ganlan
--  发布时间:2023/12/26 11:12:00
--  
学习了,谢谢
--  作者:ganlan
--  发布时间:2023/12/26 11:53:00
--  
你好,我想写在DataColChanged,改了一下,好像不起作用
If e.DataCol.Name = "订单编号" Then
        If e.NewValue Is Nothing Then
            e.DataRow("月收款状态") = Nothing
        Else
            Dim filter As String = "[客户] = \'" & e.DataRow("客户") & "\' and  账单月 = \'" & e.DataRow("账单月") & "\'"
            Dim ddje As Integer = e.DataTable.Compute("sum(金额)", filter)
            Dim ddys As Integer = e.DataTable.Compute("sum(已收金额)", filter)
            If ddje > ddys Then
                e.DataTable.replacefor("月收款状态", "未收完", filter)
            Else
                e.DataTable.replacefor("月收款状态", "已收完", filter)
            End If 
        End If
End If
[此贴子已经被作者于2023/12/26 11:54:14编辑过]

--  作者:有点蓝
--  发布时间:2023/12/26 11:58:00
--  
这个代码和"订单编号"都没有什么关系啊。

如果看不懂代码,完全抄4楼的,改为自己的正确列名。然后旧数据选中金额列,重置一下

--  作者:ganlan
--  发布时间:2023/12/26 12:13:00
--  
好的,搞好了,谢谢