Exemplo n.º 1
0
        public override void OnClick()
        {
            SysCommon.Error.frmInformation eerorFrm = new SysCommon.Error.frmInformation("是", "否", "删除数据将无法恢复,确定吗?");
            eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
            if (eerorFrm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            //执行成果数据删除操作(在列表中选中要删除的数据项,进行删除)

            Exception ex = null;

            #region 获取连接信息
            DevComponents.AdvTree.Node mDBNode     = m_Hook.ProjectTree.SelectedNode;
            DevComponents.AdvTree.Node Deltreenode = null;
            string ipStr    = "";
            string ip       = "";
            string id       = "";
            string password = "";
            string ConnStr  = "";
            int    datatype = -1;
            SysCommon.DataBase.SysTable pSysDB = new SysCommon.DataBase.SysTable();    //属性库连接类

            while (mDBNode.Parent != null)
            {
                mDBNode = mDBNode.Parent;
            }
            if (mDBNode.Name == "文件连接")
            {
                Deltreenode = mDBNode;
                System.Xml.XmlElement dbElem = mDBNode.Tag as System.Xml.XmlElement;
                if (dbElem == null)
                {
                    return;
                }
                ipStr    = dbElem.GetAttribute("MetaDBConn");
                ip       = dbElem.GetAttribute("服务器");
                id       = dbElem.GetAttribute("用户");
                password = dbElem.GetAttribute("密码");
                //ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ipStr + ";Persist Security Info=True";//元数据连接字符串
                ConnStr = ipStr;
                pSysDB.SetDbConnection(ConnStr, SysCommon.enumDBConType.ORACLE, SysCommon.enumDBType.ORACLE, out ex);
            }
            else
            {
                return;
            }
            #endregion
            if (EnumTreeNodeType.DATAITEM.ToString() == m_Hook.ProjectTree.SelectedNode.DataKey.ToString())
            {
                #region 在树节点上选择要删除的数据
                if (m_Hook.ProjectTree.SelectedNode.Tag == null)
                {
                    return;
                }
                if (m_Hook.ProjectTree.SelectedNode.Tag.ToString() == "")
                {
                    return;
                }
                long   dataID   = int.Parse(m_Hook.ProjectTree.SelectedNode.Tag.ToString());//数据
                string DataType = m_Hook.ProjectTree.SelectedNode.Parent.Tag.ToString();;
                try
                {
                    datatype = Convert.ToInt32(DataType);
                }
                catch
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误提示!", "获取数据类型失败!");
                    return;
                }
                if (2 != datatype)////数据类型不为控制点控制点数据

                {
                    string FilePath = m_Hook.ProjectTree.SelectedNode.Name;
                    string FileName = m_Hook.ProjectTree.SelectedNode.Text.Trim();
                    bool   Delstate = ModDBOperator.DelDataItem(FilePath, FileName, ip, id, password, out ex);
                    if (!Delstate)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "文件库中删除文件:" + FilePath + "/" + FileName + "失败!" + "\n请确认文件是否存在或是否为占用状态!");
                        return;
                    }
                    m_Hook.ProjectTree.SelectedNode.Remove();
                    ModDBOperator.DelDataItem(dataID, datatype, pSysDB, out ex);
                    if (null != ex)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "元信息数据库中删除数据文件记录失败!");
                        return;
                    }
                }
                else/////数据类型为控制点数据

                {
                    ModDBOperator.DelDataItem(dataID, datatype, pSysDB, out ex);
                    if (null != ex)
                    {
                        SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "元信息数据库中删除数据文件记录失败!");
                        return;
                    }
                    m_Hook.ProjectTree.SelectedNode.Remove();
                }
                #endregion
            }
            else if (m_Hook.DataInfoGrid.Rows.Count > 0)
            {
                #region 其他所有节点
                DevComponents.AdvTree.Node Selnode = m_Hook.ProjectTree.SelectedNode;
                if (null == Selnode.DataKey)
                {
                    return;
                }
                string ID       = "";
                long   lid      = -1;
                string FileName = "";
                string FilePath = "";
                string type     = "";

                FrmProcessBar frmbar = new FrmProcessBar();
                frmbar.SetFrmProcessBarText("删除操作:");
                frmbar.Show();
                List <int> delrowlist = new List <int>();
                if (EnumTreeNodeType.PRODUCTPYPE.ToString() == Selnode.DataKey.ToString())
                {
                    #region  中的是产品类型节点(标准、非标准、控制点数据)
                    type = Selnode.Text;
                    switch (type)
                    {
                    case "标准图幅":
                        datatype = 0;
                        break;

                    case "非标准图幅":
                        datatype = 1;
                        break;

                    case "控制点数据":
                        datatype = 2;
                        break;

                    default:
                        datatype = -1;
                        break;
                    }
                    if (datatype == -1)
                    {
                        return;
                    }
                    frmbar.SetFrmProcessBarMax((long)m_Hook.DataInfoGrid.Rows.Count);
                    for (int i = 0; i < m_Hook.DataInfoGrid.Rows.Count; i++)
                    {
                        frmbar.SetFrmProcessBarValue((long)i);
                        Application.DoEvents();
                        if (false == m_Hook.DataInfoGrid.Rows[i].Selected)
                        {
                            continue;
                        }
                        try
                        {
                            ID = m_Hook.DataInfoGrid.Rows[i].Cells["ID"].FormattedValue.ToString().Trim();
                            if (string.IsNullOrEmpty(ID))
                            {
                                continue;
                            }
                            lid      = Convert.ToInt64(ID);
                            FileName = m_Hook.DataInfoGrid.Rows[i].Cells["数据文件名"].FormattedValue.ToString().Trim();
                            FilePath = m_Hook.DataInfoGrid.Rows[i].Cells["存储位置"].FormattedValue.ToString().Trim();
                        }
                        catch
                        {
                            eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "数据文件:" + FileName + "删除失败,是否继续删除?");
                            eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                            if (eerorFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                continue;
                            }
                            else
                            {
                                frmbar.Close();
                                return;
                            }
                        }

                        #region 在文件库中删除数据文件

                        //////////////////在文件库中删除数据文件////////////////////////////////
                        frmbar.SetFrmProcessBarText("正在删除文件:" + FileName);
                        Application.DoEvents();
                        if (2 != datatype)////数据类型为控制点控制点数据不执行文件的删除操作

                        {
                            bool Delstate = ModDBOperator.DelDataItem(FilePath, FileName, ip, id, password, out ex);
                            if (!Delstate)
                            {
                                eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "数据文件\n'" + FilePath + "/" + FileName + "'\n删除失败。\n" + "请确认文件是否存在或是否为占用状态" + "!\n是否继续删除?");
                                eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                                if (eerorFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    continue;
                                }
                                else
                                {
                                    frmbar.Close();
                                    return;
                                }
                            }
                        }
                        #endregion
                        #region 在元数据表中删除成果信息
                        ///////////////////在元数据表中删除成果信息/////////////////////////
                        ModDBOperator.DelDataItem(lid, datatype, pSysDB, out ex);
                        if (null != ex)
                        {
                            eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "数据文件\n'" + FileName + "'\n元信息删除失败。\n" + "请确认元信息库的连接信息。" + "!\n是否继续删除?");
                            eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                            if (eerorFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                continue;
                            }
                            else
                            {
                                frmbar.Close();
                                return;
                            }
                        }
                        // m_Hook.DataInfoGrid.Rows.Remove(m_Hook.DataInfoGrid.Rows[i]);
                        // i = i - 1;
                        delrowlist.Add(i);
                        #endregion
                        #region 在树节点中删除文件节点

                        /////////////////////在树节点中删除文件节点///////////////////////////
                        ModDBOperator.DelNodeByNameAndText(Deltreenode, FilePath, FileName, out ex);
                        if (null != ex)
                        {
                            eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "树节点删除失败。原因为:\n" + ex.Message + "!\n是否继续删除?");
                            eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                            if (eerorFrm.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                            {
                                frmbar.Close();
                                return;
                            }
                            //else
                            //    return;
                        }
                        #endregion
                    }
                    #endregion
                }
                else  //除产品类型节点以外的所有节点
                {
                    frmbar.SetFrmProcessBarMax((long)m_Hook.DataInfoGrid.Rows.Count);
                    for (int i = 0; i < m_Hook.DataInfoGrid.Rows.Count; i++)
                    {
                        #region 获取必要信息
                        if (false == m_Hook.DataInfoGrid.Rows[i].Selected)
                        {
                            continue;
                        }
                        frmbar.SetFrmProcessBarValue((long)i);
                        int DataType = -1;//产品的类型(标准,非标准,属性)
                        try
                        {
                            ID = m_Hook.DataInfoGrid.Rows[i].Cells["ID"].FormattedValue.ToString().Trim();
                            if (string.IsNullOrEmpty(ID))
                            {
                                continue;
                            }
                            lid      = Convert.ToInt64(ID);
                            FileName = m_Hook.DataInfoGrid.Rows[i].Cells["数据文件名"].FormattedValue.ToString().Trim();
                            FilePath = m_Hook.DataInfoGrid.Rows[i].Cells["存储位置"].FormattedValue.ToString().Trim();
                            type     = m_Hook.DataInfoGrid.Rows[i].Cells["数据类型"].FormattedValue.ToString().Trim();
                            if ("标准图幅数据" == type)
                            {
                                datatype = EnumDataType.标准图幅.GetHashCode();
                            }
                            else if ("非标准图幅数据" == type)
                            {
                                datatype = EnumDataType.非标准图幅.GetHashCode();
                            }
                            else if ("控制点数据" == type)
                            {
                                datatype = EnumDataType.控制点数据.GetHashCode();
                            }
                        }
                        catch
                        {
                            eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "数据文件:" + FileName + "删除失败。原因为:数据文件的ID获取失败\n" + "是否继续删除?");
                            eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                            if (eerorFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                continue;
                            }
                            else
                            {
                                frmbar.Close();
                                return;
                            }
                        }
                        #endregion
                        #region 在元信息表中删除
                        frmbar.SetFrmProcessBarText("正在删除文件:" + FileName);
                        if (ex != null)
                        {
                            ex = new Exception("连接元数据库失败!连接地址为:" + ConnStr);
                            pSysDB.CloseDbConnection();
                            return;
                        }
                        if (lid != -1 && datatype != -1)
                        {
                            ModDBOperator.DelDataItem(lid, datatype, pSysDB, out ex);
                            if (null != ex)
                            {
                                eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "数据文件元信息删除失败。\n" + "请检查元信息库连接信息" + "!\n是否继续删除?");
                                eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                                if (eerorFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    continue;
                                }
                                else
                                {
                                    frmbar.Close();
                                    return;
                                }
                            }
                        }

                        #endregion
                        #region 在文件库中删除

                        if (2 != datatype)////数据类型为控制点控制点数据则不进行文件的删除操作
                        {
                            bool Delstate = ModDBOperator.DelDataItem(FilePath, FileName, ip, id, password, out ex);
                            if (!Delstate)
                            {
                                eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "数据文件\n'" + FilePath + "/" + FileName + "'\n删除失败。\n" + " 请确认文件是否存在或是否为占用状态。" + "\n是否继续删除?");
                                eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                                if (eerorFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                                {
                                    continue;
                                }
                                else
                                {
                                    frmbar.Close();
                                    return;
                                }
                            }
                        }
                        #endregion
                        #region 记录DataGrid中要删除的行
                        delrowlist.Add(i);
                        #endregion
                        #region 在树节点中删除文件节点

                        ModDBOperator.DelNodeByNameAndText(Deltreenode, FilePath, FileName, out ex);
                        if (null != ex)
                        {
                            eerorFrm       = new SysCommon.Error.frmInformation("是", "否", "树节点删除失败。原因为:\n" + ex.Message + "!\n是否继续删除?");
                            eerorFrm.Owner = (m_Hook as Plugin.Application.IAppFormRef).MainForm;
                            if (eerorFrm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                            {
                                continue;
                            }
                            else
                            {
                                frmbar.Close();
                                return;
                            }
                        }
                        #endregion
                    }
                }
                /////数据列表中移除相应的行
                if (null != delrowlist)
                {
                    for (int j = 0; j < delrowlist.Count; j++)
                    {
                        m_Hook.DataInfoGrid.Rows.Remove(m_Hook.DataInfoGrid.Rows[delrowlist[j] - j]);
                    }
                }
                frmbar.Close();
                #endregion
            }
            #region 图层处理
            if (ModData.v_AppFileDB.MapControl.LayerCount > 0 && datatype != 2)
            {
                IGroupLayer Glayer = null;
                for (int i = 0; i < ModData.v_AppFileDB.MapControl.LayerCount; i++)
                {
                    ILayer getlayer = ModData.v_AppFileDB.MapControl.get_Layer(i);
                    if (getlayer.Name == "项目范围图")
                    {
                        Glayer = getlayer as IGroupLayer;
                    }
                }
                if (null != Glayer)
                {
                    ICompositeLayer comlayer  = Glayer as ICompositeLayer;
                    string          layername = null;
                    switch (datatype)
                    {
                    case 0:
                        layername = "MapFrame_";
                        break;

                    case 1:
                        layername = "Range_";
                        break;

                    default:
                        layername = "_";
                        break;
                    }
                    if (comlayer != null)
                    {
                        for (int i = 0; i < comlayer.Count; i++)
                        {
                            ILayer orglayer = comlayer.get_Layer(i);
                            string lname    = orglayer.Name;
                            if (lname.Contains(layername))
                            {
                                Glayer.Delete(orglayer);
                                ModData.v_AppFileDB.TOCControl.Update();
                                ModData.v_AppFileDB.MapControl.ActiveView.Refresh();
                            }
                        }
                    }
                }
            }
            if (datatype == EnumDataType.控制点数据.GetHashCode())
            {
                IGraphicsContainer pGra = ModData.v_AppFileDB.MapControl.Map as IGraphicsContainer;
                pGra.DeleteAllElements();
                ModData.v_AppFileDB.MapControl.ActiveView.Refresh();
            }
            #endregion


            //刷新时间列表框

            ModDBOperator.LoadComboxTime(ConnStr, out ex);
            if (ex != null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "加载时间列表框失败," + ex.Message);
                return;
            }
        }
