Exemplo n.º 1
0
        public override void OnClick()
        {
            if (m_Hook.DataInfoGrid.Rows.Count <= 0)
            {
                return;
            }
            FolderBrowserDialog GetFileInfo = new FolderBrowserDialog();

            if (GetFileInfo.ShowDialog() == DialogResult.OK)
            {
                //System.IO.FileInfo fileinfo = new System.IO.FileInfo(GetFileInfo.FileName);
                string FileSavePath = GetFileInfo.SelectedPath;
                FileSavePath = FileSavePath.Replace("\\", "/");//文件保存路径

                //string FileSaveName = fileinfo.Name;           //文件保存名

                string serverStr = ""; //服务器
                string user      = ""; //用户
                string password  = ""; //密码

                #region 通过树节点获取IP地址
                DevComponents.AdvTree.Node DBNode = null;
                string treeNodeType = m_Hook.ProjectTree.SelectedNode.DataKey.ToString();
                if (treeNodeType == "")
                {
                    return;
                }
                DBNode = m_Hook.ProjectTree.SelectedNode;//数据库节点,根节点
                while (DBNode.Parent != null)
                {
                    DBNode = DBNode.Parent;
                }

                if (DBNode == null)
                {
                    return;
                }
                if (DBNode.DataKey.ToString() != EnumTreeNodeType.DATABASE.ToString())
                {
                    return;
                }
                if (DBNode.Name != "文件连接")
                {
                    return;
                }
                XmlElement connElem = DBNode.Tag as XmlElement;
                if (connElem == null)
                {
                    return;
                }
                serverStr = connElem.GetAttribute("服务器");
                user      = connElem.GetAttribute("用户");
                password  = connElem.GetAttribute("密码");

                if (serverStr == "" || user == "" || password == "")
                {
                    return;
                }
                //string conStr = connElem.GetAttribute("MetaDBConn");//元数据库连接信息
                #endregion

                for (int i = 0; i < m_Hook.DataInfoGrid.RowCount; i++)
                {
                    if (false == m_Hook.DataInfoGrid.Rows[i].Selected)
                    {
                        continue;
                    }
                    string fileName = "";   //文件名
                    string filePath = "";   //文件FTP路径
                    fileName = m_Hook.DataInfoGrid.Rows[i].Cells["数据文件名"].FormattedValue.ToString().Trim();
                    filePath = m_Hook.DataInfoGrid.Rows[i].Cells["存储位置"].FormattedValue.ToString().Trim();
                    if (fileName == "" || filePath == "")
                    {
                        return;
                    }

                    string error = "";
                    //执行下载数据
                    FTP_Class clsFtp   = new FTP_Class(serverStr, user, password);
                    string[]  fNameArr = clsFtp.GetFileList(filePath, out error);
                    if (error != "Succeed")
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取文件列表失败!");
                        return;
                    }
                    if (fNameArr == null)
                    {
                        //控制点数据导出,特殊处理
                        continue;
                    }
                    else
                    {
                        #region 其他数据下载
                        for (int j = 0; j < fNameArr.Length; j++)
                        {
                            string ttName = fNameArr[j];
                            if (ttName.Contains(fileName.Substring(0, fileName.LastIndexOf('.'))))
                            {
                                if (File.Exists(FileSavePath + "/" + ttName))
                                {
                                    if (SysCommon.Error.ErrorHandle.ShowFrmInformation("确定", "取消", "存在同名文件,是否替换?"))
                                    {
                                        File.Delete(FileSavePath + "/" + ttName);
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                                bool state = ModDBOperator.DownloadFile(serverStr, user, password, filePath, ttName, ttName, FileSavePath, out error);
                                if (!state)
                                {
                                    SysCommon.Error.frmInformation eerorFrm = new SysCommon.Error.frmInformation("是", "否", "数据文件\n'" + filePath + "\\" + ttName + "'\n下载失败。原因为:\n" + error + "!\n是否继续下载?");
                                    eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                                    if (eerorFrm.ShowDialog() == DialogResult.OK)
                                    {
                                        continue;
                                    }
                                    else
                                    {
                                        return;
                                    }
                                }
                            }
                        }
                        #endregion
                    }
                }
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "下载完成!");
            }
        }
