以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]跨表多条计算  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=90972)

--  作者:铜豌豆之首
--  发布时间:2016/9/26 21:05:00
--  [求助]跨表多条计算
用代码如何通过A表 条件(日期、姓名),计算出 B表 条件(日期、姓名)数量
A表                                                             B表  
         日期          姓名          金额    单价                日期                姓名      数量
 2015/06/07       张三         50       5                   2015/06/07     张三     10


--  作者:有点蓝
--  发布时间:2016/9/26 22:09:00
--  
参考:http://www.foxtable.com/webhelp/scr/1451.htm

表B DataColChanged事件中
Select Case e.DataCol.Name
    Case "姓名"
        If e.DataRow.Isnull("姓名") = False Then
            Dim dr As DataRow
            dr = DataTables("表A").Find("[姓名] = \'" & e.NewValue & "\'")
            If dr IsNot Nothing Then \'如果找到了同名的产品行,也就是dr不是Nothing
                e.DataRow("数量") = dr("金额") / dr("单价")
            End If
        End If
End Select
[此贴子已经被作者于2016/9/26 22:09:10编辑过]

--  作者:铜豌豆之首
--  发布时间:2016/9/27 14:38:00
--  
要日期和姓名同时对应的总共有两个条件,我看给我的代码只有姓名一个条件
--  作者:有点蓝
--  发布时间:2016/9/27 15:13:00
--  
学好基础,看懂代码,想要什么条件自己加



--  作者:有点蓝
--  发布时间:2016/9/27 15:15:00
--  
Select Case e.DataCol.Name
    Case "姓名","日期"
        If e.DataRow.Isnull("姓名") = False andalso e.DataRow.Isnull("日期") = False Then
            Dim dr As DataRow
            dr = DataTables("表A").Find("[姓名] = \'" & e.DataRow("姓名") & "\' and 日期=#" & e.DataRow("日期") & "#")
            If dr IsNot Nothing Then \'如果找到了同名的产品行,也就是dr不是Nothing
                e.DataRow("数量") = dr("金额") / dr("单价")
            End If
        End If
End Select