private void UploadingResults(TreeNode rootNode) { if (rootNode == null) { return; } if (!Directory.Exists((rootNode.Tag as Dictionary <string, string>)["Path"].ToString().Trim())) { return; } System.Windows.Forms.FolderBrowserDialog sOpenFileD = new System.Windows.Forms.FolderBrowserDialog(); sOpenFileD.RootFolder = Environment.SpecialFolder.Desktop; if (sOpenFileD.ShowDialog() == DialogResult.OK) { if (!sOpenFileD.SelectedPath.ToLower().EndsWith("gdb")) { MessageBox.Show("请选择gdb数据库文件夹", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } string strPathName = sOpenFileD.SelectedPath; string strDirtoryName = strPathName.Substring(strPathName.LastIndexOf("\\") + 1); Dictionary <string, string> pDic = new Dictionary <string, string>(); if (Directory.Exists(strPathName.ToString())) { string strPath = (rootNode.Tag as Dictionary <string, string>)["Path"].ToString().Trim() + "\\" + strDirtoryName; if (!ModStringpro.IsSameTreeNode(rootNode, strDirtoryName, strPath)) { SysCommon.CProgress vProgress = new SysCommon.CProgress(); vProgress.ShowDescription = true; vProgress.ShowProgressNumber = true; vProgress.TopMost = true; vProgress.EnableCancel = true; vProgress.EnableUserCancel(true); vProgress.ShowProgress(); Application.DoEvents(); vProgress.SetProgress("正在上传GDB数据....."); try { ModStringpro.CopyDirectory(strPathName, (rootNode.Tag as Dictionary <string, string>)["Path"].ToString(), vProgress); vProgress.Close(); } catch { pDic.Add(strDirtoryName, "文件上传失败"); vProgress.Close(); return; } DirectoryInfo fi = new DirectoryInfo(strPath); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } TreeNode ResultsNode = new TreeNode(strDirtoryName); //创建文件类型新节点 Dictionary <string, string> pDicTag = new Dictionary <string, string>(); pDicTag.Add("Path", strPath); pDicTag.Add("Type", "GDB"); ResultsNode.Tag = pDicTag; ResultsNode.ImageKey = "PDB"; ResultsNode.SelectedImageKey = "PDB"; rootNode.Nodes.Add(ResultsNode); rootNode.Expand(); pDic.Add(strDirtoryName, "数据上传成功"); } else { pDic.Add(strDirtoryName, "目录中已经存在"); } } frmUploadingList pfrmUploadingList = new frmUploadingList(pDic); pfrmUploadingList.ShowDialog(); } }
/// <summary> /// 清空指定的文件夹,但不删除文件夹 /// </summary> /// <param name="dir"></param> private bool CopyResults(string dir, string strCopyPath, string strTpye) { switch (strTpye) { case "File": if (File.Exists(dir)) { FileInfo fi = new FileInfo(dir); if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1) { fi.Attributes = FileAttributes.Normal; } try { fi.CopyTo(strCopyPath + "\\" + fi.Name, true); } catch { return(false); } } else { return(false); } break; case "Folder": if (Directory.Exists(dir)) { SysCommon.CProgress vProgress = new SysCommon.CProgress(); vProgress.ShowDescription = true; vProgress.ShowProgressNumber = true; vProgress.TopMost = true; vProgress.EnableCancel = true; vProgress.EnableUserCancel(true); vProgress.ShowProgress(); Application.DoEvents(); vProgress.SetProgress("正在导出目录....."); string flag = ModStringpro.CopyFolder(dir, strCopyPath, vProgress); vProgress.Close(); if (flag != "success") { return(false); } } else { return(false); } break; case "GDB": if (Directory.Exists(dir)) { SysCommon.CProgress vProgress = new SysCommon.CProgress(); vProgress.ShowDescription = true; vProgress.ShowProgressNumber = true; vProgress.TopMost = true; vProgress.EnableCancel = true; vProgress.EnableUserCancel(true); vProgress.ShowProgress(); Application.DoEvents(); vProgress.SetProgress("正在导出GDB数据....."); try { ModStringpro.CopyDirectory(dir, strCopyPath, vProgress); vProgress.Close(); } catch { vProgress.Close(); return(false); } } else { return(false); } break; } return(true); }