Exemplo n.º 2
0
        public override void OnClick()
        {
            FolderBrowserDialog GetFileInfo = new FolderBrowserDialog();

            if (GetFileInfo.ShowDialog() == DialogResult.OK)
            {
                //System.IO.FileInfo fileinfo = new System.IO.FileInfo(GetFileInfo.FileName);
                //string FileSavePath = fileinfo.DirectoryName;
                string FileSavePath = GetFileInfo.SelectedPath;
                FileSavePath = FileSavePath.Replace("\\", "/"); //文件保存路径

                string serverStr = "";                          //服务器
                string user      = "";                          //用户
                string password  = "";                          //密码
                string fileName  = "";                          //文件名
                string filePath  = "";                          //文件FTP路径

                DevComponents.AdvTree.Node DBNode = null;       //数据库节点
                string treeNodeType = m_Hook.ProjectTree.SelectedNode.DataKey.ToString();
                if (m_Hook.ProjectTree.SelectedNode.Name == "")
                {
                    return;
                }
                filePath = m_Hook.ProjectTree.SelectedNode.Name;  //数据文件存储路径
                if (m_Hook.ProjectTree.SelectedNode.Text == "")
                {
                    return;
                }
                fileName = m_Hook.ProjectTree.SelectedNode.Text;    //数据文件名
                if (m_Hook.ProjectTree.SelectedNode.Tag == null)
                {
                    return;
                }

                //if (File.Exists(FileSavePath + "/" + fileName))
                //{
                //    if (SysCommon.Error.ErrorHandle.ShowFrmInformation("确定", "取消", "存在同名文件,是否替换?"))
                //    {
                //        File.Delete(FileSavePath + "/" + fileName);
                //    }
                //    else
                //        return;
                //}
                //获得FTP地址
                DBNode = m_Hook.ProjectTree.SelectedNode;//数据库节点,根节点
                while (DBNode.Parent != null)
                {
                    DBNode = DBNode.Parent;
                }
                if (DBNode == null)
                {
                    return;
                }
                if (DBNode.DataKey.ToString() != EnumTreeNodeType.DATABASE.ToString())
                {
                    return;
                }
                if (DBNode.Name != "文件连接")
                {
                    return;
                }
                XmlElement connElem = DBNode.Tag as XmlElement;
                if (connElem == null)
                {
                    return;
                }
                serverStr = connElem.GetAttribute("服务器");
                user      = connElem.GetAttribute("用户");
                password  = connElem.GetAttribute("密码");

                if (serverStr == "" || user == "" || password == "")
                {
                    return;
                }
                string    error    = "";
                FTP_Class clsFtp   = new FTP_Class(serverStr, user, password);
                string[]  fNameArr = clsFtp.GetFileList(filePath, out error);
                if (error != "Succeed")
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "获取文件列表失败!");
                    return;
                }
                for (int j = 0; j < fNameArr.Length; j++)
                {
                    string ttName = fNameArr[j];
                    if (ttName.Contains(fileName.Substring(0, fileName.LastIndexOf('.'))))
                    {
                        if (File.Exists(FileSavePath + "/" + ttName))
                        {
                            if (SysCommon.Error.ErrorHandle.ShowFrmInformation("确定", "取消", "存在同名文件,是否替换?"))
                            {
                                File.Delete(FileSavePath + "/" + ttName);
                            }
                            else
                            {
                                return;
                            }
                        }
                        bool state = ModDBOperator.DownloadFile(serverStr, user, password, filePath, ttName, ttName, FileSavePath, out error);
                        if (!state)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "下载数据失败,数据文件为:\n'" + filePath + "\\" + ttName + "'");
                            return;
                        }
                    }
                }
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "下载完成!");
            }
        }