以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]代码不完全加载后台数据执行?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=125544)

--  作者:manyifuwu
--  发布时间:2018/9/30 13:46:00
--  [求助]代码不完全加载后台数据执行?

数据行是基于当前加载sql部分数据的,1、怎么设置基于所有数据(包括后台数据)执也可以执行以下代码,找出重复行。2、这两个代码,可以优化吗?请老师指导

 

Select Case e.DataCol.name
    Case "截止日期","工号","时段"
        Dim dr As DataRow = e.DataRow
        If dr.IsNull("截止日期") = False AndAlso dr.IsNull("时段") = False  AndAlso dr.IsNull("工号") = False Then
            For Each s As String In dr("工号").split(",")
                Dim filter = "截止日期 = \'" & dr("截止日期") & "\' and 时段 = \'" & dr("时段") & "\' and (\',\'+工号+\',\') like \'%," & s & ",%\'"
                Dim count = e.DataTable.Compute("count(时段)", filter)
                If count > 1 Then
                    msgbox("查看员工重复")
                    e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
                    Exit For
                End If
            Next
        End If
End Select


sqlFind

Select Case e.DataCol.name
    Case "截止日期","编号"
        Dim dr1 As DataRow = e.DataRow
        If dr1.IsNull("截止日期")  = False  AndAlso dr1.IsNull("编号") = False Then
            For Each s As String In dr1("编号").split(",")
                Dim filter = "截止日期 = \'" & dr1("截止日期") & "\'and 编号 = \'" & dr1("编号") & "\'"
                Dim count = e.DataTable.Compute("count(编号)", filter)
                If count > 1 Then
                    msgbox("查看客户是否重复")
                    e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
                    Exit For
                End If
            Next
        End If
End Select

[此贴子已经被作者于2018/9/30 13:48:01编辑过]

--  作者:有点蓝
--  发布时间:2018/9/30 14:12:00
--  
Select Case e.DataCol.name
    Case "截止日期","工号","时段"
        Dim dr As DataRow = e.DataRow
        If dr.IsNull("截止日期") = False AndAlso dr.IsNull("时段") = False  AndAlso dr.IsNull("工号") = False Then
            Dim filter As String = "截止日期 = \'" & dr("截止日期") & "\' and 时段 = \'" & dr("时段") & "\' and (1=2 "
            For Each s As String In dr("工号").split(",")
                filter= filter & " or (\',\'+工号+\',\') like \'%," & s & ",%\'"
            Next
            filter = filter & ")"
            Dim count = e.DataTable.SqlCompute("count(时段)", filter)
            If count > 1 Then
                msgbox("查看员工重复")
                e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
            End If
        End If
End Select

--  作者:manyifuwu
--  发布时间:2018/9/30 14:14:00
--  

还是要分成两段代码?

下面这段,怎改呢?谢谢!(判定截止日期和编号是否重复,         这两列里没有包含(,)逗号。)

Select Case e.DataCol.name
    Case "截止日期","编号"
        Dim dr1 As DataRow = e.DataRow
        If dr1.IsNull("截止日期")  = False  AndAlso dr1.IsNull("编号") = False Then
            For Each s As String In dr1("编号").split(",")
                Dim filter = "截止日期 = \'" & dr1("截止日期") & "\'and 编号 = \'" & dr1("编号") & "\'"
                Dim count = e.DataTable.Compute("count(编号)", filter)
                If count > 1 Then
                    msgbox("查看客户是否重复")
                    e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
                    Exit For
                End If
            Next
        End If
End Select

[此贴子已经被作者于2018/9/30 14:22:37编辑过]

--  作者:有点蓝
--  发布时间:2018/9/30 14:27:00
--  
方法完全一样,参考2楼自己改
--  作者:manyifuwu
--  发布时间:2018/9/30 15:43:00
--  

老师,我没有编正常,弹出窗口关不了。

Select Case e.DataCol.name
    Case "截止日期","编号"
        Dim dr1 As DataRow = e.DataRow
        If dr1.IsNull("截止日期") =  False  AndAlso dr1.IsNull("编号") = False Then
            Dim filter As String = "截止日期 = \'" & dr1("截止日期") & "\' and (1=2 "
            For Each s As String In dr1("编号").split(",")
                filter= filter & " or (\',\'+编号+\',\') like \'%," & s & ",%\'"
            Next
            filter = filter & ")"
            Dim count = e.DataTable.SqlCompute("count(编号)", filter)
            If count > 1 Then
                msgbox("日期   客户编号    重复")
                e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
            End If
        End If
End Select

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

[此贴子已经被作者于2018/9/30 15:43:35编辑过]

--  作者:有点蓝
--  发布时间:2018/9/30 16:13:00
--  
旧的数据也有可能会重复,直接清空吧

e.DataRow(e.DataCol.Name) = nothing \'取消输入

--  作者:manyifuwu
--  发布时间:2018/9/30 18:04:00
--  

这段代码,不生效。

 发帖心情 Post By:2018/9/30 14:12:00 [只看该作者]

Select Case e.DataCol.name
    Case "截止日期","工号","时段"
        Dim dr As DataRow = e.DataRow
        If dr.IsNull("截止日期") = False AndAlso dr.IsNull("时段") = False  AndAlso dr.IsNull("工号") = False Then
            Dim filter As String = "截止日期 = \'" & dr("截止日期") & "\' and 时段 = \'" & dr("时段") & "\' and (1=2 "
            For Each s As String In dr("工号").split(",")
                filter= filter & " or (\',\'+工号+\',\') like \'%," & s & ",%\'"
            Next
            filter = filter & ")"
            Dim count = e.DataTable.SqlCompute("count(时段)", filter)
            If count > 1 Then
                msgbox("查看员工重复")
                e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
            End If
        End If
End Select

[此贴子已经被作者于2018/9/30 18:04:37编辑过]

--  作者:有点甜
--  发布时间:2018/10/4 11:10:00
--  

试试这样,如果还不行,做个例子上来测试。

 

Select Case e.DataCol.name
    Case "截止日期","工号","时段"
        Dim dr As DataRow = e.DataRow
        If dr.IsNull("截止日期") = False AndAlso dr.IsNull("时段") = False  AndAlso dr.IsNull("工号") = False Then
            Dim filter As String = "截止日期 = \'" & dr("截止日期") & "\' and 时段 = \'" & dr("时段") & "\' and (1=2 "
            For Each s As String In dr("工号").split(",")
                filter= filter & " or (\',\'+工号+\',\') like \'%," & s & ",%\'"
            Next
            filter = filter & ")"
            Dim count = e.DataTable.SqlCompute("count(时段)", filter)
            If count > 1 Then
                msgbox("查看员工重复")
                e.DataRow(e.DataCol.Name) = e.OldValue \'取消输入
            Else
                e.datarow.save
            End If
        End If
End Select

--  作者:manyifuwu
--  发布时间:2018/10/21 0:49:00
--  

 

[此贴子已经被作者于2018/10/21 0:49:25编辑过]

--  作者:有点甜
--  发布时间:2018/10/21 12:50:00
--  
以下是引用manyifuwu在2018/10/21 0:49:00的发言:

 

[此贴子已经被作者于2018/10/21 0:49:25编辑过]

 

没看到附件,如果还有问题,具体实例发上来测试。