Ejemplo n.º 1
0
        private IWorkspace GetWorkspace(string sFilePath, int wstype)
        {
            IWorkspace pWks = null;

            try
            {
                IPropertySet pPropSet = new PropertySetClass();
                switch (wstype)
                {
                case 1:
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWks        = pAccessFact.Open(pPropSet, 0);
                    pAccessFact = null;
                    break;

                case 2:
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWks         = pFileGDBFact.Open(pPropSet, 0);
                    pFileGDBFact = null;
                    break;

                case 3:
                    break;
                }
                pPropSet = null;
                return(pWks);
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置PDB、GDB工作区
        /// </summary>
        /// <param name="sFilePath">文件路径</param>
        /// <param name="wstype">工作区类型</param>
        /// <returns>输出错误Exception</returns>
        public bool SetWorkspace(string sFilePath, string type, out Exception eError)
        {
            eError = null;

            try
            {
                IPropertySet pPropSet = new PropertySetClass();
                switch (type)
                {
                case "PDB":
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    m_Workspace = pAccessFact.Open(pPropSet, 0);
                    pAccessFact = null;
                    m_connset   = "PDB;" + sFilePath;
                    break;

                case "GDB":
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    m_Workspace  = pFileGDBFact.Open(pPropSet, 0);
                    pFileGDBFact = null;
                    m_connset    = "GDB;" + sFilePath;
                    break;
                }

                pPropSet = null;
                return(true);
            }
            catch (Exception eX)
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 设置PDB、GDB工作区
        /// </summary>
        /// <param name="sFilePath">文件路径</param>
        /// <param name="wstype">工作区类型</param>
        /// <returns>输出错误Exception</returns>
        private IWorkspace SetWorkspace(string sFilePath, enumWSType wstype, out Exception eError)
        {
            eError = null;
            IWorkspace pWorkspace = null;

            try
            {
                IPropertySet pPropSet = new PropertySetClass();
                switch (wstype)
                {
                case enumWSType.PDB:
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWorkspace  = pAccessFact.Open(pPropSet, 0);
                    pAccessFact = null;
                    break;

                case enumWSType.GDB:
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWorkspace   = pFileGDBFact.Open(pPropSet, 0);
                    pFileGDBFact = null;
                    break;
                }
                pPropSet = null;
                return(pWorkspace);
            }
            catch (Exception eX)
            {
                eError = eX;
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 导入图层(导入一个MDB中的所有图层)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_InputLayer_Click(object sender, EventArgs e)
        {
            OpenFileDialog OpenMDBFrm = new OpenFileDialog();

            OpenMDBFrm.Filter = "ArcGis PDB 文件|*.mdb";
            if (DialogResult.OK == OpenMDBFrm.ShowDialog())
            {
                string sGetPDBFileName = OpenMDBFrm.FileName;
                try
                {
                    IWorkspace             pWS         = null;
                    IPropertySet           pPropSet    = new PropertySetClass();
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sGetPDBFileName);
                    pWS         = pAccessFact.Open(pPropSet, 0);
                    pAccessFact = null;
                    IEnumDatasetName pEnumDatasetName = pWS.get_DatasetNames(esriDatasetType.esriDTFeatureClass);
                    IDatasetName     pDataSetName     = pEnumDatasetName.Next();
                    if (m_Layers == null)
                    {
                        m_Layers = new List <IFeatureClass>();
                    }
                    this.combox_layers.Items.Clear();
                    while (pDataSetName != null)
                    {
                        IFeatureClass pGetFeaCls = (pWS as IFeatureWorkspace).OpenFeatureClass(pDataSetName.Name);
                        if (pGetFeaCls != null)
                        {
                            m_Layers.Add(pGetFeaCls);
                            this.combox_layers.Items.Add(pDataSetName.Name);
                        }
                        pDataSetName = pEnumDatasetName.Next();
                    }
                    ////////将这些图层加载到界面上////////
                    ////////默认选中一个
                    if (this.combox_layers.Items.Count > 0)
                    {
                        this.combox_layers.SelectedIndex = 0;
                    }
                    string        sSelectLayerName = this.combox_layers.Text.Trim();
                    IFeatureClass GetLayerFeacls   = GetFeaClsByName(sSelectLayerName);
                    AddALayer(GetLayerFeacls);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pEnumDatasetName);
                }
                catch (Exception eError)
                {
                    if (ModData.SysLog == null)
                    {
                        ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    }
                    ModData.SysLog.Write(eError);
                }
            }
        }
Ejemplo n.º 5
0
        public static IWorkspace ConectarAGeodatabase(IPropertySet propertySet)
        {
            IWorkspaceFactory pFW = new AccessWorkspaceFactoryClass();
            IWorkspace        pWorkspace;

            try
            {
                pWorkspace = pFW.Open(propertySet, 0);
            }
            catch (Exception e)
            {
                throw e;
            }
            return(pWorkspace);
        }
        public IWorkspace OpenWorkspace()
        {
            try
            {
                IWorkspaceFactory workspaceFactory = new AccessWorkspaceFactoryClass();
                IWorkspace        pWorkspace       = workspaceFactory.Open(Connection.DataSource.PropertySet, 0);//用的是从注册表里面读出的默认数据,在构造connection类的时候自动生成。

                return(pWorkspace);
            }
            catch (Exception ex)
            {
                MessageBox.Show("打开数据库时出错: " + ex.Message, "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets a reference to an Access workspace object at the specified path.
        /// </summary>
        /// <param name="databasePath"></param>
        /// <returns>AccessWorkspace</returns>
        /// <remarks>
        /// </remarks>
        public static IWorkspace GetAccessWorkspace(string databasePath)
        {
            // Declare COM objects.
            IWorkspaceFactory2 workspaceFactory;
            IPropertySet2      propertyset;

            // Create the Access Workspace factory
            workspaceFactory = new AccessWorkspaceFactoryClass();

            // Create the property set
            propertyset = new PropertySetClass();
            propertyset.SetProperty("Database", databasePath);

            // Get the workspace
            return(workspaceFactory.Open(propertyset, 0));
        }
        public ITable OpenTable(string tableName)
        {
            try
            {
                IWorkspaceFactory workspaceFactory  = new AccessWorkspaceFactoryClass();
                IWorkspace        pWorkspace        = workspaceFactory.Open(Connection.DataSource.PropertySet, 0);
                IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;//注意openTable这个方法是在IFeatureWorkspace中的。
                ITable            pTable            = pFeatureWorkspace.OpenTable(tableName);

                return(pTable);
            }
            catch (Exception ex)
            {
                MessageBox.Show("打开表格数据时出错: " + ex.Message, "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(null);
            }
        }
        public IFeatureDataset OpenFeatureDataset(string featureDatasetName)
        {
            try
            {
                IWorkspaceFactory workspaceFactory  = new AccessWorkspaceFactoryClass();
                IWorkspace        pWorkspace        = workspaceFactory.Open(Connection.DataSource.PropertySet, 0);
                IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
                IFeatureDataset   pFeatureDataset   = pFeatureWorkspace.OpenFeatureDataset(featureDatasetName);

                return(pFeatureDataset);
            }
            catch (Exception ex)
            {
                MessageBox.Show("打开图形数据时出错: " + ex.Message, "错误!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(null);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 设置PDB、GDB、SHP工作区
        /// </summary>
        /// <param name="sFilePath">文件路径</param>
        /// <param name="wstype">工作区类型</param>
        /// <returns>输出错误Exception</returns>
        private IWorkspace SetWorkspace(string sFilePath, string dbType, out Exception eError)
        {
            eError = null;
            IWorkspace   pWS      = null;
            IPropertySet pPropSet = new PropertySetClass();

            try
            {
                switch (dbType)
                {
                case "PDB":
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWS         = pAccessFact.Open(pPropSet, 0);
                    pAccessFact = null;
                    break;

                case "GDB":
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWS          = pFileGDBFact.Open(pPropSet, 0);
                    pFileGDBFact = null;
                    break;

                case "SHP":
                    ShapefileWorkspaceFactory pFileSHPFact = new ShapefileWorkspaceFactory();
                    pPropSet.SetProperty("DATABASE", sFilePath);
                    pWS          = pFileSHPFact.Open(pPropSet, 0);
                    pFileSHPFact = null;
                    break;
                }
                pPropSet = null;
                return(pWS);
            }
            catch (Exception eX)
            {
                eError = eX;
                return(null);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 打开更新目标工作空间
 /// </summary>
 /// <returns>返回模板工作空间</returns>
 private IWorkspace OpenTempleteWorkSpace()
 {
     if (this._DesDBType == "PDB")
     {
         IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
         return(pWorkspaceFactory.Open(this._PropertySet, 0));
     }
     else if (this._DesDBType == "GDB")
     {
         IWorkspaceFactory pWorkspaceFactory = new FileGDBWorkspaceFactoryClass();
         return(pWorkspaceFactory.Open(this._PropertySet, 0));
     }
     else if (this._DesDBType == "SDE")
     {
         IWorkspaceFactory pWorkspaceFactory = new SdeWorkspaceFactoryClass();
         return(pWorkspaceFactory.Open(this._PropertySet, 0));
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 12
0
 //
 //
 //
 public static IFeatureWorkspace openPDB(string filePath)
 {
     try
     {
         IWorkspaceFactory pWSF = new AccessWorkspaceFactoryClass();
         IFeatureWorkspace pFWS;
         IPropertySet pPropset = new PropertySetClass();
         pPropset.SetProperty("DATABASE", filePath);
         pFWS = pWSF.Open(pPropset, 0) as IFeatureWorkspace;
         return pFWS;
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
         return null;
     }
 }
Ejemplo n.º 13
0
        private void listViewEx2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewEx2.SelectedItems.Count == 0)
            {
                return;
            }
            if (listViewEx2.SelectedItems.Count > 1)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("信息提示", "请只选择一行");
                return;
            }
            listViewEx1.Items.Clear();
            ListViewItem         pListItem      = listViewEx2.SelectedItems[0];
            string               path           = pListItem.SubItems[0].Text;
            string               type           = pListItem.SubItems[1].Text;
            string               lastPath       = path.Substring(path.LastIndexOf('.') + 1).ToLower();
            IWorkspace           mWorkSpace     = null;
            List <IFeatureLayer> mFeatureLayers = new List <IFeatureLayer>();

            if (type == "Personal Geodatabase")
            {
                try
                {
                    if (lastPath == "mdb")
                    {
                        AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                        IPropertySet           pPropSet    = new PropertySetClass();
                        pPropSet.SetProperty("DATABASE", path);
                        mWorkSpace = pAccessFact.Open(pPropSet, 0);
                    }
                    else if (lastPath == "gdb")
                    {
                        FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                        IPropertySet pPropSet = new PropertySetClass();
                        pPropSet.SetProperty("DATABASE", path);
                        mWorkSpace = pFileGDBFact.Open(pPropSet, 0);
                    }

                    if (pAllEditInfo.ContainsKey(mWorkSpace))
                    {
                        mFeatureLayers = pAllEditInfo[mWorkSpace];
                        foreach (IFeatureLayer i in mFeatureLayers)
                        {
                            listViewEx1.Items.Add(i.Name.ToString());
                        }
                        listViewEx1.Refresh();
                    }
                    pSelectWorkspace = mWorkSpace;
                }
                catch (System.Exception ex)
                {
                    //******************************************
                    //guozheng added System Exception log
                    if (SysCommon.Log.Module.SysLog == null)
                    {
                        SysCommon.Log.Module.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    }
                    SysCommon.Log.Module.SysLog.Write(ex);
                    //******************************************
                }
            }
        }
Ejemplo n.º 14
0
        //根据文件路径打开文件 ygc 2012-8-29
        private IWorkspace GetWorkspace(string filePath)
        {
            IWorkspace pWorkspace = null;
            string     FileType   = filePath.Substring(filePath.Length - 4, 4);

            switch (FileType)
            {
            case ".shp":
                IWorkspaceFactory pShpWorkSpaceFactory = new ShapefileWorkspaceFactory();
                try
                {
                    pWorkspace = pShpWorkSpaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(filePath), 0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "错误");
                    return(null);
                }
                finally
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pShpWorkSpaceFactory);
                }
                break;

            case ".mdb":
                IPropertySet pPropertySet = new PropertySetClass();
                pPropertySet.SetProperty("DATABASE", filePath);
                IWorkspaceFactory pWorkspaceFactory = new AccessWorkspaceFactoryClass();
                try
                {
                    pWorkspace = pWorkspaceFactory.Open(pPropertySet, 0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "错误");
                    return(null);
                }
                finally
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pWorkspaceFactory);
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pPropertySet);
                }
                break;

            case ".gdb":
                IWorkspaceFactory pGDBWorkSpace = new FileGDBWorkspaceFactoryClass();
                try
                {
                    pWorkspace = pGDBWorkSpace.OpenFromFile(filePath, 0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "错误");
                    return(null);
                }
                finally
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(pGDBWorkSpace);
                }
                break;
            }
            return(pWorkspace);
        }
Ejemplo n.º 15
0
        //根据XML节点获取连接信息
        public static object GetDBInfoByXMLNode(XmlElement dbElement, string strPath)
        {
            try
            {
                string strType     = dbElement.GetAttribute("类型");
                string strServer   = dbElement.GetAttribute("服务器");
                string strInstance = dbElement.GetAttribute("服务名");
                string strDB       = dbElement.GetAttribute("数据库");
                if (strPath != "")
                {
                    strDB = strPath + strDB;
                }
                string strUser     = dbElement.GetAttribute("用户");
                string strPassword = dbElement.GetAttribute("密码");
                string strVersion  = dbElement.GetAttribute("版本");

                IPropertySet pPropSet = null;
                switch (strType.Trim().ToLower())
                {
                case "pdb":
                    pPropSet = new PropertySetClass();
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    if (!File.Exists(strDB))
                    {
                        FileInfo filePDB = new FileInfo(strDB);
                        pAccessFact.Create(filePDB.DirectoryName, filePDB.Name, null, 0);
                    }
                    pPropSet.SetProperty("DATABASE", strDB);
                    IWorkspace pdbWorkspace = pAccessFact.Open(pPropSet, 0);
                    pAccessFact = null;
                    return(pdbWorkspace);

                case "gdb":
                    pPropSet = new PropertySetClass();
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    if (!Directory.Exists(strDB))
                    {
                        DirectoryInfo dirGDB = new DirectoryInfo(strDB);
                        pFileGDBFact.Create(dirGDB.Parent.FullName, dirGDB.Name, null, 0);
                    }
                    pPropSet.SetProperty("DATABASE", strDB);
                    IWorkspace gdbWorkspace = pFileGDBFact.Open(pPropSet, 0);
                    pFileGDBFact = null;
                    return(gdbWorkspace);

                case "sde":
                    pPropSet = new PropertySetClass();
                    IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass();
                    pPropSet.SetProperty("SERVER", strServer);
                    pPropSet.SetProperty("INSTANCE", strInstance);
                    pPropSet.SetProperty("DATABASE", strDB);
                    pPropSet.SetProperty("USER", strUser);
                    pPropSet.SetProperty("PASSWORD", strPassword);
                    pPropSet.SetProperty("VERSION", strVersion);
                    IWorkspace sdeWorkspace = pSdeFact.Open(pPropSet, 0);
                    pSdeFact = null;
                    return(sdeWorkspace);

                case "access":
                    System.Data.Common.DbConnection dbCon = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDB);
                    dbCon.Open();
                    return(dbCon);

                case "oracle":
                    string strOracle = "Data Source=" + strDB + ";Persist Security Info=True;User ID=" + strUser + ";Password="******";Unicode=True";
                    System.Data.Common.DbConnection dbConoracle = new OracleConnection(strOracle);
                    dbConoracle.Open();
                    return(dbConoracle);

                case "sql":
                    string strSql = "Data Source=" + strDB + ";Initial Catalog=" + strInstance + ";User ID=" + strUser + ";Password=" + strPassword;
                    System.Data.Common.DbConnection dbConsql = new SqlConnection(strSql);
                    dbConsql.Open();
                    return(dbConsql);

                default:
                    break;
                }

                return(null);
            }
            catch (Exception e)
            {
                //*******************************************************************
                //guozheng added
                if (ModuleData.v_SysLog != null)
                {
                    ModuleData.v_SysLog.Write(e, null, DateTime.Now);
                }
                else
                {
                    ModuleData.v_SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModuleData.v_SysLog.Write(e, null, DateTime.Now);
                }
                //********************************************************************
                return(null);
            }
        }
Ejemplo n.º 16
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (listViewEx.CheckedItems.Count == 0)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未选择对象,无法生成历史!");
                return;
            }

            Exception err = null;

            //获取现势库连接信息

            SysCommon.Gis.SysGisDataSet sourceSysGisDataSet = new SysCommon.Gis.SysGisDataSet();
            switch (comBoxType.Text)
            {
            case "SDE":
                sourceSysGisDataSet.SetWorkspace(txtServer.Text, txtInstance.Text, txtDB.Text, txtUser.Text, txtPassword.Text, txtVersion.Text, out err);
                break;

            case "GDB":
                sourceSysGisDataSet.SetWorkspace(txtDB.Text, SysCommon.enumWSType.GDB, out err);
                break;

            case "PDB":
                sourceSysGisDataSet.SetWorkspace(txtDB.Text, SysCommon.enumWSType.PDB, out err);
                break;

            default:
                break;
            }

            if (err != null || sourceSysGisDataSet.WorkSpace == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未设置用户数据库连接或连接失败,请检查!");
                return;
            }

            //获取历史库连接信息

            IPropertySet pPropSet        = new PropertySetClass();
            IWorkspace   pTagetWorkspace = null;

            try
            {
                switch (comboBoxTypeHistory.Text)
                {
                case "PDB":
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    if (!File.Exists(txtDBHistory.Text))
                    {
                        FileInfo filePDB = new FileInfo(txtDBHistory.Text);
                        pAccessFact.Create(filePDB.DirectoryName, filePDB.Name, null, 0);
                    }
                    pPropSet.SetProperty("DATABASE", txtDBHistory.Text);
                    pTagetWorkspace = pAccessFact.Open(pPropSet, 0);

                    break;

                case "GDB":
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    DirectoryInfo dirGDB = new DirectoryInfo(txtDBHistory.Text);
                    pFileGDBFact.Create(dirGDB.Parent.FullName, dirGDB.Name.Substring(0, dirGDB.Name.Length - 4), null, 0);
                    pPropSet.SetProperty("DATABASE", txtDBHistory.Text);
                    pTagetWorkspace = pFileGDBFact.Open(pPropSet, 0);

                    break;

                case "SDE":
                    IWorkspaceFactory pSdeFact = new SdeWorkspaceFactoryClass();
                    pPropSet.SetProperty("SERVER", txtServerHistory.Text);
                    pPropSet.SetProperty("INSTANCE", txtInstanceHistory.Text);
                    pPropSet.SetProperty("DATABASE", txtDBHistory.Text);
                    pPropSet.SetProperty("USER", txtUserHistory.Text);
                    pPropSet.SetProperty("PASSWORD", txtPasswordHistory.Text);
                    pPropSet.SetProperty("VERSION", txtVersionHistory.Text);
                    pTagetWorkspace = pSdeFact.Open(pPropSet, 0);

                    break;

                default:
                    break;
                }
            }
            catch (Exception er)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                //********************************************************************
            }

            if (pTagetWorkspace == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未设置历史库连接或连接失败,请检查!");
                return;
            }

            this.Cursor = System.Windows.Forms.Cursors.AppStarting;

            List <string> lstData = new List <string>();

            try
            {
                //根据用户数据库结构创建历史库
                foreach (ListViewItem aItem in listViewEx.CheckedItems)
                {
                    if (aItem.Tag.ToString() == "FD")
                    {
                        IFeatureDataset tagetFeatureDataset = null;
                        IFeatureDataset pFeatureDataset     = sourceSysGisDataSet.GetFeatureDataset(aItem.Text, out err);
                        if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureDataset, aItem.Text + "_GOH"))
                        {
                            tagetFeatureDataset = (pTagetWorkspace as IFeatureWorkspace).CreateFeatureDataset(aItem.Text + "_GOH", (pFeatureDataset as IGeoDataset).SpatialReference);
                        }
                        else
                        {
                            tagetFeatureDataset = (pTagetWorkspace as IFeatureWorkspace).OpenFeatureDataset(aItem.Text + "_GOH");
                        }

                        IEnumDataset pEnumDs = pFeatureDataset.Subsets;
                        pEnumDs.Reset();
                        IDataset pDs = pEnumDs.Next();
                        while (pDs != null)
                        {
                            IFeatureClass pFeatureClass = pDs as IFeatureClass;
                            if (pFeatureClass != null)
                            {
                                if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, pDs.Name + "_GOH"))
                                {
                                    CreateFeatCls(tagetFeatureDataset, pFeatureClass, pDs.Name + "_GOH", out err);
                                }
                                lstData.Add(pDs.Name);
                            }
                            pDs = pEnumDs.Next();
                        }
                    }
                    else if (aItem.Tag.ToString() == "FC")
                    {
                        IFeatureClass pFeatureClass = sourceSysGisDataSet.GetFeatureClass(aItem.Text, out err);
                        if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, aItem.Text + "_GOH"))
                        {
                            CreateFeatCls(pTagetWorkspace as IFeatureWorkspace, pFeatureClass, aItem.Text + "_GOH", out err);
                        }
                        lstData.Add(aItem.Text);
                    }
                }
            }
            catch (Exception er)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                //********************************************************************
                this.Cursor = System.Windows.Forms.Cursors.Default;
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建历史库结构失败!");
                return;
            }

            //遍历现势库数据FC进行数据移植
            Dictionary <string, string> dicFieldsPair = new Dictionary <string, string>();

            dicFieldsPair.Add("OBJECTID", "SourceOID");
            Dictionary <string, object> dicValue = new Dictionary <string, object>();

            dicValue.Add("FromDate", DateTime.Now.ToString("u"));
            dicValue.Add("ToDate", DateTime.MaxValue.ToString("u"));//.ToString("YYYY-MM-DD HH:MI:SS"));
            dicValue.Add("State", 0);
            (pTagetWorkspace as IWorkspaceEdit).StartEditing(false);
            bool res = true;

            progressBarXLay.Maximum = lstData.Count;
            progressBarXLay.Minimum = 0;
            progressBarXLay.Value   = 0;
            foreach (string aFeatClsName in lstData)
            {
                labelXMemo.Text = "正在进行图层" + aFeatClsName + "...";
                Application.DoEvents();
                int            cnt           = 0;
                int            allcnt        = 0;
                IFeatureCursor featureCursor = null;
                IFeatureClass  tagetFeatCls  = null;
                try
                {
                    featureCursor = sourceSysGisDataSet.GetFeatureCursor(aFeatClsName, "", null, "", out err, out cnt, out allcnt);
                    tagetFeatCls  = (pTagetWorkspace as IFeatureWorkspace).OpenFeatureClass(aFeatClsName + "_GOH");
                }
                catch (Exception ex)
                {
                    //*******************************************************************
                    //guozheng added
                    if (ModData.SysLog != null)
                    {
                        ModData.SysLog.Write(ex, null, DateTime.Now);
                    }
                    else
                    {
                        ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                        ModData.SysLog.Write(ex, null, DateTime.Now);
                    }
                    //********************************************************************
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", ex.Message);
                    return;
                }

                progressBarXFeat.Maximum = cnt;
                progressBarXFeat.Minimum = 0;
                progressBarXFeat.Value   = 0;
                ModDBOperator.NewFeatures(tagetFeatCls, featureCursor, dicFieldsPair, dicValue, true, false, progressBarXFeat, out err);
                Marshal.ReleaseComObject(featureCursor);
                progressBarXLay.Value++;

                labelXMemo.Text = "";
                Application.DoEvents();
                if (err != null)
                {
                    res = false;
                    break;
                }
            }
            (pTagetWorkspace as IWorkspaceEdit).StopEditing(res);

            this.Cursor = System.Windows.Forms.Cursors.Default;
            if (res)
            {
                if (m_DbProjectElement != null)
                {
                    try
                    {
                        XmlElement aElement = m_DbProjectElement.SelectSingleNode(".//内容//历史库//连接信息") as XmlElement;
                        SaveObjDB(aElement, listViewEx.Items[0].Text + "_GOH");
                    }
                    catch (Exception er)
                    {
                        //*******************************************************************
                        //guozheng added
                        if (ModData.SysLog != null)
                        {
                            ModData.SysLog.Write(er, null, DateTime.Now);
                        }
                        else
                        {
                            ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                            ModData.SysLog.Write(er, null, DateTime.Now);
                        }
                        //********************************************************************
                        return;
                    }
                }
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "生成历史库成功!");
                this.Close();
            }
            else
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "生成历史库失败!");
            }
        }
