以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=89881)

--  作者:xh2207
--  发布时间:2016/8/31 16:39:00
--  [求助]

请教:

 

第一列    第二列     第三列

123       ABC      001

123       DEF      001

456       ABC      001

789       DEF      001

789       DEF      001     不允许 

789       DEF      002     允许

123       ABC      001     不允许

 

如何判断,当第三列的值相同时,不允许第一列和第二列同时重复。当第三列的值不相同时,允许第一列和第二列同时重复。

请教如何完善程序,谢谢!

If e.DataCol.Name= "第一列" Then
    Dim dr As DataRow = e.DataTable.Find("第一列=\'" & e.NewValue & "\' and 第二列=\'" & e.DataRow("第二列") & "\'")
    If dr IsNot Nothing Then
        e.Cancel = True
    End If
ElseIf e.DataCol.Name= "第二列" Then
    Dim dr As DataRow = e.DataTable.Find("第二列=\'" & e.NewValue & "\' and 第一列=\'" & e.DataRow("第一列") & "\'")
    If dr IsNot Nothing Then
        e.Cancel = True
    End If
End If


--  作者:狐狸爸爸
--  发布时间:2016/8/31 16:58:00
--  

实际上就是不允许三列都相同啊:

 

 

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目267.table


--  作者:xh2207
--  发布时间:2016/8/31 17:30:00
--  

逻辑思维的错误,老是想在同订单号范围判断品名和型号规格

 

 

Select Case e.DataCol.name
    Case "订单号"
        If e.DataCol.Name= "订单号" Then
            Dim dr As DataRow = e.DataTable.Find("订单号=\'" & e.NewValue & "\' and 品名=\'" & e.DataRow("品名") & "\' and 型号规格=\'" & e.DataRow("型号规格") & "\'")
            If dr IsNot Nothing Then
                MessageBox.Show("已经存在相同型号和规格的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                e.Cancel = True
            End If
        End If
    Case "品名"
        If e.DataCol.Name= "品名" Then
            Dim dr As DataRow = e.DataTable.Find("品名=\'" & e.NewValue & "\' and 订单号=\'" & e.DataRow("订单号") & "\' and 型号规格=\'" & e.DataRow("型号规格") & "\'")
            If dr IsNot Nothing Then
                MessageBox.Show("已经存在相同型号和规格的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                e.Cancel = True
            End If
        End If
       
    Case "型号规格"
        If e.DataCol.Name= "型号规格" Then
            Dim dr As DataRow = e.DataTable.Find("型号规格=\'" & e.NewValue & "\' and 订单号=\'" & e.DataRow("订单号") & "\' and 品名=\'" & e.DataRow("品名") & "\'")
            If dr IsNot Nothing Then
                MessageBox.Show("已经存在相同型号和规格的行!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                e.Cancel = True
            End If
        End If
End Select