private void tlsbtnShowCopyPanel_Click(object sender, EventArgs e)
        {
            #region "Open the Database to Copy From"

            findDatabase:
            // Check the registry
            string regValue = commonFunctions.ReadReg("Software\\NCGMPTools", "getSqlDatabase");

            // Find a Database
            IWorkspaceFactory wsFact = null;
            IWorkspace openedWorkspace = null;

            // Browse for a file, personal or SDE geodatabase
            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an NCGMP database");
            if (openedObject == null) { return; }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;

            switch (openedObject.Category)
            {
                case "Personal Geodatabase":
                    wsFact = new AccessWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "File Geodatabase":
                    wsFact = new FileGDBWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "Spatial Database Connection":
                case "Database Connection":
                    wsFact = new SdeWorkspaceFactoryClass();
                    IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                    pathToOpen = remoteDatabaseFolder.Path + openedObject.Name;
                    break;
                default:
                    break;
            }
            openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);

            // Check to see if the database is valid NCGMP
            bool isValid = ncgmpChecks.IsWorkspaceMinNCGMPCompliant(openedWorkspace);
            if (isValid == false)
            {
                MessageBox.Show("The selected database is not a valid NCGMP database.", "NCGMP Toolbar");
                goto findDatabase;
            }
            //else
            //{
            //    isValid = ncgmpChecks.IsSysInfoPresent(openedWorkspace);
            //    if (isValid == false)
            //    {
            //        MessageBox.Show("In order to use these tools, the NCGMP database must contain a SysInfo table.", "NCGMP Toolbar");
            //        goto findDatabase;
            //    }
            //}
            #endregion

            // Show the copy form
            sourceLegendItemSelection sourceForm = new sourceLegendItemSelection(openedWorkspace);
            sourceForm.ShowDialog();

            // Bail if they canceled
            if (sourceForm.Canceled == true) { return; }

            // Get the Ids from the form, then close it
            if (sourceForm.idsToCopy.Count == 0) { sourceForm.Close(); return; }
            List<string> idsToCopy = sourceForm.idsToCopy;
            sourceForm.Close();

            // Build the Query to get the records to copy
            string sqlWhereClause = "DescriptionOfMapUnits_ID = '";
            foreach (string idValue in idsToCopy) { sqlWhereClause += idValue + "' OR DescriptionOfMapUnits_ID = '"; }

            // Get the records
            if (sqlWhereClause == "DescriptionOfMapUnits_ID = '") { return; }
            DescriptionOfMapUnitsAccess sourceDmu = new DescriptionOfMapUnitsAccess(openedWorkspace);
            sourceDmu.AddDescriptionOfMapUnits(sqlWhereClause.Remove(sqlWhereClause.Length - 32));

            // Get the next new Hierarchy Key
            string newHierarchy = GetNewHierarchyKey();
            int newValue = int.Parse(newHierarchy.Substring(newHierarchy.Length - 4));

            // Loop through the source records, add them to the target legend after adjusting the Hierarchy
            DescriptionOfMapUnitsAccess targetDmu = new DescriptionOfMapUnitsAccess(m_theWorkspace);
            foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> sourceEntry in sourceDmu.DescriptionOfMapUnitsDictionary)
            {
                DescriptionOfMapUnitsAccess.DescriptionOfMapUnit sourceDmuEntry = sourceEntry.Value;
                string thisHierachyKey = newValue.ToString().PadLeft(4, '0');

                targetDmu.NewDescriptionOfMapUnit(sourceDmuEntry.MapUnit, sourceDmuEntry.Name, sourceDmuEntry.FullName, sourceDmuEntry.Label,
                    sourceDmuEntry.Age, sourceDmuEntry.Description, thisHierachyKey,
                    sourceDmuEntry.ParagraphStyle, sourceDmuEntry.AreaFillRGB, sourceDmuEntry.AreaFillPatternDescription,
                    commonFunctions.GetCurrentDataSourceID(), sourceDmuEntry.GeneralLithology, sourceDmuEntry.GeneralLithologyConfidence);

                newValue++;
            }

            // Save the target Dmu
            targetDmu.SaveDescriptionOfMapUnits();

            // Refresh the tree
            ClearMapUnitInput();
            PopulateMainLegendTree();
        }