Ejemplo n.º 17
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtProjectName.Text == "")
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("信息提示", "请填写输出文件名称 !");
                return;
            }

            if (!Directory.Exists(txtSavePath.Text.Trim()))
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("信息提示", "请选择保存路径 !");
                return;
            }

            if (listViewEx.CheckedItems.Count == 0)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("信息提示", "请选择数据版本信息 !");
                return;
            }

            string WorkSpacePath = txtSavePath.Text.Trim() + "\\" + txtProjectName.Text.Trim();

            IPropertySet pPropSet        = new PropertySetClass();
            IWorkspace   pTagetWorkspace = null;

            try
            {
                switch (comBoxType.Tag.ToString().Trim())
                {
                case "PDB":
                    AccessWorkspaceFactory pAccessFact = new AccessWorkspaceFactoryClass();
                    if (!File.Exists(WorkSpacePath + ".mdb"))
                    {
                        pAccessFact.Create(txtSavePath.Text, txtProjectName.Text, null, 0);
                    }
                    pPropSet.SetProperty("DATABASE", WorkSpacePath + ".mdb");
                    pTagetWorkspace = pAccessFact.Open(pPropSet, 0);
                    pAccessFact     = null;
                    pPropSet        = null;
                    break;

                case "GDB":
                    FileGDBWorkspaceFactoryClass pFileGDBFact = new FileGDBWorkspaceFactoryClass();
                    if (!Directory.Exists(WorkSpacePath + ".gdb"))
                    {
                        pFileGDBFact.Create(txtSavePath.Text, txtProjectName.Text, null, 0);
                    }
                    pPropSet.SetProperty("DATABASE", WorkSpacePath + ".gdb");
                    pTagetWorkspace = pFileGDBFact.Open(pPropSet, 0);
                    pFileGDBFact    = null;
                    pPropSet        = null;
                    break;

                default:
                    break;
                }
            }
            catch (Exception er)
            {
                //*******************************************************************
                //guozheng added
                if (ModData.SysLog != null)
                {
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                else
                {
                    ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                    ModData.SysLog.Write(er, null, DateTime.Now);
                }
                //********************************************************************
            }

            if (pTagetWorkspace == null)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "未设置输出库连接或连接失败,请检查!");
                return;
            }

            this.Cursor = System.Windows.Forms.Cursors.AppStarting;

            Exception            err        = null;
            bool                 res        = true;
            List <IFeatureLayer> lstFeatLay = new List <IFeatureLayer>();

            //根据历史图层创建输出数据图层结构
            for (int i = 0; i < Map.LayerCount; i++)
            {
                //cyf 20110706 add
                ILayer mLayer = Map.get_Layer(i);
                if (mLayer is IGroupLayer)
                {
                    ICompositeLayer pComLayer = mLayer as ICompositeLayer;
                    for (int j = 0; j < pComLayer.Count; j++)
                    {
                        IFeatureLayer featLay = pComLayer.get_Layer(j) as IFeatureLayer;
                        if (featLay == null)
                        {
                            continue;
                        }
                        if (!(featLay.FeatureClass as IDataset).Name.EndsWith("_GOH"))
                        {
                            continue;
                        }
                        lstFeatLay.Add(featLay);
                        if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, featLay.Name))//(featLay.FeatureClass as IDataset).Name
                        {
                            if (!CreateFeatCls(pTagetWorkspace as IFeatureWorkspace, featLay.FeatureClass, featLay.Name, out err))
                            {
                                res       = false;
                                featLay   = null;
                                pComLayer = null;
                                mLayer    = null;
                                break;
                            }
                        }
                    }
                }//end
                else
                {
                    IFeatureLayer featLay = Map.get_Layer(i) as IFeatureLayer;
                    if (featLay == null)
                    {
                        continue;
                    }
                    if (!(featLay.FeatureClass as IDataset).Name.EndsWith("_GOH"))
                    {
                        continue;
                    }
                    lstFeatLay.Add(featLay);
                    if (!(pTagetWorkspace as IWorkspace2).get_NameExists(esriDatasetType.esriDTFeatureClass, featLay.Name))//(featLay.FeatureClass as IDataset).Name
                    {
                        if (!CreateFeatCls(pTagetWorkspace as IFeatureWorkspace, featLay.FeatureClass, featLay.Name, out err))
                        {
                            res     = false;
                            featLay = null;
                            mLayer  = null;
                            break;
                        }
                    }
                }
            }

            if (res == false)
            {
                this.Cursor = System.Windows.Forms.Cursors.Default;
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "创建输出库结构失败!");
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pTagetWorkspace);
                pTagetWorkspace = null;
                lstFeatLay.Clear();
                lstFeatLay = null;
                try
                {
                    Directory.Delete(txtSavePath.Text + "\\" + txtProjectName.Text + ".gdb", true);
                }
                catch (Exception err2)
                { }
                return;
            }

            StringBuilder sb = new StringBuilder();

            foreach (ListViewItem aItem in listViewEx.CheckedItems)
            {
                if (sb.Length != 0)
                {
                    sb.Append("or");
                }
                else
                {
                    sb.Append("(");
                }

                sb.Append("(FromDate<='" + aItem.Text + "' and ToDate>'" + aItem.Text + "')");
            }

            sb.Append(")");

            //遍历数据FC进行数据移植
            (pTagetWorkspace as IWorkspaceEdit).StartEditing(false);
            progressBarXLay.Maximum = lstFeatLay.Count;
            progressBarXLay.Minimum = 0;
            progressBarXLay.Value   = 0;
            foreach (IFeatureLayer aFeatLay in lstFeatLay)
            {
                labelXMemo.Text = aFeatLay.FeatureClass.AliasName + "...";
                Application.DoEvents();

                StringBuilder newSB = new StringBuilder();
                newSB.Append(sb.ToString());

                if (m_Sel)
                {
                    int fdIndex = aFeatLay.FeatureClass.Fields.FindField("SourceOID");
                    if (fdIndex == -1)
                    {
                        continue;
                    }
                    IFeatureLayerDefinition featLayDefTemp = aFeatLay as IFeatureLayerDefinition;
                    IEnumIDs      pEnumIDs = featLayDefTemp.DefinitionSelectionSet.IDs;
                    int           ID       = pEnumIDs.Next();
                    StringBuilder sbTemp   = new StringBuilder();
                    while (ID != -1)
                    {
                        IFeature pFeat = aFeatLay.FeatureClass.GetFeature(ID);
                        if (sbTemp.Length != 0)
                        {
                            sbTemp.Append(",");
                        }
                        sbTemp.Append(pFeat.get_Value(fdIndex).ToString());
                        ID = pEnumIDs.Next();
                    }
                    newSB.Append(" and SourceOID in (" + sbTemp.ToString() + ")");
                }

                IQueryFilter queryFilter = new QueryFilterClass();
                queryFilter.WhereClause = newSB.ToString();
                IFeatureCursor featureCursor = aFeatLay.FeatureClass.Search(queryFilter, false);
                progressBarXFeat.Maximum = aFeatLay.FeatureClass.FeatureCount(queryFilter);
                progressBarXFeat.Minimum = 0;
                progressBarXFeat.Value   = 0;
                try
                {
                    //cyf 20110706 modify:去掉用户名
                    string pFeaLayerName = aFeatLay.Name.Trim();
                    if (pFeaLayerName.Contains("."))
                    {
                        pFeaLayerName = pFeaLayerName.Substring(pFeaLayerName.IndexOf('.') + 1);
                    }
                    //end
                    IFeatureClass tagetFeatCls = (pTagetWorkspace as IFeatureWorkspace).OpenFeatureClass(pFeaLayerName);//(aFeatLay.FeatureClass as IDataset).Name
                    ModDBOperator.NewFeatures(tagetFeatCls, featureCursor, null, null, true, false, progressBarXFeat, out err);
                }
                catch (Exception ex)
                {
                    //*******************************************************************
                    //guozheng added
                    if (ModData.SysLog != null)
                    {
                        ModData.SysLog.Write(ex, null, DateTime.Now);
                    }
                    else
                    {
                        ModData.SysLog = new SysCommon.Log.clsWriteSystemFunctionLog();
                        ModData.SysLog.Write(ex, null, DateTime.Now);
                    }
                    //********************************************************************
                    SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "入库失败!");
                    return;
                }

                Marshal.ReleaseComObject(featureCursor);
                progressBarXLay.Value++;

                labelXMemo.Text = "";
                Application.DoEvents();
                if (err != null)
                {
                    res = false;
                    break;
                }
            }

            (pTagetWorkspace as IWorkspaceEdit).StopEditing(res);

            this.Cursor = System.Windows.Forms.Cursors.Default;
            if (res)
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "提取成功!");
                this.Close();
            }
            else
            {
                SysCommon.Error.ErrorHandle.ShowFrmErrorHandle("提示", "提取失败!");
            }
        }
Ejemplo n.º 18
0
        public void CheckforGeoSpatialData(String strPath, String geoType, ListBox lstBox)
        {
            IWorkspaceFactory owrkspaceFact = null;
            IFeatureWorkspace theFWS;
            IFeatureClass theFClass;
            int FCount;

            try
            {
                switch (geoType)
                {
                    case "ShapeFile":
                        owrkspaceFact = new ShapefileWorkspaceFactory();
                        break;
                    default:
                        owrkspaceFact = new AccessWorkspaceFactoryClass();
                        break;
                }

                PropertySet pPropSet = new PropertySetClass();
                pPropSet.SetProperty("DATABASE", strPath);

                IWorkspace theWS = owrkspaceFact.Open(pPropSet, 0);
                theFWS = (IFeatureWorkspace)theWS;

                if (theWS != null)
                {
                    String[] theSrcNames = GeoDbProcs.GetFeatureClassNames(theWS);

                    foreach (String theSrcName in theSrcNames)
                    {
                        theFClass = theFWS.OpenFeatureClass(theSrcName);
                        lbSource.Items.Add(new FeatureData(theSrcName, theFClass));
                        Application.DoEvents();
                    }
                }
            }
            catch { }
        }