Exemplo n.º 2
0
        public override void OnClick()
        {
            Exception eError = null;

            #region 通过树节点获取源数据库的连接地址
            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.DataKey.ToString() != EnumTreeNodeType.DATABASE.ToString())
            {
                return;
            }
            if (DBNode.Name != "文件连接")
            {
                return;
            }
            XmlElement connElem = DBNode.Tag as XmlElement;
            if (connElem == null)
            {
                return;
            }
            string conStr = connElem.GetAttribute("MetaDBConn");

            #endregion

            SaveFileDialog saveDial = new SaveFileDialog();
            saveDial.Title  = "保存数据";
            saveDial.Filter = "控制点数据(*.mdb)|*.mdb";
            if (saveDial.ShowDialog() == DialogResult.OK)
            {
                FrmProcessBar frmbar = new FrmProcessBar();
                frmbar.Show();

                string   pFileName   = saveDial.FileName;
                FileInfo pFileInfo   = new FileInfo(ModData.v_TempControlDB);
                FileInfo desFileInfo = pFileInfo.CopyTo(pFileName, true);         //文件存储路径加名称

                string path = desFileInfo.DirectoryName;                          //文件存储路径

                //连接目标表

                SysCommon.DataBase.SysTable desSysTable = new SysCommon.DataBase.SysTable();
                desSysTable.SetDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pFileName + ";Persist Security Info=True", SysCommon.enumDBConType.OLEDB, SysCommon.enumDBType.ACCESS, out eError);
                if (eError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "连接元数据库失败!\n连接地址为:" + pFileName);
                    desSysTable.CloseDbConnection();
                    return;
                }
                //获得目标表格
                DataTable desTable = desSysTable.GetTable("metadata", out eError);
                if (eError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message + "在库中不存在表格'metadata',请检查!");
                    desSysTable.CloseDbConnection();
                    return;
                }

                //insert 语句
                string insertStr = "insert into metadata (";
                for (int i = 1; i < desTable.Columns.Count; i++)
                {
                    //第一列为自动编号ID,从第二列开始

                    insertStr += desTable.Columns[i].ColumnName + ",";
                }
                insertStr  = insertStr.Substring(0, insertStr.Length - 1) + ")";
                insertStr += " values (";

                //连接源数据库
                SysCommon.DataBase.SysTable pSysTable = new SysCommon.DataBase.SysTable();
                ////pSysTable.SetDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + conStr + ";Persist Security Info=True", SysCommon.enumDBConType.OLEDB, SysCommon.enumDBType.ACCESS, out eError);
                pSysTable.SetDbConnection(conStr, SysCommon.enumDBConType.ORACLE, SysCommon.enumDBType.ORACLE, out eError);
                if (eError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("错误", "连接元数据库失败!\n连接地址为:" + conStr);
                    pSysTable.CloseDbConnection();
                    desSysTable.CloseDbConnection();
                    return;
                }
                //源数据表格

                DataTable ordDt = pSysTable.GetTable("ControlPointMDTable", out eError);
                if (eError != null)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "查询控制点元信息出错!");
                    pSysTable.CloseDbConnection();
                    desSysTable.CloseDbConnection();
                    return;
                }
                pSysTable.CloseDbConnection();

                if (desTable.Columns.Count + 5 != ordDt.Columns.Count)
                {
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "目标数据库与源数据库字段结构不一致!");
                    desSysTable.CloseDbConnection();
                    return;
                }
                #region 遍历要导出的数据
                //设置进度条最大值

                frmbar.SetFrmProcessBarMax(m_Hook.DataInfoGrid.SelectedRows.Count);
                int pValue = 0;
                for (int i = 0; i < m_Hook.DataInfoGrid.RowCount; i++)
                {
                    if (m_Hook.DataInfoGrid.Rows[i].Selected)
                    {
                        string savePath = m_Hook.DataInfoGrid.Rows[i].Cells["存储位置"].FormattedValue.ToString().Trim();
                        if (!savePath.Contains("控制点数据"))
                        {
                            //其他数据导出
                            //pValue++;
                            //frmbar.SetFrmProcessBarValue(pValue);
                            continue;
                        }
                        frmbar.SetFrmProcessBarText("正在进行下载数据:" + m_Hook.DataInfoGrid.Rows[i].Cells["数据文件名"].FormattedValue.ToString().Trim());

                        if (m_Hook.DataInfoGrid.Rows[i].Cells["ID"].FormattedValue.ToString().Trim() == "")
                        {
                            return;
                        }
                        long dataID = Convert.ToInt64(m_Hook.DataInfoGrid.Rows[i].Cells["ID"].FormattedValue.ToString().Trim());
                        //执行导出操作
                        OutPutOneRacord(dataID, insertStr, ordDt, desSysTable, path, out eError);
                        if (eError != null)
                        {
                            SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", eError.Message);
                            desSysTable.CloseDbConnection();
                            frmbar.Dispose();
                            frmbar.Close();
                            return;
                        }
                        pValue++;
                        frmbar.SetFrmProcessBarValue(pValue);
                    }
                }
                #endregion

                frmbar.Dispose();
                frmbar.Close();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="ftpfilepath">相对根目录的文件完整路径</param>
        /// <param name="filePath">本地保存文件的完整路径</param>
        /// <param name="fileName">文件名</param>
        /// <returns></returns>
        public bool Download(string ftpfilepath, string filePath, string fileName, out string errorinfo)////上面的代码实现了从ftp服务器下载文件的功能
        {
            Exception ex = null;

            errorinfo = "";
            FrmProcessBar ProcBar = new FrmProcessBar();

            ProcBar.Show();
            try
            {
                filePath = filePath.Replace("我的电脑\\", "");
                String onlyFileName = Path.GetFileName(fileName);
                string newFileName  = filePath;
                if (File.Exists(newFileName))
                {
                    errorinfo = string.Format("本地文件{0}已存在,无法下载", newFileName);
                    return(false);
                }
                ftpfilepath = ftpfilepath.Replace("\\", "/");
                string url = "ftp://" + ftpServerIP + "/" + ftpfilepath;
                Connect(url);//连接
                reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
                reqFTP.KeepAlive   = false;
                reqFTP.Timeout     = 10000;
                FtpWebResponse response   = (FtpWebResponse)reqFTP.GetResponse();
                Stream         ftpStream  = response.GetResponseStream();
                long           cl         = response.ContentLength;
                int            bufferSize = 2048;

                int    readCount;
                byte[] buffer = new byte[bufferSize];
                readCount = ftpStream.Read(buffer, 0, bufferSize);
                FileStream outputStream = new FileStream(newFileName, FileMode.Create);
                long       ProcBarValue = 0;
                //////
                long all = GetFileSize(ftpfilepath, out ex);
                {
                    if (null != ex)
                    {
                        return(false);
                    }
                }
                ProcBar.SetFrmProcessBarMax(all / 2048);
                //////
                while (readCount > 0)
                {
                    ProcBarValue++;
                    ProcBar.SetFrmProcessBarText("正在下载文件:" + fileName);
                    ProcBar.SetFrmProcessBarValue(ProcBarValue);
                    Application.DoEvents();
                    outputStream.Write(buffer, 0, readCount);
                    readCount = ftpStream.Read(buffer, 0, bufferSize);
                }
                ftpStream.Close();
                outputStream.Close();
                response.Close();
                errorinfo = "Succeed";
                return(true);
            }
            catch (Exception exx)
            {
                errorinfo = string.Format("因{0},无法下载", exx.Message);
                return(false);
            }
            finally
            {
                ProcBar.Dispose();
                ProcBar.Close();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 续传文件
        /// </summary>
        /// <param name="filename"></param>
        public bool Upload(string filename, long size, string path, out string errorinfo) //上面的代码实现了从ftp服务器上载文件的功能
        {
            FrmProcessBar frmbar = new FrmProcessBar();

            frmbar.Show();
            path = path.Replace("\\", "/");
            FileInfo fileInf = new FileInfo(filename);
            //string uri = "ftp://" + path + "/" + fileInf.Name;
            string uri = "ftp://" + ftpServerIP + "/" + path + filename;

            Connect(uri);//连接
            // 默认为true,连接不会被关闭
            // 在一个命令之后被执行
            reqFTP.KeepAlive = false;
            reqFTP.Timeout   = 10000;
            // 指定执行什么命令
            reqFTP.Method = WebRequestMethods.Ftp.AppendFile;
            // 上传文件时通知服务器文件的大小
            reqFTP.ContentLength = fileInf.Length;
            // 缓冲大小设置为kb
            long procMax = (fileInf.Length - size) / 2048;

            frmbar.SetFrmProcessBarMax(procMax);
            frmbar.SetFrmProcessBarText("正在续传文件:" + filename);
            int buffLength = 2048;

            byte[] buff = new byte[buffLength];
            int    contentLen;
            // 打开一个文件流(System.IO.FileStream) 去读上传的文件
            FileStream fs    = fileInf.OpenRead();
            int        value = 0;

            try
            {
                StreamReader dsad = new StreamReader(fs);
                fs.Seek(size, SeekOrigin.Begin);
                // 把上传的文件写入流
                Stream strm = reqFTP.GetRequestStream();
                // 每次读文件流的kb
                contentLen = fs.Read(buff, 0, buffLength);
                // 流内容没有结束
                while (contentLen != 0)
                {
                    // 把内容从file stream 写入upload stream
                    value++;
                    frmbar.SetFrmProcessBarValue(value);
                    Application.DoEvents();
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
                // 关闭两个流
                strm.Close();
                fs.Close();
                errorinfo = "Succeed";
                return(true);
            }
            catch (Exception ex)
            {
                errorinfo = string.Format("因{0},无法完成上传", ex.Message);
                return(false);
            }
            finally
            {
                if (null != fileInf)
                {
                    fileInf = null;
                }
                frmbar.Close();
                frmbar.Dispose();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="path"></param>
        public bool Upload(string filename, string path, string savename, out string errorinfo) //上面的代码实现了从ftp服务器上载文件的功能
        {
            FrmProcessBar frmbar = new FrmProcessBar();

            frmbar.Show();
            path = path.Replace("\\", "/");
            FileInfo fileInf = new FileInfo(filename);

            savename = savename.Replace("+", "-"); // 处理非法字符
            savename = savename.Replace("#", "-"); //
            string uri;

            if (string.IsNullOrEmpty(path))
            {
                uri = "ftp://" + ftpServerIP + "/" + savename;
            }
            else
            {
                uri = "ftp://" + ftpServerIP + "/" + path + "/" + savename;
            }
            Connect(uri);//连接

            // 默认为true,连接不会被关闭
            // 在一个命令之后被执行
            reqFTP.KeepAlive = false;
            reqFTP.Timeout   = 10000;
            // 指定执行什么命令
            reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
            // 上传文件时通知服务器文件的大小
            reqFTP.ContentLength = fileInf.Length;
            // 缓冲大小设置为kb
            long procMax = fileInf.Length / 2048;

            //进度条最大值
            frmbar.SetFrmProcessBarMax(procMax);
            string task = "正在上传文件:" + savename;

            frmbar.SetFrmProcessBarText(task);
            int value      = 0;
            int buffLength = 2048;

            byte[] buff = new byte[buffLength];
            int    contentLen;

            // 打开一个文件流(System.IO.FileStream) 去读上传的文件

            try
            {
                FileStream fs = fileInf.OpenRead();
                // 把上传的文件写入流
                Stream strm = reqFTP.GetRequestStream();
                // 每次读文件流的kb
                contentLen = fs.Read(buff, 0, buffLength);
                // 流内容没有结束
                while (contentLen != 0)
                {
                    value++;
                    frmbar.SetFrmProcessBarValue(value);
                    Application.DoEvents();
                    // 把内容从file stream 写入upload stream
                    strm.Write(buff, 0, contentLen);
                    contentLen = fs.Read(buff, 0, buffLength);
                }
                // 关闭两个流
                strm.Close();
                fs.Close();
                errorinfo = "Succeed";
                return(true);
            }
            catch (Exception ex)
            {
                errorinfo = string.Format("因{0},无法完成上传", ex.Message);
                return(false);
            }
            finally
            {
                frmbar.Dispose();
                frmbar.Close();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 删除一个工程
        /// </summary>
        /// <returns></returns>
        public bool DeleteProject(DevComponents.AdvTree.Node ProjectNode, string ConStr, long Projiectid , out string err)
        {
            Exception ex = null;

            err = "";
            if (string.IsNullOrEmpty(this._ProName))
            {
                err = "没有指定项目名称!";
                return(false);
            }
            if (string.IsNullOrEmpty(ConStr))
            {
                err = "没有指定元信息库连接信息!";
                return(false);
            }
            int           value  = 0;
            FrmProcessBar DelBar = new FrmProcessBar(10);

            DelBar.Show();
            DelBar.SetFrmProcessBarText("正在连接元信息库");
            Application.DoEvents();
            SysCommon.DataBase.SysTable pSysDB = new SysCommon.DataBase.SysTable();    //属性库连接类
            pSysDB.SetDbConnection(ConStr, SysCommon.enumDBConType.ORACLE, SysCommon.enumDBType.ORACLE, out ex);
            if (ex != null)
            {
                err = "元信息库连接失败!连接地址为:" + ConStr;
                pSysDB.CloseDbConnection();
                DelBar.Dispose();
                DelBar.Close();
                return(false);
            }
            long ProjectID = Projiectid;

            #region  除项目的所有产品
            string    Sql      = "SELECT ID,产品名称,存储位置 FROM ProductMDTable WHERE 项目ID=" + ProjectID;
            DataTable GetTable = pSysDB.GetSQLTable(Sql, out ex);
            if (null != ex)
            {
                err = "获取项目的产品信息失败!";
                pSysDB.CloseDbConnection();
                DelBar.Dispose();
                DelBar.Close();
                return(false);
            }
            if (null != GetTable)
            {
                for (int i = 0; i < GetTable.Rows.Count; i++)
                {
                    long   ProducetId  = -1;
                    string ProductName = string.Empty;
                    string ProductPath = string.Empty;
                    ProducetId  = long.Parse(GetTable.Rows[i][0].ToString());
                    ProductName = GetTable.Rows[i][1].ToString().Trim();
                    ProductPath = GetTable.Rows[i][2].ToString().Trim();
                    DelBar.SetFrmProcessBarValue(value);
                    DelBar.SetFrmProcessBarText(" 正在删除产品:" + ProductName);
                    value += 1;
                    if (value == 10)
                    {
                        value = 0;
                    }
                    Application.DoEvents();
                    DevComponents.AdvTree.Node ProductNode = ModDBOperator.GetTreeNode(ProjectNode, ProductPath, ProductName, EnumTreeNodeType.PRODUCT.ToString(), ProducetId, out ex);
                    if (null != ex)
                    {
                        err = "获取项目的产品:‘" + ProductName + "’树节点失败!";
                        pSysDB.CloseDbConnection();
                        DelBar.Dispose();
                        DelBar.Close();
                        return(false);
                    }
                    if (null != ProductNode)
                    {
                        if (!ModDBOperator.DelProduct(ProductNode, out ex))
                        {
                            err = "删除项目的产品:‘" + ProductName + "’失败!";
                            pSysDB.CloseDbConnection();
                            DelBar.Dispose();
                            DelBar.Close();
                            return(false);
                        }
                    }
                }
            }
            #endregion
            #region  除项目的文件夹
            DelBar.SetFrmProcessBarText("正在删除工程项目目录");
            Application.DoEvents();
            if (!ModDBOperator.DelDirtory(this._ftpIP, this._ftpUSER, this._ftpPassWord, this._ProName, out ex))
            {
                err = "工程项目项目目录删除失败!";
                pSysDB.CloseDbConnection();
                DelBar.Dispose();
                DelBar.Close();
                return(false);
            }
            #endregion
            DelBar.Dispose();
            DelBar.Close();
            pSysDB.CloseDbConnection();
            return(true);
        }