以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关于关联表克隆行的问题  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=99522)

--  作者:舞楼名角
--  发布时间:2017/4/20 18:20:00
--  关于关联表克隆行的问题
前提:一、表产品型号与表产品配方根据列产品型号关联,克隆代码如下(能正常克隆):
Dim r As Row = Tables("产品型号").Current
Dim dnew As Row = Tables("产品型号").AddNew
Dim name As String = r("产品型号") & "_复件"
For Each c As Col In Tables("产品型号").Cols
    If c.Name = "产品型号" Then
        dnew(c.Name) = name
    ElseIf c.Name <> "_Identify" Then
        dnew(c.Name) = r(c.Name)
    End If
Next
Dim drs As List(Of DataRow)
drs = r.DataRow.GetChildRows("产品配方")
Dim rc As DataRow
For Each dr As DataRow In drs
    rc = dr.Clone
    rc("产品型号") = name
Next
前提二、表产品型号中列产品型号禁止了重复,且表Datacolchanging属性中也写了如下禁止重复代码
If e.DataCol.Name = "产品型号" Then
    Dim dr As DataRow
    dr = e.DataTable.Find("产品型号 = \'" & e.NewValue & "\'")
    If dr IsNot Nothing Then
        MessageBox.Show("此产品型号已经存在!")
        e.Cancel = True
    End If
End If

问题:我用同一行点两次克隆行按钮,第一次成功,第二次不成功(因为禁止重复),但是关联表产品配方中依然克隆了关联行到第一次中;
我想解决的问题是:因重复克隆的时候没有成功,那么不克隆关联表中的行和当前克隆的行。
请大家帮忙,谢谢!

--  作者:有点色
--  发布时间:2017/4/20 20:30:00
--  

 在克隆代码那里判断

 

Dim r As Row = Tables("产品型号").Current
Dim name As String = r("产品型号") & "_复件"
Dim fdr As DataRow = DataTables("产品型号").Find("产品型号 = \'" & name & "\'")
If fdr IsNot Nothing Then
    msgbox("重复了")
Else
    Dim dnew As Row = Tables("产品型号").AddNew
    For Each c As Col In Tables("产品型号").Cols
        If c.Name = "产品型号" Then
            dnew(c.Name) = name
        ElseIf c.Name <> "_Identify" Then
            dnew(c.Name) = r(c.Name)
        End If
    Next
    Dim drs As List(Of DataRow)
    drs = r.DataRow.GetChildRows("产品配方")
    Dim rc As DataRow
    For Each dr As DataRow In drs
        rc = dr.Clone
        rc("产品型号") = name
    Next
End If


--  作者:舞楼名角
--  发布时间:2017/4/21 10:18:00
--  
非常感谢有点色!OK的
--  作者:舞楼名角
--  发布时间:2018/7/19 12:39:00
--  
请教以上代码中如果“产品型号”列是用好几个列组合起来的编码列,这代码在如何写?帮忙改改,谢谢
--  作者:有点甜
--  发布时间:2018/7/19 12:52:00
--  
以下是引用舞楼名角在2018/7/19 12:39:00的发言:
请教以上代码中如果“产品型号”列是用好几个列组合起来的编码列,这代码在如何写?帮忙改改,谢谢

 

把各个列的值合并到一个列里面处理。