以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  如何实现针对不同的客户显示上次售价?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=71774)

--  作者:minxizai
--  发布时间:2015/7/17 18:28:00
--  如何实现针对不同的客户显示上次售价?
想实现的功能:在订单界面输入客户和产品后,价格列自动填入该客户上次订单的售价
Dim dr As DataRow
Dim pm As String = Tables("订单明细").Current.DataRow("品名")
Dim kh As String = Tables("订单明细").Current.DataRow("客户名称")
dr = DataTables("订单明细").Find(".品名 = pm & .客户名称 = kh ","日期 Desc")
If dr IsNot Nothing Then 
    Tables("订单明细").Current.DataRow("价格") = dr("价格")
End If
另一种也是不行:
If e.DataCol.Name = "客户名称" Or e.DataCol.Name = "品名" Then
    Dim dr As DataRow
    Dim Filter As String
    Filter = "[客户名称] = \'" & e.DataRow("客户名称") & "\' And [品名] = \'" & e.DataRow("品名") & "\'"
    dr = DataTables("订单明细").Find(Filter ,"日期 Desc")
    If dr IsNot Nothing Then 
        e.DataRow("价格") = dr("价格")
    End If
End If
还有个疑问:当代码查找到需要的行时,current是当前需要输入的行,还是查找到的行?
[此贴子已经被作者于2015/7/17 20:37:25编辑过]

--  作者:狐狸爸爸
--  发布时间:2015/7/18 10:27:00
--  
第二种方法应该可以,不过应该稍微改一下,排除掉本行:

If e.DataCol.Name = "客户名称" Or e.DataCol.Name = "品名" Then
    Dim dr As DataRow
    Dim Filter As String
    Filter = "[客户名称] = \'" & e.DataRow("客户名称") & "\' And [品名] = \'" & e.DataRow("品名") & "\' And [_Identify] <> " & e.DataRow("_Identify")
    dr = DataTables("订单明细").Find(Filter ,"日期 Desc")
    If dr IsNot Nothing Then 
        e.DataRow("价格") = dr("价格")
    End If
End If

如果还不行,做个例子发上来。