以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]if……else后总被执行的代码问题?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=132695)

--  作者:bashanren
--  发布时间:2019/3/27 16:54:00
--  [求助]if……else后总被执行的代码问题?

各位老师下午好!在下面的代码中:e.DataRow("文号") = qz & "【" & nh & "】" & xh & "号"    这段在dr找到重复行和未找到重复行,都被执行了,我本意是想如果找到了相同行的话,就将文件序号清空并退出这段代码,可是在运行时,在提示“此文号已经存在!”并清空文件序号单元格后,还是将“文号”组合填入了,不知错在哪儿,请老师帮我修改并精简一下下面的代码,谢谢!!

If e.DataCol.name ="文件序号" Then
    Dim qz As String = e.DataRow("文号前缀")
    Dim nh As String = e.DataRow("年号")
    Dim xh As String = e.DataRow("文件序号")
Dim wh As String = qz & "【" & nh & "】" & xh & "号"
Dim dr As DataRow = e.DataTable.Find("文号 = \'" & wh & "\'")
MessageBox.show(wh)
    If dr IsNot Nothing Then
        MessageBox.Show("此文号已经存在!")
e.DataRow("文件序号") = Nothing
        e.Cancel = True
Else
e.DataRow("文号") = qz & "【" & nh & "】" & xh & "号"
       End If
End If


--  作者:有点甜
--  发布时间:2019/3/27 17:26:00
--  
代码没问题,请上传具体实例测试。
--  作者:bashanren
--  发布时间:2019/3/28 10:12:00
--  
谢谢甜老师!!我将项目呈上,麻烦帮我看看,目前问题有两个:问题一,是在双击表行进入“文件登记”窗口后,修改“文件序号”后,只要是有相同“文号”,会返回去执行两次;问题二,在窗口中修改原有行时内容时,有时窗口上输入了,但不会将修改的内容加到表中去。还谢老师指导!!
[此贴子已经被作者于2019/3/28 10:13:00编辑过]

--  作者:bashanren
--  发布时间:2019/3/28 10:16:00
--  
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:文件管理.foxdb

谢谢甜老师!!我将项目呈上,麻烦帮我看看,目前问题有两个:问题一,是在双击表行进入“文件登记”窗口后,修改“文件序号”后,只要是有相同“文号”,会返回去执行两次;问题二,在窗口中修改原有行时内容时,有时窗口上输入了,但不会将修改的内容加到表中去。还谢老师指导!!
[此贴子已经被作者于2019/3/28 10:31:56编辑过]

--  作者:有点甜
--  发布时间:2019/3/28 10:41:00
--  

1、

 

If e.DataCol.name ="文件序号" Then
    Dim dr As DataRow=e.DataRow
    If dr.Isnull("文号前缀") Then
        MessageBox.Show("文号前缀和文件年号不能为空值!", "提示")
        e.Cancel = True
    End If
    \'Else
    Dim qz As String = e.DataRow("文号前缀")
    Dim nh As String = e.DataRow("年号")
    Dim xh As String = e.DataRow("文件序号")
    Dim wh As String = qz & "【" & nh & "】" & xh & "号"
    MessageBox.show(wh)
    Dim dr1 As DataRow = e.DataTable.Find("文号 = \'" & wh & "\'")
systemready = False
    If dr1 IsNot Nothing Then
        MessageBox.Show("此文号已经存在!")
        e.DataRow("文件序号") = Nothing
        e.Cancel = True
        \'ElseIf dr Is Nothing Then
    Else
        e.DataRow("文号") = qz & "【" & nh & "】" & xh & "号"
        \'e.DataRow("登记人") = _username
        \'e.DataRow("登记时间") = Date.now
    End If
systemready = True
End If

 

2、

 

e.cancel = True
Forms("文件登记").Open()