Пример #1
0
 public IFeatureWorkspace GetFeatureWorkspace(WorkspaceSource pSourceType, string sDataSource, string sService, string sInitialCatalog, string sVersion, string sUserID, string sPassword, bool bShowErr)
 {
     try
     {
         if (pSourceType != WorkspaceSource.esriWSSdeWorkspaceFactory)
         {
             return(null);
         }
         IWorkspace workspace = null;
         string     serr      = "";
         string     server    = sDataSource;
         string     instance  = sService;
         string     database  = sInitialCatalog;
         string     version   = sVersion;
         string     user      = sUserID;
         string     password  = sPassword;
         workspace = this.open_ArcSDE_Workspace(server, instance, user, password, database, version, out serr);
         if (workspace == null)
         {
             if (bShowErr)
             {
                 MessageBox.Show("服务名、服务器名、数据库名、用户名或密码输入错误", "数据源链接失败!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             return(null);
         }
         return(workspace as IFeatureWorkspace);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.WorkspaceFun", "GetFeatureWorkspace", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
Пример #2
0
 public IFeatureWorkspace GetFeatureWorkspace(WorkspaceSource pSourceType)
 {
     try
     {
         if (pSourceType != WorkspaceSource.esriWSSdeWorkspaceFactory)
         {
             return(null);
         }
         IWorkspace workspace = null;
         string     serr      = "";
         string     server    = UtilFactory.GetConfigOpt().GetConfigValue2("SqlServer", "DataSource");
         string     instance  = UtilFactory.GetConfigOpt().GetConfigValue2("SqlServer", "Service");
         string     database  = UtilFactory.GetConfigOpt().GetConfigValue2("SqlServer", "InitialCatalog");
         string     version   = UtilFactory.GetConfigOpt().GetConfigValue2("SqlServer", "Version");
         string     user      = UtilFactory.GetConfigOpt().GetConfigValue2("SqlServer", "UserID");
         string     password  = UtilFactory.GetConfigOpt().GetConfigValue2("SqlServer", "Password");
         workspace = this.open_ArcSDE_Workspace(server, instance, user, password, database, version, out serr);
         if (workspace == null)
         {
             MessageBox.Show("服务名、服务器名、数据库名、用户名或密码输入错误", "数据源链接失败!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return(null);
         }
         return(workspace as IFeatureWorkspace);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.WorkspaceFun", "GetFeatureWorkspace", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(null);
     }
 }
Пример #3
0
 public bool ClearFeatureData(string sSourceFile, WorkspaceSource pSourceType, string sFeatureClassName)
 {
     try
     {
         if (string.IsNullOrEmpty(sSourceFile) | string.IsNullOrEmpty(sFeatureClassName))
         {
             return(false);
         }
         IFeatureWorkspace featureWorkspace = null;
         featureWorkspace = GISFunFactory.WorkspaceFun.GetFeatureWorkspace(sSourceFile, pSourceType);
         if (featureWorkspace == null)
         {
             return(false);
         }
         IFeatureClass class2 = null;
         class2 = featureWorkspace.OpenFeatureClass(sFeatureClassName);
         if (class2 == null)
         {
             return(false);
         }
         if (class2.FeatureCount(null) != 0)
         {
             IWorkspaceEdit edit = null;
             edit = featureWorkspace as IWorkspaceEdit;
             edit.StartEditing(false);
             IFeatureCursor cursor = null;
             cursor = class2.Search(null, false);
             IFeature feature = null;
             for (feature = cursor.NextFeature(); feature != null; feature = cursor.NextFeature())
             {
                 feature.Delete();
             }
             edit.StopEditing(true);
         }
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.FeatureFun", "GetFeatureWorkspace", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Пример #4
0
 public bool SetFeatureLayerSource(IFeatureLayer pFeatureLayer, string sSourceFile, WorkspaceSource pSourceType, string sFeatureClassName)
 {
     try
     {
         if (pFeatureLayer == null)
         {
             return(false);
         }
         if (string.IsNullOrEmpty(sSourceFile) | string.IsNullOrEmpty(sFeatureClassName))
         {
             return(false);
         }
         IFeatureWorkspace featureWorkspace = null;
         featureWorkspace = GISFunFactory.WorkspaceFun.GetFeatureWorkspace(sSourceFile, pSourceType);
         if (featureWorkspace == null)
         {
             return(false);
         }
         IFeatureClass class2 = null;
         class2 = featureWorkspace.OpenFeatureClass(sFeatureClassName);
         if (class2 == null)
         {
             return(false);
         }
         pFeatureLayer.FeatureClass = class2;
         return(true);
     }
     catch (Exception exception)
     {
         this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.FeatureFun", "SetFeatureLayerSource", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
         return(false);
     }
 }
Пример #5
0
        /// <summary>
        /// 获取初始化后的各种工作空间
        /// </summary>
        /// <param name="sSourceFile"></param>
        /// <param name="pSourceType"></param>
        /// <returns></returns>
        public IFeatureWorkspace GetFeatureWorkspace(string sSourceFile, WorkspaceSource pSourceType)
        {
            try
            {
                if ((string.IsNullOrEmpty(sSourceFile) | !File.Exists(sSourceFile)) & (string.IsNullOrEmpty(sSourceFile) | !Directory.Exists(sSourceFile)))
                {
                    MessageBox.Show("数据文件 " + sSourceFile + " 丢失。", "打开工作空间错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(null);
                }
                IWorkspaceFactory factory = null;
                WorkspaceSource   source  = pSourceType;
                if (source <= WorkspaceSource.esriWSStreetMapWorkspaceFactory)
                {
                    if (source < WorkspaceSource.esriWSAccessWorkspaceFactory)
                    {
                        goto Label_010D;//当source<1.返回空
                    }
                    switch (((int)(source - 1L)))
                    {
                    case 0:
                        factory = new AccessWorkspaceFactoryClass();
                        goto Label_0111;

                    case 1:
                    case 4:
                    case 5:
                    case 7:
                    case 8:
                    case 10:
                        goto Label_010D;

                    case 2:
                        factory = new ArcInfoWorkspaceFactoryClass();
                        goto Label_0111;

                    case 3:
                        factory = new CadWorkspaceFactoryClass();
                        goto Label_0111;

                    case 6:
                        factory = new PCCoverageWorkspaceFactoryClass();
                        goto Label_0111;

                    case 9:
                        factory = new SDCWorkspaceFactoryClass();
                        goto Label_0111;

                    case 11:
                        factory = new ShapefileWorkspaceFactoryClass();
                        goto Label_0111;

                    case 12:
                        factory = new StreetMapWorkspaceFactoryClass() as IWorkspaceFactory;
                        goto Label_0111;
                    }
                }
                if ((source <= WorkspaceSource.esriWSFileGDBWorkspaceFactory) && (source >= WorkspaceSource.esriWSVpfWorkspaceFactory))
                {
                    switch (((int)(source - 0x11L)))
                    {
                    case 0:
                        factory = new VpfWorkspaceFactoryClass();
                        goto Label_0111;

                    case 1:
                        factory = new FileGDBWorkspaceFactoryClass();
                        goto Label_0111;
                    }
                }
Label_010D:
                return(null);//返回空

Label_0111:
                if (!factory.IsWorkspace(sSourceFile))
                {
                    return(null);
                }
                return(factory.OpenFromFile(sSourceFile, 0) as IFeatureWorkspace);
            }
            catch (Exception exception)
            {
                this.mErrOpt.ErrorOperate(this.mSubSysName, "FunFactory.WorkspaceFun", "GetFeatureWorkspace", exception.GetHashCode().ToString(), exception.Source, exception.Message, "", "", "");
                return(null);
            }
        }