Ejemplo n.º 1
0
        /// <summary>
        /// 重置图层数据源
        /// </summary>
        /// <param name="pLayer"></param>
        /// <param name="pNewWksp"></param>
        /// <returns></returns>
        public static bool ResetLayerDatasource(IDataLayer2 pLayer, IWorkspace pNewWksp)
        {
            if (pLayer == null || pNewWksp == null)
            {
                return(false);
            }

            //// 2012-06-15 张航宇
            //// 直接获取Layer的数据源名称,从新的Workspace打开FeatureClass进行替换
            //IDatasetName fClassName = pLayer.DataSourceName as IDatasetName;
            //if (fClassName != null)
            //{
            //    string strClassName = fClassName.Name;
            //    try
            //    {
            //        IFeatureClass fClass = (pNewWksp as IFeatureWorkspace).OpenFeatureClass(strClassName);
            //        pLayer.DataSourceName = (fClass as IDataset).FullName;
            //    }
            //    catch
            //    {
            //        return false;
            //    }
            //}

            IEnumDatasetName pEnumDsName = pNewWksp.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
            IDatasetName     pFtDsName   = pEnumDsName.Next();

            try
            {
                if (!pLayer.InWorkspace(pNewWksp))
                {
                    IFeatureClassName pOldName = pLayer.DataSourceName as IFeatureClassName;
                    // 2012-06-15 张航宇
                    // 修改对没有Dataset的Workspace,直接将Workspace重置
                    if (pOldName != null)
                    {
                        if (pOldName.FeatureDatasetName == null || pFtDsName == null)
                        {
                            (pOldName as IDatasetName).WorkspaceName = (pNewWksp as IDataset).FullName as IWorkspaceName;
                        }
                        else
                        {
                            pOldName.FeatureDatasetName = pFtDsName;
                            pOldName.FeatureDatasetName.WorkspaceName = ((IDataset)pNewWksp).FullName as IWorkspaceName;
                        }
                    }
                    pLayer.Connect(pOldName as IName);
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 重置图层数据源
        /// </summary>
        /// <param name="pLayer"></param>
        /// <param name="pNewWksp"></param>
        /// <returns></returns>
        public static bool ResetLayerDatasource2(IDataLayer2 pLayer, IWorkspace pNewWksp)
        {
            if (pLayer == null || pNewWksp == null)
            {
                return(false);
            }
            IEnumDataset pEnumDsName = pNewWksp.get_Datasets(esriDatasetType.esriDTFeatureDataset);
            IDataset     pFtDsName   = pEnumDsName.Next();
            IEnumDataset pEnumDs     = pFtDsName.Subsets;

            try
            {
                if (!pLayer.InWorkspace(pNewWksp))
                {
                    IFeatureClassName pOldName = pLayer.DataSourceName as IFeatureClassName;

                    if (pOldName != null)
                    {
                        IDatasetName dsName = pOldName as IDatasetName;
                        IDataset     pDs    = null;
                        while ((pDs = pEnumDs.Next()) != null)
                        {
                            if (dsName.Name.Equals(pDs.Name, StringComparison.OrdinalIgnoreCase) ||
                                pDs.Name.Contains(dsName.Name.ToUpper()))
                            {
                                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                                if (pFeatureLayer == null)
                                {
                                    return(true);
                                }
                                pFeatureLayer.FeatureClass = pDs as IFeatureClass;
                                return(true);
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 重置图层数据源
        /// </summary>
        /// <param name="pLayer"></param>
        /// <param name="pNewWksp"></param>
        /// <returns></returns>
        public static bool ResetLayerDatasource2(IDataLayer2 pLayer, IWorkspace pNewWksp)
        {
            if (pLayer == null || pNewWksp == null) return false;
            IEnumDataset pEnumDsName = pNewWksp.get_Datasets(esriDatasetType.esriDTFeatureDataset);
            IDataset pFtDsName = pEnumDsName.Next();
            IEnumDataset pEnumDs = pFtDsName.Subsets;
            try
            {
                if (!pLayer.InWorkspace(pNewWksp))
                {
                    IFeatureClassName pOldName = pLayer.DataSourceName as IFeatureClassName;

                    if (pOldName != null)
                    {
                        IDatasetName dsName = pOldName as IDatasetName;
                        IDataset pDs = null;
                        while ((pDs = pEnumDs.Next()) != null)
                        {
                            if (dsName.Name.Equals(pDs.Name, StringComparison.OrdinalIgnoreCase) ||
                                pDs.Name.Contains(dsName.Name.ToUpper()))
                            {
                                IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
                                if (pFeatureLayer == null) return true;
                                pFeatureLayer.FeatureClass = pDs as IFeatureClass;
                                return true;
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return false;
            }
            return true;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 重置图层数据源
        /// </summary>
        /// <param name="pLayer"></param>
        /// <param name="pNewWksp"></param>
        /// <returns></returns>
        public static bool ResetLayerDatasource(IDataLayer2 pLayer, IWorkspace pNewWksp)
        {
            if (pLayer == null || pNewWksp == null) return false;

            //// 2012-06-15 张航宇
            //// 直接获取Layer的数据源名称,从新的Workspace打开FeatureClass进行替换
            //IDatasetName fClassName = pLayer.DataSourceName as IDatasetName;
            //if (fClassName != null)
            //{
            //    string strClassName = fClassName.Name;
            //    try
            //    {
            //        IFeatureClass fClass = (pNewWksp as IFeatureWorkspace).OpenFeatureClass(strClassName);
            //        pLayer.DataSourceName = (fClass as IDataset).FullName;
            //    }
            //    catch
            //    {
            //        return false;
            //    }
            //}

            IEnumDatasetName pEnumDsName = pNewWksp.get_DatasetNames(esriDatasetType.esriDTFeatureDataset);
            IDatasetName pFtDsName = pEnumDsName.Next();
            try
            {
                if (!pLayer.InWorkspace(pNewWksp))
                {
                    IFeatureClassName pOldName = pLayer.DataSourceName as IFeatureClassName;
                    // 2012-06-15 张航宇
                    // 修改对没有Dataset的Workspace,直接将Workspace重置
                    if (pOldName != null)
                    {
                        if (pOldName.FeatureDatasetName == null || pFtDsName == null)
                        {
                            (pOldName as IDatasetName).WorkspaceName = (pNewWksp as IDataset).FullName as IWorkspaceName;
                        }
                        else
                        {
                            pOldName.FeatureDatasetName = pFtDsName;
                            pOldName.FeatureDatasetName.WorkspaceName = ((IDataset)pNewWksp).FullName as IWorkspaceName;
                        }
                    }
                    pLayer.Connect(pOldName as IName);
                }
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return false;
            }
            return true;
        }