以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  代码改变值后,表事件:DataColChanged 中的代码未执行。  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=74193)

--  作者:yancheng
--  发布时间:2015/9/6 10:24:00
--  代码改变值后,表事件:DataColChanged 中的代码未执行。

表:客户,表事件:DataColChanged  写入:
Select Case e.DataCol.Name
    Case "客户编号"
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
End Select
表:销售订单,表事件:DataColChanged  写入:
If e.DataCol.Name = "客户编号" Then
    Dim cmd As New SQLCommand
    Dim dt As DataTable
    cmd.C
    Dim dr As DataRow = e.DataRow
    cmd.CommandText = "SELECT * Fro m {客户} Where [客户编号] = \'" & dr("客户编号") & "\'"
    dt = cmd.ExecuteReader
    If dt.DataRows.Count > 0 Then
        dr("客户") = dt.DataRows(0)("公司名称")
    Else
        dr("客户")= Nothing
    End If
End If

当表:客户,客户编号,发生变化后, 销售订单,表,中的:客户编号,可以更新,但是,表中的:客户,无法获取:客户表的:公司名称。
也就是说:表:销售订单,表事件:DataColChanged 中的代码未执行。
请问是哪里的问题,怎么解决呢?

在:销售订单,新增加行,输入:客户编号 ,或都:重置:客户编号列,可以更新:客户。就是通过代码改变:客户编号,后,无法自动更新。

--  作者:大红袍
--  发布时间:2015/9/6 10:27:00
--  

select 获取的,是保存后的数据,你这样写

 

Select Case e.DataCol.Name
    Case "客户编号"
        DataTables("销售订单").SqlReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
End Select

--  作者:yancheng
--  发布时间:2015/9/6 10:35:00
--  
 可不可以,只写:

    DataTables("销售订单").SqlReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")

不写:
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")

--  作者:大红袍
--  发布时间:2015/9/6 10:37:00
--  

不写,就无法在foxtable里触发DataColChanged事件。

 

要不你把select语句,改成find函数或者sqlfind函数。


--  作者:yancheng
--  发布时间:2015/9/6 10:54:00
--  
我在客户表,事件,写入:
Select Case e.DataCol.Name
    Case "客户编号"
        DataTables("销售订单").SqlReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
End Select
还是跟之前一样,可以更新:销售订单的,客户编号。但是,客户,更不自动更新。
还是销售订单,的表事件,更改更新未执行。(代码未改,还是SELECT)

--  作者:yancheng
--  发布时间:2015/9/6 10:57:00
--  
而且,我在客户表,更改,客户编号时,数据是保存了的。按理说,销售订单,表事件执行时,应该能获取最新修改的:客户编号和客户。(公司名称)
--  作者:大红袍
--  发布时间:2015/9/6 10:59:00
--  
Select Case e.DataCol.Name
    Case "客户编号"
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
        DataTables("销售订单").DataCols("客户编号").RaiseDataColChanged("客户编号 = \'" & e.OldValue & "\'")
End Select

 

-----------------

 

If e.DataCol.Name = "客户编号" Then
    Dim dr As DataRow = DataTables("客户").Find("[客户编号] = \'" & dr("客户编号") & "\'")
    If dr IsNot Nothing Then
        dr("客户") = dr("公司名称")
    Else
        dr("客户")= Nothing
    End If
End If


--  作者:yancheng
--  发布时间:2015/9/6 11:13:00
--  
客户表:
Select Case e.DataCol.Name
    Case "客户编号"
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
        DataTables("销售订单").DataCols("客户编号").RaiseDataColChanged("客户编号 = \'" & e.OldValue & "\'")
End Select
销售订单:
If e.DataCol.Name = "客户编号" Then
    Dim dr As DataRow = DataTables("客户").Find("客户编号 = \'" & e.DataRow("客户编号") & "\'")
    If dr IsNot Nothing Then
        e.DataRow("客户") = dr("公司名称")
    Else
        e.DataRow("客户")= Nothing
    End If
End If

还是不行,跟以前一样。

--  作者:大红袍
--  发布时间:2015/9/6 11:14:00
--  
Select Case e.DataCol.Name
    Case "客户编号"
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
        DataTables("销售订单").DataCols("客户编号").RaiseDataColChanged("客户编号 = \'" & e.NewValue & "\'")
End Select

 

-----------------

 

If e.DataCol.Name = "客户编号" Then
    Dim dr As DataRow = DataTables("客户").Find("[客户编号] = \'" & dr("客户编号") & "\'")
    If dr IsNot Nothing Then
        dr("客户") = dr("公司名称")
    Else
        dr("客户")= Nothing
    End If
End If


--  作者:yancheng
--  发布时间:2015/9/6 11:26:00
--  
上面的代码,还是不符合要求,销售订单的,客户,还是旧值。
我把客户表的代码写成下面的,就行了。
Select Case e.DataCol.Name
    Case "客户编号"
        DataTables("销售订单").ReplaceFor(e.DataCol.Name,e.NewValue,"客户编号 = \'" & e.OldValue & "\'")
    Case "公司名称"
        DataTables("销售订单").DataCols("客户编号").RaiseDataColChanged("客户编号 = \'" & e.DataRow("客户编号") & "\'")
End Select

但是,不知道有没有更好的办法?