老师,我终于搞定了,您写的代码还是不行,我为了简化代码,将起始时间与结束时间分开判断,代码如下:
'同卷号时间冲突判断
If e.DataCol.Name = "审核" AndAlso e.NewValue = True Then
Dim dr1 As DataRow = _dt工序合并表.SQLFind("([起始时间] < '" & e.DataRow("起始时间") & "' and [结束时间] > '" & e.DataRow("起始时间") & "') And [卷号] = '" & e.DataRow("卷号") &"'")
If dr1 IsNot Nothing Then
e.Cancel = True
MessageBox.Show("同卷号[起始时间]冲突,未修复前禁止审核!" & vbcrlf & "冲突工序: " & dr1("来源表名") & vbcrlf & "行号流水: " & dr1("行号流水") ,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else
Dim dr2 As DataRow = _dt工序合并表.SQLFind("([起始时间] < '" & e.DataRow("结束时间") & "' and [结束时间] > '" & e.DataRow("结束时间") & "') And [卷号] = '" & e.DataRow("卷号") &"'")
If dr2 IsNot Nothing Then
e.Cancel = True
MessageBox.Show("同卷号[结束时间]冲突,未修复前禁止审核!" & vbcrlf & "冲突工序: " & dr2("来源表名") & vbcrlf & "行号流水: " & dr2("行号流水") ,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
Else
Dim dr3 As DataRow = _dt工序合并表.SQLFind("([起始时间] > '" & e.DataRow("起始时间") & "' and [结束时间] < '" & e.DataRow("结束时间") & "') And [卷号] = '" & e.DataRow("卷号") &"'")
If dr3 IsNot Nothing Then
e.Cancel = True
MessageBox.Show("同卷号[起始时间]及[结束时间]冲突,未修复前禁止审核!" & vbcrlf & "冲突工序: " & dr3("来源表名") & vbcrlf & "行号流水: " & dr3("行号流水") ,"提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
End If
End If
End If
End If
三层IF看的有点烦,有办法改进吗?
[此贴子已经被作者于2015/8/10 13:47:41编辑过]