以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]禁止多列输入重复值  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=71166)

--  作者:wangyinming
--  发布时间:2015/7/6 15:29:00
--  [求助]禁止多列输入重复值
看帮助写的代码,目前不能实现禁止多列输入重复值,求纠正?

Select Case e.DataCol.name
    Case "作业日期","加硫炉号","管理号码","管理号码1","生产数","开始时间","结束时间"
        Dim dr As DataRow = e.DataRow
        If dr.IsNull("作业日期") = False AndAlso dr.IsNull("作业日期") = False AndAlso dr.IsNull("加硫炉号") = False AndAlso dr.IsNull("管理号码") = False AndAlso dr.IsNull("管理号码1") = False AndAlso dr.IsNull("生产数")= False AndAlso dr.IsNull("开始时间") = False AndAlso dr.IsNull("结束时间") =False Then
            If e.DataTable.Compute("Count([_Identify])","作业日期 = \'" & dr("作业日期") & "\' And 加硫炉号= \'" & dr("加硫炉号") & "\' And 管理号码= \'" & dr("管理号码") & "\'And 管理号码1= \'" & dr("管理号码1") & "\' And 生产数= \'" & dr("生产数") & "\' And 开始时间= \'" & dr("开始时间") & "\'  And 结束时间= \'" & dr("结束时间") & "\'") > 1 Then
                MessageBox.Show("同一工号已经存在相同管理号码和生产数,请确认是否重复输入!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
            End If
        End If
End Select

--  作者:大红袍
--  发布时间:2015/7/6 15:31:00
--  
 你说的不能禁止是什么情况下的?你这段代码,是所有列都数据都输入了值的情况才判断的。
[此贴子已经被作者于2015/7/6 15:31:16编辑过]

--  作者:wangyinming
--  发布时间:2015/7/6 15:56:00
--  
是不是我复制了上一条数据的原因啊
有些列我没有输入值,是复制的。
输入这些值时不提示 

DataRowAdding
e.DataRow("工程") = Tables("二次加硫").Rows(Tables("二次加硫").Count - 1)("工程")
e.DataRow("作业日期") = Tables("二次加硫").Rows(Tables("二次加硫").Count - 1)("作业日期")
e.DataRow("管理号码") = Tables("二次加硫").Rows(Tables("二次加硫").Count - 1)("管理号码")
e.DataRow("加硫炉号") = Tables("二次加硫").Rows(Tables("二次加硫").Count - 1)("加硫炉号")
e.DataRow("管理号码1") = Tables("二次加硫").Rows(Tables("二次加硫").Count - 1)("管理号码1")
e.DataRow("生产数") = Tables("二次加硫").Rows(Tables("二次加硫").Count - 1)("生产数")


--  作者:大红袍
--  发布时间:2015/7/6 15:58:00
--  
 那就得看你判断的标准了,根据哪些列判断,没有输入值的时候,需不需要判断。
[此贴子已经被作者于2015/7/6 15:57:52编辑过]

--  作者:wangyinming
--  发布时间:2015/7/6 16:07:00
--  
我想根据以下列判断,没有输入时一样要判断

作业日期","加硫炉号","管理号码","管理号码1","生产数","开始时间","结束时间




--  作者:大红袍
--  发布时间:2015/7/6 16:20:00
--  
Select Case e.DataCol.name
    Case "作业日期","加硫炉号","管理号码","管理号码1","生产数","开始时间","结束时间"
        Dim dr As DataRow = e.DataRow
        Dim filter As String = "1=1"
        If dr.IsNull("作业日期") Then
            filter &= " and 作业日期 is null"
        Else
            filter &= " and 作业日期 = \'" & dr("作业日期") & "\'"
        End If
        If dr.IsNull("加硫炉号") Then
            filter &= " and 加硫炉号 is null"
        Else
            filter &= " and 加硫炉号 = \'" & dr("加硫炉号") & "\'"
        End If
        If dr.IsNull("管理号码") Then
            filter &= " and 管理号码 is null"
        Else
            filter &= " and 管理号码 = \'" & dr("管理号码") & "\'"
        End If
        If dr.IsNull("管理号码1") Then
            filter &= " and 管理号码1 is null"
        Else
            filter &= " and 管理号码1 = \'" & dr("管理号码1") & "\'"
        End If
        If dr.IsNull("生产数") Then
            filter &= " and 生产数 is null"
        Else
            filter &= " and 生产数 = \'" & dr("生产数") & "\'"
        End If
        If dr.IsNull("开始时间") Then
            filter &= " and 开始时间 is null"
        Else
            filter &= " and 开始时间 = \'" & dr("开始时间") & "\'"
        End If
        If dr.IsNull("结束时间") Then
            filter &= " and 结束时间 is null"
        Else
            filter &= " and 结束时间 = \'" & dr("结束时间") & "\'"
        End If
        If e.DataTable.Compute("Count([_Identify])",filter) > 1 Then
            MessageBox.Show("同一工号已经存在相同管理号码和生产数,请确认是否重复输入!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
        End If
End Select

--  作者:wangyinming
--  发布时间:2015/7/6 16:44:00
--  
可以这样吗?
编号,发生变化后,检查作业日期","加硫炉号","管理号码","管理号码1","生产数","开始时间","结束时间,有没有重复的。
[此贴子已经被作者于2015/7/6 16:46:14编辑过]

--  作者:大红袍
--  发布时间:2015/7/6 16:46:00
--  
Select Case e.DataCol.name
    Case "编号"
        Dim dr As DataRow = e.DataRow
        Dim filter As String = "1=1"
        If dr.IsNull("作业日期") Then
            filter &= " and 作业日期 is null"
        Else
            filter &= " and 作业日期 = \'" & dr("作业日期") & "\'"
        End If
        If dr.IsNull("加硫炉号") Then
            filter &= " and 加硫炉号 is null"
        Else
            filter &= " and 加硫炉号 = \'" & dr("加硫炉号") & "\'"
        End If
        If dr.IsNull("管理号码") Then
            filter &= " and 管理号码 is null"
        Else
            filter &= " and 管理号码 = \'" & dr("管理号码") & "\'"
        End If
        If dr.IsNull("管理号码1") Then
            filter &= " and 管理号码1 is null"
        Else
            filter &= " and 管理号码1 = \'" & dr("管理号码1") & "\'"
        End If
        If dr.IsNull("生产数") Then
            filter &= " and 生产数 is null"
        Else
            filter &= " and 生产数 = \'" & dr("生产数") & "\'"
        End If
        If dr.IsNull("开始时间") Then
            filter &= " and 开始时间 is null"
        Else
            filter &= " and 开始时间 = \'" & dr("开始时间") & "\'"
        End If
        If dr.IsNull("结束时间") Then
            filter &= " and 结束时间 is null"
        Else
            filter &= " and 结束时间 = \'" & dr("结束时间") & "\'"
        End If
        If e.DataTable.Compute("Count([_Identify])",filter) > 1 Then
            MessageBox.Show("同一工号已经存在相同管理号码和生产数,请确认是否重复输入!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
            e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
        End If
End Select

--  作者:wangyinming
--  发布时间:2015/7/6 16:49:00
--  

图片点击可在新窗口打开查看此主题相关图片如下:无标题.png
图片点击可在新窗口打开查看

为什么还可以重复输入呢

--  作者:大红袍
--  发布时间:2015/7/6 16:51:00
--  

 重置列,看是否弹出提示啊。

 

 不会做就上传具体里例子。