以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  关于预览图片问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=154312)

--  作者:裴保民
--  发布时间:2020/9/10 18:04:00
--  关于预览图片问题

在 TimerTick 事件中写了如下代码,运行后假如数据行没有图片时会报错,怎么处理


Dim wjjmc As String
Dim t As  Table = Tables("充值凭证表")
wjjmc =Format(T.Current("充值日期"),"yyy年MM月dd日") & "【" & T.Current("起始号") & "至" & T.Current("终止号") & "】"
Dim dlg As New FolderBrowserDialog
Dim czkh As DataRow
Dim shID As String = e.Form.Controls("czpzIDTextBox").value
Dim dr1 As DataRow = DataTables("充值凭证表").Find("充值凭证ID= \'" & shID & "\'" )
Dim str As String = dr1("充值凭证原始名称")
For Each file As String In FileSys.GetFiles(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" )
    Dim name As String = FileSys.GetName(file)
    If name.Contains(str) Then
        Dim ls = dr1.Lines("充值凭证")
        If ls.contains(name) = False Then
            ls.add(name)
            dr1.lines("充值凭证") = ls
            DataTables("充值凭证表").Save
        End If
    End If
Next
DataTables("充值凭证表").DataCols("充值凭证").DefaultFolder =ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\"




图片点击可在新窗口打开查看此主题相关图片如下:截图08.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:截图09.jpg
图片点击可在新窗口打开查看

[此贴子已经被作者于2020/9/10 19:39:24编辑过]

--  作者:有点蓝
--  发布时间:2020/9/10 20:21:00
--  
……
Dim dr1 As DataRow = DataTables("充值凭证表").Find("充值凭证ID= \'" & shID & "\'" )
Dim str As String = dr1("充值凭证原始名称")
dim lst as list(of string)
if dr1.isnull("充值凭证") then
lst = new list(of string)
else
lst =dr1.Lines("充值凭证")
end if
For Each file As String In FileSys.GetFiles(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" )
    Dim name As String = FileSys.GetName(file)
    If name.Contains(str) andalso lst.contains(name) = False  Then
        lst.add(name)
    End If
Next
dr1.lines("充值凭证") = lst
DataTables("充值凭证表").Save
……

--  作者:裴保民
--  发布时间:2020/9/10 21:01:00
--  
蓝老师照您修改后还是错误

图片点击可在新窗口打开查看此主题相关图片如下:截图10.jpg
图片点击可在新窗口打开查看

图片点击可在新窗口打开查看此主题相关图片如下:截图11.jpg
图片点击可在新窗口打开查看

代码如下

Dim wjjmc As String
Dim t As  Table = Tables("充值凭证表")
wjjmc =Format(T.Current("充值日期"),"yyy年MM月dd日") & "【" & T.Current("起始号") & "至" & T.Current("终止号") & "】"
Dim dlg As New FolderBrowserDialog
Dim czkh As DataRow
Dim shID As String = e.Form.Controls("czpzIDTextBox").value
Dim dr1 As DataRow = DataTables("充值凭证表").Find("充值凭证ID= \'" & shID & "\'" )
Dim str As String = dr1("充值凭证原始名称")
Dim lst As List(of String)
If dr1.isnull("充值凭证") Then
lst = new List(of String)
Else
lst =dr1.Lines("充值凭证")
End If
For Each file As String In FileSys.GetFiles(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" )
    Dim name As String = FileSys.GetName(file)
If name.Contains(str) AndAlso lst.contains(name) = False  Then
        lst.add(name)
    End If
Next
dr1.lines("充值凭证") = lst
DataTables("充值凭证表").Save
DataTables("充值凭证表").DataCols("充值凭证").DefaultFolder =ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\"
[此贴子已经被作者于2020/9/10 21:12:50编辑过]

--  作者:有点蓝
--  发布时间:2020/9/10 21:45:00
--  
提示的路径不存在
--  作者:裴保民
--  发布时间:2020/9/10 21:52:00
--  
蓝老师是没照片,没照片这个文件夹肯定也不存在的,如果有照片行没事,只要某一行无照片就会出现错误,并且关闭了程序出现死循环
[此贴子已经被作者于2020/9/10 21:54:44编辑过]

--  作者:有点蓝
--  发布时间:2020/9/10 21:55:00
--  
路径不存在,先判断一下http://www.foxtable.com/webhelp/topics/0334.htm

For Each file As String In FileSys.GetFiles(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" )

--  作者:裴保民
--  发布时间:2020/9/10 22:16:00
--  
Dim wjjmc As String
Dim t As  Table = Tables("充值凭证表")
wjjmc =Format(T.Current("充值日期"),"yyy年MM月dd日") & "【" & T.Current("起始号") & "至" & T.Current("终止号") & "】"
Dim dlg As New FolderBrowserDialog
Dim czkh As DataRow
Dim shID As String = e.Form.Controls("czpzIDTextBox").value
Dim dr1 As DataRow = DataTables("充值凭证表").Find("充值凭证ID= \'" & shID & "\'" )
Dim str As String = dr1("充值凭证原始名称")
Dim lst As List(of String)
If dr1.isnull("充值凭证") Then
    lst = new List(of String)
Else
    lst =dr1.Lines("充值凭证")
End If
If FileSys.DirectoryExists(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" ) Then \'如果目录C:\\MyFolder存在
    For Each file As String In FileSys.GetFiles(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" )
        Dim name As String = FileSys.GetName(file)
        If name.Contains(str) AndAlso lst.contains(name) = False  Then
            lst.add(name)
        End If
    Next
    dr1.lines("充值凭证") = lst
    DataTables("充值凭证表").Save
    DataTables("充值凭证表").DataCols("充值凭证").DefaultFolder =ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\"
End If


这段代码放到计时器上运行没发现错误,怎么放到CurrentChanged事件中就出现未实例化呢?

--  作者:有点蓝
--  发布时间:2020/9/10 22:26:00
--  
没有判断Current是否空值
--  作者:裴保民
--  发布时间:2020/9/11 7:37:00
--  
If Tables("充值凭证表").current("充值凭证") Is Nothing  Then
    Dim wjjmc As String
    Dim t As  Table = Tables("充值凭证表")
    wjjmc =Format(T.Current("充值日期"),"yyy年MM月dd日") & "【" & T.Current("起始号") & "至" & T.Current("终止号") & "】"
    Dim dlg As New FolderBrowserDialog
    Dim czkh As DataRow
    Dim shID As String = e.Form.Controls("czpzIDTextBox").value
    Dim dr1 As DataRow = DataTables("充值凭证表").Find("充值凭证ID= \'" & shID & "\'" )
    Dim str As String = dr1("充值凭证原始名称")
    Dim lst As List(of String)
    If dr1.isnull("充值凭证") Then
        lst = new List(of String)
    Else
        lst =dr1.Lines("充值凭证")
    End If
    If FileSys.DirectoryExists(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" ) Then \'如果目录C:\\MyFolder存在
        For Each file As String In FileSys.GetFiles(ProjectPath & "照片\\充值凭证截图\\" & wjjmc & "\\" )
            Dim name As String = FileSys.GetName(file)
            If name.Contains(str) AndAlso lst.contains(name) = False  Then
                lst.add(name)
            End If
        Next
        dr1.lines("充值凭证") = lst
        DataTables("充值凭证表").Save
        DataTables("充值凭证表").DataCols("充值凭证").DefaultFolder =ProjectPath & "照片\\值凭证截图\\" & wjjmc & "\\"
    End If
End If

启动后只能加载一条图片,其他有图片也不显示

--  作者:有点蓝
--  发布时间:2020/9/11 9:06:00
--  
http://www.foxtable.com/webhelp/topics/0445.htm

自己核对单元格的文件名称是否正确和文件是否存在