-- 作者:ajie5211
-- 发布时间:2019/2/26 8:05:00
--
执行代码:
Dim dr As DataRow = DataTables("文件存储窗口_Table4").DataRows(0) Dim html As String = _UserFtID & _UserName Dim htmldr As DataRow htmldr = DataTables("目录表").SQLFind("目录名 = \'" & html & "\' and 一级目录 = \'个人文件\' and 二级目录 is null") Dim htmlid As Integer = htmldr("_Identify") Functions.AsyncExecute("T同步工作文件夹",dr("工作目录"),"/个人文件/" & html,htmlid)
自定义函数“T同步工作文件夹”代码
Dim ml As String = Args(0) \'要同步的本地工作目录 Dim htlj As String = Args(1) \'Ftp文件夹路径 Dim htmlid As Integer = Args(2) \'后台目录ID \'生成本地文件信息表和后台文件信息表 Dim cmd As new SQLCommand Dim htwjdt As DataTable cmd.C cmd.CommandText = "select * fr om {文件表} where [_Identify] is null" htwjdt = cmd.ExecuteReader(True) \'记得将参数设置为True
Dim bdwjdt As DataTable Dim cmd1 As new SQLCommand cmd1.C cmd1.CommandText = "select * fro m {本机文件表} where [_Identify] is null" bdwjdt = cmd1.ExecuteReader(True) \'记得将参数设置为True
Dim mldr As DataRow mldr = DataTables("文件存储窗口_Table4").Find("硬盘ID = \'" & harddiskid & "\'") If mldr Is Nothing Then Return Nothing End If Dim html As String = _UserFtID & _UserName DataTables("目录表").LoadFilter = "父目录ID = " & htmlid & " and 一级目录 = \'个人文件\' and 二级目录 = \'" & html & "\' and 三级目录 is null" DataTables("目录表").Load(False) htwjdt.LoadFilter = "父目录ID = " & htmlid \'加载ftp文件信息 htwjdt.Load() bdwjdt.LoadFilter = "父目录ID = " & htmlid \'加载本地文件信息 bdwjdt.Load() Dim mlwjs As new List(of String) For Each File As String In FileSys.GetFiles(ml) \'得到本地当前目录所有文件名,不含路径 If mlwjs.Contains(FileSys.GetName(file)) = False Then mlwjs.Add(FileSys.GetName(file)) End If Next \'更新文件 For Each File As String In FileSys.GetFiles(ml) Dim ifo As new FileInfo(file) Dim htwjdr As DataRow = htwjdt.Find("文件名 + 后辍 = \'" & ifo.Name & "\'") Dim bdwjdr As DataRow Dim wjm As String = ifo.Name.Remove(Ifo.Name.Length - ifo.Extension.Length) If htwjdr Is Nothing Then Functions.Execute("T同步上传或更新文件",wjm,Ifo.Extension,htlj & "/" & Ifo.Name,file,htwjdt,htwjdr,bdwjdt,bdwjdr,htmlid,mldr("_Identify")) Else bdwjdr = bdwjdt.Find("文件ID = " & htwjdr("_Identify") & " and 硬盘行ID = " & mldr("_Identify")) If bdwjdr IsNot Nothing Then If format(ifo.LastWriteTime,"yyyy-MM-dd HH:mm:ss") > bdwjdr("本机修改时间") Then Functions.Execute("T同步上传或更新文件",wjm,Ifo.Extension,htlj & "/" & Ifo.Name,file,htwjdt,htwjdr,bdwjdt,bdwjdr,htmlid,mldr("_Identify")) End If End If End If Next \'下载新文件 For Each htdr As DataRow In htwjdt.DataRows If mlwjs.Contains(htdr("文件名") & htdr("后辍")) = False Then Dim xzpd As Boolean xzpd = Functions.Execute("ftp下载文件",htlj & htdr("文件名") & htdr("后辍"),ml & "\\" & htdr("文件名") & htdr("后辍")) If xzpd = True Then Dim bdwjdr As DataRow = bdwjdt.AddNew() bdwjdr("硬盘行ID") = mldr("_Identify") bdwjdr("文件ID") = htdr("_Identify") bdwjdr("父目录ID") = htdr("父目录ID") bdwjdr("本机修改时间") = htdr("修改时间") End If End If Next bdwjdt.Save() \'遍历同步文件夹下的目录 Dim htmls As new List(of String()) \'后台同步目录下的所有子目录 htmls = DataTables("目录表").GetValues("_Identify|目录名") Dim html1s As new List(of String) \'后台同步目录下的子目录无目录ID html1s = DataTables("目录表").GetValues("目录名") Dim bdmls As new List(of String) \'文件夹下的所有目录 For Each dir As String In FileSys.GetDirectories(ml) \'得到文件夹下的所有目录,同时新增ftp目录并同步 Dim mlname As String = dir.SubString(ml.Length + 1) If bdmls.Contains(mlname) = False Then bdmls.Add(mlname) End If If html1s.Contains(mlname) = False Then Dim xid As Integer xid = Functions.Execute("ftp创建文件夹",mlname,htmlid,"个人文件\\" & html) Functions.Execute("T同步工作文件夹",dir,htlj & "/" & mlname,xid) Else For Each hml As String() In htmls If hml(1) = mlname Then Functions.Execute("T同步工作文件夹",dir,htlj & "/" & mlname,hml(0)) End If Next End If Next \'新增本地目录并下载 For Each hml As String() In htmls If bdmls.Contains(hml(1)) = False Then Dim hxlm As String = ml & "\\" & hml(1) Dim xhtlj As String = htlj & hml(1) & "/" Functions.Execute("T同步下载新文件夹",hml(0),hml(1),hxlm,htwjdt,xhtlj,html,bdwjdt,mldr("_Identify")) End If Next bdwjdt.Save()
|
-- 作者:ajie5211
-- 发布时间:2019/2/26 8:06:00
--
自定义函数“T同步上传或更新文件”代码如下:
Dim wjm As String = args(0) \'文件名 Dim hzm As String = args(1) \'后辍名 Dim ftplj As String = args(2) \'ftp路径含文件名 Dim bdlj As String = args(3) \'本地上传文件路径含文件名 Dim htwjdt As DataTable = args(4) \'后台文件表 Dim htwjdr As DataRow = args(5) \'后台文件行 Dim bdwjdt As DataTable = args(6) \'本地文件表 Dim bdwjdr As DataRow = args(7) \'本地文件行 Dim fid As Integer = args(8) \'父目录ID Dim yphid As Integer = args(9) \'硬盘行ID \'计算文件的修改时间 Dim ifo As new FileInfo(bdlj) \'****ftp中创建文件夹**** Dim dr1 As DataRow dr1 = DataTables("通讯设置").SQLFind("类型 = \'ftp\'") Dim ftp1 As New FtpClient ftp1.Host = dr1("IP") ftp1.Port = dr1("端品") ftp1.Account = dr1("帐号") ftp1.Password = DecryptText(dr1("密码"),"111","111") ftp1.UTF8 = True If ftp1.Connected = False \'如果FTP没有连接 If ftp1.Connect = False Then Messagebox.show("连接FTP失败!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information) Return Nothing End If End If If htwjdr Is Nothing Then If ftp1.Upload(bdlj,ftplj) = True Then \'生成本地文件信息表和后台文件信息表 htwjdr = htwjdt.AddNew() bdwjdr = bdwjdt.AddNew() htwjdr("文件名") = wjm htwjdr("后辍") = hzm htwjdr("父目录ID") = fid htwjdr("上传人员ID") = _OperID htwjdr("版本") = 0 htwjdr("是否最新版") = True htwjdr("修改时间") = format(ifo.LastWriteTime,"yyyy-MM-dd HH:mm:ss") htwjdt.Save() MessageBox.Show(htwjdr("_Identify")) bdwjdr("硬盘行ID") = yphid bdwjdr("文件ID") = htwjdr("_Identify") bdwjdr("父目录ID") = fid bdwjdr("本机修改时间") = format(ifo.LastWriteTime,"yyyy-MM-dd HH:mm:ss") bdwjdt.Save() End If Else Dim s As Date s = Functions.Execute("系统时间") If s > #1/1/1999# Then Dim sj As String = Format(s,"yyyyMdHms") sj = wjm & sj & hzm If ftp1.Rename(ftplj,"/旧版文件/" & sj) Then htwjdr("对应文件名") = htwjdr("文件名") htwjdr("对应文件父目录ID") = htwjdr("父目录ID") htwjdr("是否最新版") = False htwjdr("文件名") = htwjdr("文件名") & sj htwjdr("父目录ID") = Nothing htwjdt.Save() Dim tj As String = "对应文件名 = \'" & wjm & "\' and 后辍 = \'" & hzm & "\' and 对应文件父目录ID = " & fid & "and 版本 + 5 < " & htwjdr("版本") htwjdt.SQLDeleteFor(tj & " And 修改时间 < #" & ifo.LastWriteTime.AddDays(-7) & "#") If ftp1.Upload(bdlj,ftplj) = True Then If bdwjdr Is Nothing Then bdwjdr = bdwjdt.AddNew() End If Dim dr As DataRow = htwjdt.AddNew() dr("文件名") = wjm dr("后辍") = hzm dr("父目录ID") = fid dr("上传人员ID") = _OperID dr("版本") = htwjdr("版本") + 1 dr("是否最新版") = True dr("修改时间") = format(ifo.LastWriteTime,"yyyy-MM-dd HH:mm:ss") bdwjdt.Save() bdwjdr("硬盘行ID") = yphid bdwjdr("文件ID") = dr("_Identify") bdwjdr("父目录ID") = fid bdwjdr("本机修改时间") = format(ifo.LastWriteTime,"yyyy-MM-dd HH:mm:ss") bdwjdt.Save() End If End If End If End If ftp1.Close()
|
-- 作者:ajie5211
-- 发布时间:2019/2/26 8:11:00
--
窗口中AfterSelectNode代码如下
Dim jds As new List(of String()) Dim djds As new List(of String) Dim ycjds As new List(of String) Dim pd1 As Boolean = False Dim dbm As String For Each db As Integer In _UserDeptIDs dbm = db & "," & dbm Next dbm = dbm & "-1" Dim bmjs As String For Each db As String In _UserRGroups bmjs = "\'" & db.Replace(".","") & "\'," & bmjs Next bmjs = bmjs.TrimEnd(",") DataTables("文件夹权限").LoadFilter = "(操作类型 = 1 and 部门ID in (" & dbm & ") and 角色ID in (-1,0)) or ((val(部门ID) + val(角色ID)) In (" & bmjs & ") And 操作类型 = 1)" DataTables("文件夹权限").Load(False) Dim qnc As String = e.Node.FullName \'全名称 Dim nc() As String = qnc.Split("\\") \'选择节点名称数组 Dim qlj As String = e.Node.FullPath \'全标题 Dim lj() As String = qlj.Split("\\") \'选择节点标题数组 Dim csfilter As String If e.Node.Level = 0 Then If e.Node.Name = "项目文件" Then Dim xmdr As DataRow xmdr = DataTables("文件夹权限").Find("文件夹名 = \'项目文件\'") If xmdr Is Nothing Then \'不能读取项目文件夹时,不增加节点 Return End If jds = DataTables("目录表").SQLGetValues("_Identify|目录名","一级目录 = \'项目文件\' and 二级目录 is null") Else If e.Node.Name = "部门文件" Then csfilter = "select 文件夹名 fro m {文件夹权限} where (文件类型 = 2 and 操作类型 = 1 And 部门ID In (" & dbm & ") And 角色ID In (-1,0))" csfilter = csfilter & " Or ((val(部门ID) + val(角色ID)) In (" & bmjs & ") And 操作类型 = 1 and 文件类型 = 2)" csfilter = "目录名 in (" & csfilter & ") and 一级目录 = \'部门文件\' and 二级目录 is null and 三级目录 is null and 父目录ID is null" jds = DataTables("目录表").SQLGetValues("_Identify|目录名",csfilter) Else If e.Node.Name = "个人文件" Then csfilter = "select 文件夹名 fro m {文件夹权限} where (文件类型 = 3 and 操作类型 = 1 And 部门ID In (" & dbm & ") And 角色ID In (-1,0))" csfilter = csfilter & " Or ((val(部门ID) + val(角色ID)) In (" & bmjs & ") And 操作类型 = 1 and 文件类型 = 3)" csfilter = "目录名 in (" & csfilter & ") and 一级目录 = \'个人文件\' and 二级目录 is null and 三级目录 is null and 父目录ID is null" jds = DataTables("目录表").SQLGetValues("_Identify|目录名",csfilter) End If Else If e.Node.Level = 1 Then If e.Node.ParentNode.Name = "项目文件" Then djds = DataTables("文件夹权限").GetValues("文件夹名","文件类型 = 1 and 文件夹名 <> \'项目文件\' and 操作类型 = 1") csfilter = "select 文件夹名 fr om {文件夹权限} where (文件类型 = 1 and 文件夹名 <> \'项目文件\' and 操作类型 = 1 And 部门ID In (" & dbm & ") And 角色ID In (-1,0))" csfilter = csfilter & " Or ((val(部门ID) + val(角色ID)) In (" & bmjs & ") And 操作类型 = 1 and 文件类型 = 1 and 文件夹名 <> \'项目文件\')" csfilter = "目录名 in (" & csfilter & ") and 一级目录 = \'项目文件\' and 二级目录 = \'" & lj(1) & "\' and 三级目录 is null and 父目录ID is null" jds = DataTables("目录表").SQLGetValues("_Identify|目录名",csfilter) Else csfilter = "一级目录 = \'" & lj(0) & "\' and 二级目录 = \'" & lj(1) & "\' and 三级目录 Is null and 父目录ID = " & CInt(e.Node.Name) jds = DataTables("目录表").SQLGetValues("_Identify|目录名",csfilter) End If Else Dim fcc As String If nc(0) = "项目文件" Then fcc = "一级目录 = \'" & lj(0) & "\' and 二级目录 = \'" & lj(1) & "\' and 三级目录 = \'" & lj(2) & "\' and 父目录ID = " & CInt(e.Node.Name) fcc = fcc & " and [_Identify] <> " & CInt(e.Node.Name) Else fcc = "一级目录 = \'" & lj(0) & "\' and 二级目录 = \'" & lj(1) & "\' and 三级目录 Is null and 父目录ID = " & CInt(e.Node.Name) & " and [_Identify] <> " & CInt(e.Node.Name) End If jds = DataTables("目录表").SQLGetValues("_Identify|目录名",fcc) End If For Each yc As WinForm.TreeNode In e.Node.Nodes \'查找被移除的节点 Dim jdz() As String = {yc.Name,yc.Text} If jds.Contains(jdz) = False Then If ycjds.Contains(yc.Name) = False Then ycjds.Add(yc.Name) End If End If Next For Each ycjd As String In ycjds \'移除节点 e.Node.Nodes.Remove(e.Node.Nodes(ycjd)) Next For Each jd As String() In jds \'增加新节点 If e.Node.Nodes.Contains(jd(0)) = False Then e.Node.Nodes.Add(jd(0),jd(1)) End If Next \'展开节点 If e.Node.ParentNode IsNot Nothing Then For Each yc As WinForm.TreeNode In e.Node.ParentNode.Nodes If yc.IsSelected = True Then yc.Expand() Else yc.Collapse() End If Next Else For Each yc As WinForm.TreeNode In e.Sender.Nodes If yc.IsSelected = True Then yc.Expand() Else yc.Collapse() End If Next End If \'加载文件数据表 If e.Node.Level > 0 Then DataTables("文件表").LoadFilter = "父目录ID = " & CInt(e.Node.Name) DataTables("文件表").Load() Else DataTables("文件表").LoadFilter = "[_Identify] is null" DataTables("文件表").Load() End If
|