以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  编号重复,清空当前行  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=107091)

--  作者:cd_tdh
--  发布时间:2017/9/21 10:37:00
--  编号重复,清空当前行

老师,我DataColChanging代码验证编号禁止重复,重复时,清空当前行,代码如下:这样的效果是直接删除行了,只清空不删除怎么改?

If e.DataCol.Name = "项目编码"  Then
    Dim dr  As  DataRow
    dr = e.DataTable.Find("项目编码 = \'" & e.NewValue &  "\'")
    If dr IsNot Nothing Then
        MessageBox.Show("此项目编码已经存在,请复核项目名称!")
        Dim r As Row = Tables("合同签订").Current
        r.Reject()
    End  If
End  If

 

项目编码是直接通过输入其他列引用过来的。

[此贴子已经被作者于2017/9/21 10:39:03编辑过]

--  作者:drcqh
--  发布时间:2017/9/21 10:46:00
--  


If e.DataCol.Name = "项目编码"  Then
    Dim dr  As  DataRow
    dr = e.DataTable.Find("项目编码 = \'" & e.NewValue &  "\'")
    If dr IsNot Nothing Then
         for each dc as datacol in  e.DataTable.datacols

            dr(dc.name)=nothing

    next
    End  If
End  If



--  作者:cd_tdh
--  发布时间:2017/9/21 10:52:00
--  
老师,这样不对,把我原来有的一样的项目编号的行的内容清空了,把新增加的行的编号留下了。
[此贴子已经被作者于2017/9/21 10:55:30编辑过]

--  作者:有点甜
--  发布时间:2017/9/21 10:57:00
--  
If e.DataCol.Name = "项目编码"  Then
    Dim dr  As  DataRow
    dr = e.DataTable.Find("项目编码 = \'" & e.NewValue &  "\'")
    If dr IsNot Nothing Then
        e.cancel = True
        For Each dc As DataCol In e.DataTable.datacols
            If dc.Expression = "" Then
                e.DataRow(dc.name)=Nothing
            End If
        Next
    End  If
End  If

--  作者:cd_tdh
--  发布时间:2017/9/21 11:14:00
--  
以下是引用有点甜在2017/9/21 10:57:00的发言:
If e.DataCol.Name = "项目编码"  Then
    Dim dr  As  DataRow
    dr = e.DataTable.Find("项目编码 = \'" & e.NewValue &  "\'")
    If dr IsNot Nothing Then
        e.cancel = True
        For Each dc As DataCol In e.DataTable.datacols
            If dc.Expression = "" Then
                e.DataRow(dc.name)=Nothing
            End If
        Next
    End  If
End  If

有点甜老师,现在出来是这样,是不是我没表述清楚,我是通过窗口录入,选择项目名称,自动引用的另外一个表的前四列:

 


图片点击可在新窗口打开查看此主题相关图片如下:qq截图20170921111254.jpg
图片点击可在新窗口打开查看
[此贴子已经被作者于2017/9/21 11:18:51编辑过]

--  作者:有点甜
--  发布时间:2017/9/21 12:48:00
--  
回复5楼,贴出你窗口录入后引用的代码。
--  作者:cd_tdh
--  发布时间:2017/9/21 13:07:00
--  
以下是引用有点甜在2017/9/21 12:48:00的发言:
回复5楼,贴出你窗口录入后引用的代码。

DataColChanged代码如下

If e.DataCol.Name = "项目名称" Then  \'如果内容发生变动的是品名列
    If e.NewValue Is Nothing Then  \'如果新值是空白,也就是品名列的内容为空
        e.DataRow("项目编码") = Nothing \'那么清空此行单价列的内容
        e.DataRow("所属机构") = Nothing \'那么清空此行单价列的内容
        e.DataRow("项目类别") = Nothing \'那么清空此行单价列的内容
        e.DataRow("招标方式") = Nothing \'那么清空此行单价列的内容
    Else
        Dim dr  As  DataRow \'否则在产品表查找同名的产品行,将找到的行赋值给变量dr
        dr = DataTables("中标统计").Find("[项目名称] = \'" & e.NewValue &  "\'")
        If dr IsNot  Nothing  Then  \'如果找到了同名的产品行,也就是dr不是Nothing
            e.DataRow("项目编码") = dr("项目编码")
            e.DataRow("所属机构") = dr("所属机构")
            e.DataRow("项目类别") = dr("项目类别")
            e.DataRow("招标方式") = dr("招标方式")
        End  If
    End If
End If


--  作者:有点甜
--  发布时间:2017/9/21 13:19:00
--  

4楼代码没问题,datacolchanging事件写4楼代码有什么问题?

 

做例子发上来测试。

[此贴子已经被作者于2017/9/21 13:19:36编辑过]

--  作者:cd_tdh
--  发布时间:2017/9/21 13:38:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目2.table

老师,示例已上传。
--  作者:有点甜
--  发布时间:2017/9/21 15:34:00
--  

datacolchanged事件

 

If e.DataCol.Name = "第五列" Then  \'如果内容发生变动的是品名列
    If e.NewValue Is Nothing Then  \'如果新值是空白,也就是品名列的内容为空
        e.DataRow("第一列") = Nothing \'那么清空此行单价列的内容
        e.DataRow("第二列") = Nothing \'那么清空此行单价列的内容
        e.DataRow("第三列") = Nothing \'那么清空此行单价列的内容
        e.DataRow("第四列") = Nothing \'那么清空此行单价列的内容
    Else
        Dim dr  As  DataRow \'否则在产品表查找同名的产品行,将找到的行赋值给变量dr
        dr = DataTables("表A").Find("[第五列] = \'" & e.NewValue &  "\'")
        If dr IsNot  Nothing  Then  \'如果找到了同名的产品行,也就是dr不是Nothing
           
            Dim fdr  As  DataRow
            fdr = e.DataTable.Find("第一列 = \'" & dr("第一列") &  "\'")
            If fdr IsNot Nothing Then
                For Each dc As DataCol In e.DataTable.datacols
                    If dc.Expression = "" Then
                        e.DataRow(dc.name)=Nothing
                    End If
                Next
            Else
                e.DataRow("第一列") = dr("第一列")
                e.DataRow("第二列") = dr("第二列")
                e.DataRow("第三列") = dr("第三列")
                e.DataRow("第四列") = dr("第四列")
            End  If
        End  If
    End If
End If