Dim tb As Table = Tables("文件管理_Table1")
Dim rdid, pid, ri As Integer
Dim sfl As String
rdid = tb.Current("did")
pid = tb.Current("childid")
sfl = tb.Current("分类")
Dim dlg As New FolderBrowserDialog
dlg.ShowNewFolderButton = True
If dlg.ShowDialog = DialogResult.Ok Then
Syscmd.GridTree.AddChild()
Dim mr As Row = tb.Current
mr.DataRow.Save
mr("扩展名") = "文件夹"
Dim dds() As String = dlg.SelectedPath.Split ("\")
Dim dd As String = dds(dds.Length - 1)
mr("文件名") = dd
mr("分类") = sfl
mr("childid") = mr("_Identify")
mr("did") = rdid
mr("parentid") = pid
mr ("单位") = Tables("one").rows(0)("单位")
mr ("操作员") = Tables("one").rows(0)("操作员")
Dim si As String
Dim ii As Integer
For Each fl As String In FileSys.GetFiles(dlg.SelectedPath)
ii = ii + 1
Syscmd.GridTree.AddSlibing()
Dim r As Row = tb.Current
r.DataRow.Save
r("parentid") = mr("childid")
r("childid") = r("_Identify")
r("did") = rdid
Dim ifo As New FileInfo(fl)
Dim ss() As String = ifo.Name.Split(".")
Dim ffd As DataRow = tb.DataTable.SQLFind ("文件名='" & ss(ss.Length - 2) & "' and 扩展名='." & ss(ss.Length - 1) & "'and parentid=" & pid)
If ffd IsNot Nothing Then '如果找到的话
MessageBox.Show(ss(ss.Length - 2) & "." & ss(ss.Length - 1) & " 该文件名已经存在")
r.Delete
tb.DataTable.Save
Return
End If
r("分类") = sfl
r("文件名") = ss(ss.Length - 2)
r("扩展名") = ifo.Extension
Dim i As Integer = ifo.Length
If i < 1024 Then
si = i & " B"
ElseIf 1048576 > i AndAlso i >= 1024 Then
si = round2(i / 1024, 2) & " KB"
ElseIf 1073741824 > i AndAlso i >= 1048576 Then
si = round2(i / 1024 / 1024, 2) & " MB"
ElseIf 1099511627776 > i AndAlso i >= 1073741824 Then
si = round2(i / 1024 / 1024 / 1024, 2) & " GB"
End If
r("大小") = si
r ("单位") = Tables("one").rows(0)("单位")
r ("操作员") = Tables("one").rows(0)("操作员")
ShowWaitDialog(New Operation(Function() As Boolean '等待开始
r.DataRow.SQLInsertFile("fl", fl) '插入文件
End Function), Nothing) '等待结束'
Next
MessageBox.Show ("已成功上传 " & ii & " 个文件")
tb.DataTable.Save
End If