Пример #2
0
        public static void ExportDatabase(IWorkspace theWorkspace)
        {
            // Try and make sure the user understands what they're doing
            MessageBox.Show("You must first browse to a previously generated, empty geodatabase.", "NCGMP Tools");

            // Browse for a file, personal or SDE geodatabase
            IWorkspaceFactory wsFact          = null;
            IWorkspace        openedWorkspace = null;

            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject       openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an empty database");

            if (openedObject == null)
            {
                return;
            }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;

            switch (openedObject.Category)
            {
            case "Personal Geodatabase":
                wsFact     = new AccessWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "File Geodatabase":
                wsFact     = new FileGDBWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "Spatial Database Connection":
                wsFact = new SdeWorkspaceFactoryClass();
                IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                pathToOpen = remoteDatabaseFolder.Path + openedObject.Name;
                break;

            default:
                break;
            }
            openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);

            // Okay, now export the current database to an XML doc
            string tempFilePath = System.IO.Path.GetTempFileName();

            tempFilePath += ".xml";

            IGdbXmlExport xmlExporter = new GdbExporterClass();

            xmlExporter.ExportWorkspace(theWorkspace, tempFilePath, true, false, false);

            // Import to the new database
            // Use the temp file to perform the import
            IGdbXmlImport    xmlImporter     = new GdbImporterClass();
            IEnumNameMapping enumNameMapping = null;
            bool             conflictsFound  = xmlImporter.GenerateNameMapping(tempFilePath, openedWorkspace, out enumNameMapping);

            try
            {
                // Deal with conflicts (lifted wholesale from http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000011m000000.htm)
                if (conflictsFound)
                {
                    IName workspaceName = ((IDataset)openedWorkspace).FullName;

                    // Iterate through each name mapping.
                    INameMapping nameMapping = null;
                    enumNameMapping.Reset();
                    while ((nameMapping = enumNameMapping.Next()) != null)
                    {
                        // Resolve the mapping's conflict (if there is one).
                        if (nameMapping.NameConflicts)
                        {
                            nameMapping.TargetName = nameMapping.GetSuggestedName(workspaceName);
                        }
                        // See if the mapping's children have conflicts.
                        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                        if (childEnumNameMapping != null)
                        {
                            childEnumNameMapping.Reset();
                            // Iterate through each child mapping.
                            INameMapping childNameMapping = null;
                            while ((childNameMapping = childEnumNameMapping.Next()) != null)
                            {
                                if (childNameMapping.NameConflicts)
                                {
                                    childNameMapping.TargetName = nameMapping.GetSuggestedName
                                                                      (workspaceName);
                                }
                            }
                        }
                    }
                }

                // Perform the import
                xmlImporter.ImportWorkspace(tempFilePath, enumNameMapping, openedWorkspace, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine + "XML Workspace Doc written to: " + tempFilePath);
            }


            // Perhaps, strip the SysInfo table
        }
        protected override void OnClick()
        {
findDatabase:
            // Check the registry
            // Find a Database
            IWorkspaceFactory wsFact = null;
            IWorkspace openedWorkspace = null;

            // Browse for a file, personal or SDE geodatabase
            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject       openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an NCGMP database");

            if (openedObject == null)
            {
                return;
            }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;
            IGxRemoteDatabaseFolder remoteDatabaseFolder;

            switch (openedObject.Category)
            {
            case "Personal Geodatabase":
                wsFact     = new AccessWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "File Geodatabase":
                wsFact     = new FileGDBWorkspaceFactoryClass();
                pathToOpen = openedObject.FullName;
                break;

            case "Spatial Database Connection":
                wsFact = new SdeWorkspaceFactoryClass();
                remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                pathToOpen           = remoteDatabaseFolder.Path + "\\" + openedObject.Name;
                break;

            case "Database Connection":
                wsFact = new SdeWorkspaceFactoryClass();
                remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                pathToOpen           = remoteDatabaseFolder.Path + "\\" + openedObject.Name;
                break;

            default:
                break;
            }

            try
            {
                openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            // Check to see if the database is valid NCGMP
            bool isValid = ncgmpChecks.IsWorkspaceMinNCGMPCompliant(openedWorkspace);

            if (isValid == false)
            {
                MessageBox.Show("The selected database is not a valid NCGMP database.", "NCGMP Toolbar");
                goto findDatabase;
            }
            //else
            //{
            //    isValid = ncgmpChecks.IsSysInfoPresent(openedWorkspace);
            //    if (isValid == false)
            //    {
            //        MessageBox.Show("In order to use these tools, the NCGMP database must contain a SysInfo table.", "NCGMP Toolbar");
            //        goto findDatabase;
            //    }
            //}

            //bool isTopologyUsed = ncgmpChecks.IsTopologyUsed(openedWorkspace);
            //bool hasStationTables = ncgmpChecks.IsAzgsStationAddinPresent(openedWorkspace);
            //bool hasStandardLithtables = ncgmpChecks.IsStandardLithAddinPresent(openedWorkspace);
            bool hasRepresentations = ncgmpChecks.AreRepresentationsUsed(openedWorkspace);

            // Add FeatureClasses and tables to the ArcMap Project
            AddLayersToMap(openedWorkspace, hasRepresentations); // isTopologyUsed, hasStationTables,


            // Populate the Data Sources combobox
        }
        protected override void OnClick()
        {
            //          string getSqlDatabase = "False";
            findDatabase:
            // Check the registry
            // Find a Database
            IWorkspaceFactory wsFact = null;
            IWorkspace openedWorkspace = null;

            // Browse for a file, personal or SDE geodatabase
            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an NCGMP database");
            if (openedObject == null) { return;  }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;

            switch (openedObject.Category)
            {
                case "Personal Geodatabase":
                    wsFact = new AccessWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "File Geodatabase":
                    wsFact = new FileGDBWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "Spatial Database Connection":
                    wsFact = new SdeWorkspaceFactoryClass();
                    IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                    pathToOpen = remoteDatabaseFolder.Path + "\\" + openedObject.Name;
                    break;
                default:
                    break;
            }

            try
            {
                openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            // Check to see if the database is valid NCGMP
            bool isValid = ncgmpChecks.IsWorkspaceMinNCGMPCompliant(openedWorkspace);
            if (isValid == false)
            {
                MessageBox.Show("The selected database is not a valid NCGMP database.", "NCGMP Toolbar");
                goto findDatabase;
            }
            else
            {
                isValid = ncgmpChecks.IsSysInfoPresent(openedWorkspace);
                if (isValid == false)
                {
                    MessageBox.Show("In order to use these tools, the NCGMP database must contain a SysInfo table.", "NCGMP Toolbar");
                    goto findDatabase;
                }
            }

            bool isTopologyUsed = ncgmpChecks.IsTopologyUsed(openedWorkspace);
            bool hasStationTables = ncgmpChecks.IsAzgsStationAddinPresent(openedWorkspace);
            bool hasStandardLithtables = ncgmpChecks.IsStandardLithAddinPresent(openedWorkspace);
            bool hasRepresentations = ncgmpChecks.AreRepresentationsUsed(openedWorkspace);

            // Add FeatureClasses and tables to the ArcMap Project
            AddLayersToMap(openedWorkspace, isTopologyUsed, hasStationTables, hasRepresentations);

            // Populate the Data Sources combobox
        }
Пример #5
0
        public static void ExportDatabase(IWorkspace theWorkspace)
        {
            // Try and make sure the user understands what they're doing
            MessageBox.Show("You must first browse to a previously generated, empty geodatabase.", "NCGMP Tools");

            // Browse for a file, personal or SDE geodatabase
            IWorkspaceFactory wsFact = null;
            IWorkspace openedWorkspace = null;

            IGxObjectFilter objectFilter = new GxFilterWorkspaces();
            IGxObject openedObject = commonFunctions.OpenArcFile(objectFilter, "Please select an empty database");
            if (openedObject == null) { return; }

            // Check to see if it is a File, Personal or SDE database, create appropriate workspace factory
            string pathToOpen = null;

            switch (openedObject.Category)
            {
                case "Personal Geodatabase":
                    wsFact = new AccessWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "File Geodatabase":
                    wsFact = new FileGDBWorkspaceFactoryClass();
                    pathToOpen = openedObject.FullName;
                    break;
                case "Spatial Database Connection":
                    wsFact = new SdeWorkspaceFactoryClass();
                    IGxRemoteDatabaseFolder remoteDatabaseFolder = (IGxRemoteDatabaseFolder)openedObject.Parent;
                    pathToOpen = remoteDatabaseFolder.Path + openedObject.Name;
                    break;
                default:
                    break;
            }
            openedWorkspace = wsFact.OpenFromFile(pathToOpen, 0);

            // Okay, now export the current database to an XML doc
            string tempFilePath = System.IO.Path.GetTempFileName();
            tempFilePath += ".xml";

            IGdbXmlExport xmlExporter = new GdbExporterClass();
            xmlExporter.ExportWorkspace(theWorkspace, tempFilePath, true, false, false);

            // Import to the new database
            // Use the temp file to perform the import
            IGdbXmlImport xmlImporter = new GdbImporterClass();
            IEnumNameMapping enumNameMapping = null;
            bool conflictsFound = xmlImporter.GenerateNameMapping(tempFilePath, openedWorkspace, out enumNameMapping);

            try
            {
                // Deal with conflicts (lifted wholesale from http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/00010000011m000000.htm)
                if (conflictsFound)
                {
                    IName workspaceName = ((IDataset)openedWorkspace).FullName;

                    // Iterate through each name mapping.
                    INameMapping nameMapping = null;
                    enumNameMapping.Reset();
                    while ((nameMapping = enumNameMapping.Next()) != null)
                    {
                        // Resolve the mapping's conflict (if there is one).
                        if (nameMapping.NameConflicts)
                        {
                            nameMapping.TargetName = nameMapping.GetSuggestedName(workspaceName);
                        }
                        // See if the mapping's children have conflicts.
                        IEnumNameMapping childEnumNameMapping = nameMapping.Children;
                        if (childEnumNameMapping != null)
                        {
                            childEnumNameMapping.Reset();
                            // Iterate through each child mapping.
                            INameMapping childNameMapping = null;
                            while ((childNameMapping = childEnumNameMapping.Next()) != null)
                            {
                                if (childNameMapping.NameConflicts)
                                {
                                    childNameMapping.TargetName = nameMapping.GetSuggestedName
                                        (workspaceName);
                                }
                            }
                        }
                    }
                }

                // Perform the import
                xmlImporter.ImportWorkspace(tempFilePath, enumNameMapping, openedWorkspace, false);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + Environment.NewLine + "XML Workspace Doc written to: " + tempFilePath);
            }

            // Perhaps, strip the SysInfo table
        }