以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  帮我看看代码到底错在哪里?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=127073)

--  作者:304376480
--  发布时间:2018/11/5 0:24:00
--  帮我看看代码到底错在哪里?
Dim but As Boolean = False
Dim drs As List(of DataRow) = DataTables("销售单").Select("商品ID is not null and 数量 is null")
If drs IsNot Nothing Then
For Each drc As DataRow In drs
drc.SetError("数量", "数量必须大于0!")
Next
but = True
End If
Dim drd As List(of DataRow) = DataTables("销售单").Select("商品ID is not null and 单价 is null")
If drd IsNot Nothing Then
For Each dre As DataRow In drd
dre.SetError("单价", "单价必须大于0!")
Next
but = True
End If
If but = True Then
MessageBox.show("当前数据填写不规范,请检查")
Else
可以执行的代码
end if

这段代码的意思就是:销售单中,找出填写了商品,但没有填写数量或单价的行,提示错误
代码放置在 Button 中,我把整张表都写满了,还是会弹出MessageBox,  这是为什么呢? 而且测试这个错误信息设置是有效果的,For Each是有效果的,
[此贴子已经被作者于2018/11/5 0:27:06编辑过]

--  作者:有点甜
--  发布时间:2018/11/5 8:33:00
--  


Dim drs As List(of DataRow) = DataTables("销售单").Select("商品ID is not null and 数量 is null")
    For Each drc As DataRow In drs
        drc.SetError("数量", "数量必须大于0!")
    Next

Dim drd As List(of DataRow) = DataTables("销售单").Select("商品ID is not null and 单价 is null")

    For Each dre As DataRow In drd
        dre.SetError("单价", "单价必须大于0!")
    Next

If drs.count>0 OrElse drd.count>0 Then
    MessageBox.show("当前数据填写不规范,请检查")
Else
    \'可以执行的代码
End If