Exemplo n.º 1
0
        /// <summary>
        /// 生成检查数据库(Base库和Query库)
        /// </summary>
        /// <param name="strTaskPath">任务所在路径</param>
        /// <param name="strTaskName"></param>
        /// <param name="baseUseSource"></param>
        /// <param name="queryUseBase"></param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public static bool CreateCheckDB(string strTaskPath, string strTaskName, bool baseUseSource, bool queryUseBase, ref string errMsg)
        {
            string strPath = strTaskPath + "\\" + strTaskName;

            // Base 库
            if (!baseUseSource)
            {
                if (!AEAccessFactory.CreateFGDB(strPath, COMMONCONST.DB_Name_Base))
                {
                    errMsg = "创建Base库时出错";
                    return(false);
                }
            }

            // Query
            if (!queryUseBase)
            {
                if (!AEAccessFactory.CreatePGDB(strPath, COMMONCONST.DB_Name_Query))
                {
                    errMsg = "创建Query库出错";
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool PrepareForWorkspace(IWorkspace wsTarget, out string strBaseName, out string strQueryName, out enumDataType baseDataType)
        {
            strBaseName  = null;
            strQueryName = null;
            baseDataType = enumDataType.FileGDB;

            try
            {
                string      strPath    = wsTarget.PathName;
                IDataImport dataImport = new NoReferenceDataImport();
                dataImport.ImportingObjectChanged += new ImportingObjectChangedHandler(DataImport_ImportingObjectChanged);
                dataImport.Datasource              = strPath;
                dataImport.TargetPath              = TempPath;
                dataImport.JustCopy = true;

                // 获取空间参考
                ISpatialReference spatialRef = null;
                IEnumDataset      enDataset  = wsTarget.get_Datasets(esriDatasetType.esriDTAny);
                IDataset          dsCurrent  = enDataset.Next();
                while (dsCurrent != null)
                {
                    if (dsCurrent is IGeoDataset)
                    {
                        spatialRef = (dsCurrent as IGeoDataset).SpatialReference;
                        break;
                    }

                    dsCurrent = enDataset.Next();
                }
                dataImport.SpatialReference = spatialRef;
                enumDataType dataType = enumDataType.PGDB;

                // 设置数据类型
                string strName = System.IO.Path.GetExtension(strPath);
                if (string.IsNullOrEmpty(strName))  // Shp File
                {
                    dataType = enumDataType.SHP;
                }
                else if (strName.ToLower() == ".gdb")
                {
                    dataType = enumDataType.FileGDB;
                }
                else // MDB
                {
                    dataType = enumDataType.PGDB;
                }
                dataImport.DataType = dataType;
                if (dataType != enumDataType.PGDB)
                {
                    AEAccessFactory.CreatePGDB(TempPath, "Query.mdb");
                }

                dataImport.Import();

                // 获取Base/Query库Workspace和ADO连接
                strBaseName  = (dataType == enumDataType.PGDB ? "Base.mdb" : (dataType == enumDataType.FileGDB ? "Base.gdb" : "Base"));
                strQueryName = (dataType == enumDataType.PGDB ? strBaseName : "Query.mdb");
                baseDataType = dataType;

                return(true);
            }
            catch
            {
                return(false);
            }
        }