Foxtable(狐表)用户栏目专家坐堂 → 这个代码哪里错了?闪退,而且不显示上传的图片


  共有2007人关注过本帖树形打印复制链接

主题:这个代码哪里错了?闪退,而且不显示上传的图片

帅哥哟,离线,有人找我吗?
hongye
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:2943 威望:0 精华:0 注册:2011/3/15 12:49:00
这个代码哪里错了?闪退,而且不显示上传的图片  发帖心情 Post By:2020/1/8 13:25:00 [只看该作者]

能不能帮我看看,是出什么问题了
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:人员新增.rar


Dim r As Row = Tables("员工信息_员工信息").Current
Dim sffo As String
sffo = ProjectPath & "Attachments\sdb.cfg"
Dim txt As WinForm.Label = e.Form.Controls("Label1")
If FileSys.FileExists(sffo) Then
    Dim Info As String
    Info = FileSys.ReadAllText(sffo) '读取生成的文本文件
    info = info.Replace(vbcrlf,vblf) '将回车换行替换为换行
    Dim pars() As String = Info.Split(vblf) '将读取的信息拆分为数组
    Dim tsq1 As String
    Dim tsq2 As String
    Dim tsq3 As String
    Dim jzf1 As String = pars(0).SubString(6)
    Dim jzf3 As String = pars(1).SubString(7)
    Dim jzf5 As String = pars(2).SubString(10)
    tsq1 = jzf1.Trim()
    tsq2 = jzf3.Trim()
    tsq3 = jzf5.Trim()
    Vars.Add("AppID",Gettype(String),tsq1)
    Vars.Add("APIKey",Gettype(String),tsq2)
    Vars.Add("SecretKey",Gettype(String),tsq3)
    Dim dlg As New FolderBrowserDialog '选择目录对话框
    dlg.Description = "选择文件夹" '对话框的说明
    dlg.ShowNewFolderButton = False '不显示"新建文件夹"按钮
    If dlg.ShowDialog = DialogResult.Ok Then '如果单击确定
        MessageBox.Show("你选择的目录是:" & dlg.SelectedPath ,"提示")
        For Each File As String In FileSys.GetFiles(dlg.SelectedPath)  '列出已选择文件夹根目录下所有的文件名
            If File.EndsWith("1.jpg") Or File.EndsWith("1.JPG") Then '如果文件后缀名为"1.jpg"或者"1.JPG"为真
                MessageBox.Show(File)
                try
                    '----------------------------------识别身份证正面------------------------------------------------------
                    Dim client As new Baidu.Aip.Ocr.Ocr(Vars("APIKey"), Vars("SecretKey")) '初始化接口类,传入创建的应用的API Key,Secret Key
                    client.Timeout = 60000 '设置超时时间
                    Dim data() As Byte = System.IO.File.ReadAllBytes(File)'dlg.FileName) '把图片文件字节流加载进来,
                    Dim options As new Dictionary(of String, object) '使用字典传递参数
                    'options.Add("detect_direction","true") '是否检测图像朝向,默认不检测
                    options.Add("detect_risk","true")
                    Dim jo = client.Idcard(data,"front", options) '调用接口开始识别,返回值为JObject对象
                    If jo("error_code") IsNot Nothing AndAlso jo("error_code") <> 0 Then
                        txt.text = "识别失败: " & vbcrlf & jo("error_msg").Tostring
                    Else
                        Dim sbu As new StringBuilder
                        sbu.AppendLine( "--------************-----------")
                        sbu.AppendLine( "状态:" & jo("image_status").Tostring)
                        If jo("risk_type") IsNot Nothing Then sbu.AppendLine("风险类型:" & jo("risk_type").Tostring)
                        If jo("edit_tool") IsNot Nothing Then sbu.AppendLine("编辑状态:" & jo("edit_tool").Tostring)
                        sbu.AppendLine( "--------************-----------")
                        sbu.AppendLine( "识别出" & jo("words_result_num").Tostring & "条信息:")
                        If jo("words_result")("公民身份号码") IsNot Nothing Then sbu.AppendLine( "--公民身份号码:" & jo("words_result")("公民身份号码")("words").ToString)
                        If jo("words_result")("出生") IsNot Nothing Then sbu.AppendLine( "--出生日期:" & jo("words_result")("出生")("words").ToString)
                        If jo("words_result")("姓名") IsNot Nothing Then sbu.AppendLine( "--姓名:" & jo("words_result")("姓名")("words").ToString)
                        If jo("words_result")("性别") IsNot Nothing Then sbu.AppendLine( "--性别:" & jo("words_result")("性别")("words").ToString)
                        If jo("words_result")("民族") IsNot Nothing Then sbu.AppendLine( "--民族:" & jo("words_result")("民族")("words").ToString)
                        If jo("words_result")("住址") IsNot Nothing Then sbu.AppendLine( "--住址:" & jo("words_result")("住址")("words").ToString)
                        Dim gSf0 As String =jo("words_result")("姓名")("words").ToString
                        Dim gSf1 As String =jo("words_result")("公民身份号码")("words").ToString
                        Dim gSf2 As String =jo("words_result")("性别")("words").ToString
                        Dim gSf3 As String =jo("words_result")("住址")("words").ToString
                        If gSf1.Length = 18 Then
                            With Tables("员工信息_员工信息")
                                Dim ri As Integer
                                ri = .Find(gSf1, .RowSel + 1, "证件号码", False, False, True)
                                If ri > - 1 Then '如果找到符合条件的行
                                    Dim Result As DialogResult
                                    Result = MessageBox.Show("员工证件重复!" & vblf & "请检查是否已输入该员工!" & vblf & "员工姓名: "  & gSf0 & "性别: " & gSf2 & vblf & "公民身份号码: " & gSf1 & vblf & "住 址:" & gSf3 , "提示", MessageBoxButtons.ok, MessageBoxIcon.Question)
                                    If Result = DialogResult.ok Then
                                        r("员工姓名") = Nothing
                                        r("证件号码") = Nothing
                                        r("性别") = Nothing
                                        r("原籍地址") = Nothing
                                    End If
                                Else
                                    r("员工姓名") = jo("words_result")("姓名")("words").ToString
                                    r("证件号码") = jo("words_result")("公民身份号码")("words").ToString
                                    r("性别") = jo("words_result")("性别")("words").ToString
                                    r("原籍地址") = jo("words_result")("住址")("words").ToString
                                    r("是否为持卡人") = True
                                    If DataTables("员工信息_员工信息").HasChanges Then
                                        DataTables("员工信息_员工信息").Save
                                    End If
                                    '----------------------------------上传身份证正反面------------------------------------------------------
                                    Dim ftp1 As New FtpClient
                                    ftp1.Host=Tables("FTPIP").Current("FTPhost")
                                    ftp1.Account = Tables("FTPIP").Current("FTPAccount")
                                    ftp1.Password = Tables("FTPIP").Current("FTPpassword")
                                    Dim l As String = "/身份证/"& r("证件号码") + r("员工姓名")
                                    Dim sf As String =  r("证件图1")
                                    If  ftp1.DirExists(l)  Then
                                        Messagebox.Show("服务器文件目录已经存在!","提示")
                                        If FileSys.FileExists(File) Then
                                            If  ftp1.Upload(File,sf) = True Then
                                                Messagebox.show("" &r("员工姓名")&" 身份证正面上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                            Else
                                                Messagebox.show("" &r("员工姓名")&" 身份证正面上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                            End If
                                        Else
                                            Messagebox.show("没有找到 " &r("员工姓名")&" 的身份证(正面)图片!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                        End If
                                    Else
                                        If ftp1.MakeDir(l) Then
                                            Messagebox.Show("创建目录成功!")
                                            If FileSys.FileExists(File) Then
                                                If  ftp1.Upload(File,sf) = True Then
                                                    Messagebox.show("" &r("员工姓名")&" 身份证正面上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                                Else
                                                    Messagebox.show("" &r("员工姓名")&" 身份证正面上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                                End If
                                            Else
                                                Messagebox.show("没有找到 " &r("员工姓名")&" 的身份证(正面)图片!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                            End If
                                            'Else
                                            Messagebox.Show("创建目录失败,请联系管理员!")
                                        End If
                                    End If
                                End If
                                If File.EndsWith("2.jpg") Or File.EndsWith("2.JPG") Then '如果文件后缀名为"2.jpg"或者"2.JPG"为真
                                    Output.Show(File)
                                    Dim ftp1 As New FtpClient
                                    ftp1.Host=Tables("FTPIP").Current("FTPhost")
                                    ftp1.Account = Tables("FTPIP").Current("FTPAccount")
                                    ftp1.Password = Tables("FTPIP").Current("FTPpassword")
                                    Dim l As String = "/身份证/"& r("证件号码") + r("员工姓名")
                                    Dim sf1 As String = r("证件图2")
                                    If  ftp1.DirExists(l)  Then
                                        If FileSys.FileExists(File) Then
                                            If  ftp1.Upload(File,sf1) = True Then
                                                Messagebox.show("" &r("员工姓名")&" 身份证反面上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                            Else
                                                Messagebox.show("" &r("员工姓名")&" 身份证反面上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                            End If
                                        Else
                                            Messagebox.show("没有找到 " &r("员工姓名")&" 的身份证(反面)图片!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                        End If
                                    Else
                                        If ftp1.MakeDir(l) Then
                                            Messagebox.Show("创建目录成功!")
                                            If FileSys.FileExists(File) Then
                                                If  ftp1.Upload(File,sf1) = True Then
                                                    Messagebox.show("" &r("员工姓名")&" 身份证反面上传完成!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                                Else
                                                    Messagebox.show("" &r("员工姓名")&" 身份证反面上传失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                                End If
                                            Else
                                                Messagebox.show("没有找到 " &r("员工姓名")&" 的身份证(反面)图片!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information)
                                            End If
                                        Else
                                            Messagebox.Show("创建目录失败,请联系管理员!")
                                        End If
                                    End If
                                End If
                            End With
                        Else
                            Dim Result As DialogResult
                            Result = MessageBox.Show("识别位数错误,请重新识别!" & vblf & "请重新扫描证件后再次识别!" , "提示", MessageBoxButtons.ok, MessageBoxIcon.Question)
                            If Result = DialogResult.ok Then
                                r("员工姓名") = Nothing
                                r("证件号码") = Nothing
                                r("性别") = Nothing
                                r("原籍地址") = Nothing
                            End If
                        End If
                    End If
                catch ex As exception
                    txt.Visible = True
                    txt.text = txt.text & vbcrlf & "识别接口调用失败,错误描述: " &  vbcrlf & ex.message
                    txt.ForeColor = Color.Red
                End try
            End If
            Dim idx As Integer = Tables("员工信息_员工信息").position
            If idx <> 0 Then
                Tables("员工信息_员工信息").position = 0
                Tables("员工信息_员工信息").position = idx
            Else
                Tables("员工信息_员工信息").position += 1
                Tables("员工信息_员工信息").position = idx
            End If
            
        Next
    End If
Else
    Dim frm As WinForm.Form
    frm = Forms("百度AI开发接口数据配置")
    frm.Open()
End If

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107034 积分:544401 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/1/8 14:06:00 [只看该作者]

调试技巧:http://www.foxtable.com/webhelp/scr/1485.htm,看执行到哪里出错

抄代码之前先花点时间理解一下,如果看不懂,那么就发帖问一问。

几个问题
1、使用Current没有判断是否有值
2、有些属性可能会识别不到,请判断json是否有值再使用,既然别人的例子有这个判断,一般都不会是多余的
If jo("words_result")("公民身份号码") IsNot Nothing Then sbu.AppendLine( "--公民身份号码:" & jo("words_result")("公民身份号码")("words").ToString)
……
                        Dim gSf1 As String =jo("words_result")("公民身份号码")("words").ToString

3、这个判断【If File.EndsWith("2.jpg") Or File.EndsWith("2.JPG") Then】是在这个if里面的【If File.EndsWith("1.jpg") Or File.EndsWith("1.JPG") Then 】,这个判断里面的代码永远都不可能执行到。

4、至于闪退估计还是和下面的代码导致触发的其它事件执行有关
            Dim idx As Integer = Tables("员工信息_员工信息").position
            If idx <> 0 Then
                Tables("员工信息_员工信息").position = 0
                Tables("员工信息_员工信息").position = idx
            Else
                Tables("员工信息_员工信息").position += 1
                Tables("员工信息_员工信息").position = idx
            End If


 回到顶部
帅哥哟,离线,有人找我吗?
hongye
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:437 积分:2943 威望:0 精华:0 注册:2011/3/15 12:49:00
  发帖心情 Post By:2020/1/8 18:35:00 [只看该作者]

改成这样怎么还是闪退?难道还有错?

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:问题.txt



 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:107034 积分:544401 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/1/9 9:04:00 [只看该作者]

学会调试:http://www.foxtable.com/webhelp/scr/1485.htm

闪退一般是形成了死循环导致的,比如代码A触发执行代码B,代码B触发执行代码C,代码C触发执行代码A。。。。。。。。。。

把相关的代码都注释掉,减少代码测试,没有问题后,一步步添加代码测试找原因

 回到顶部