Exemplo n.º 1
0
        private Dictionary<string, object> BuildDataAccessFromSelection()
        {
            // Will be building SQL Where Clauses for each possible selected thing
            string MapUnitPolysSearch = "MapUnitPolys_ID = '";
            string DataSourcePolysSearch = "DataSourcePolys_ID = '";
            string OtherPolysSearch = "OtherPolys_ID = '";
            string ContactsAndFaultsSearch = "ContactsAndFaults_ID = '";
            string GeologicLinesSearch = "GeologicLines_ID = '";
            string StationsSearch = "Stations_ID = '";
            string GenericSamplesSearch = "GenericSamples_ID = '";
            string OrientationPointsSearch = "OrientationPoints_ID = '";
            string GlossarySearch = "Glossary_ID = '";
            string DataSourcesSearch = "DataSources_ID = '";
            string DescriptionOfMapUnitsSearch = "DescriptionOfMapUnits_ID = '";

            // This object will be populated and returned
            Dictionary<string, object> dataAccessClasses = new Dictionary<string, object>();

            #region Selected FEATURES
            // Get an enumeration of the selected features
            IEnumFeature selectionEnum = ArcMap.Document.FocusMap.FeatureSelection as IEnumFeature;

            // Loop through the features to build queries to find the features
            IRow thisFeature = selectionEnum.Next() as IRow;

            while (thisFeature != null)
            {
                // Get the Table Name
                string tableName = (thisFeature.Table as IDataset).Name;

                // Parse the table name in order to strip out unneccessary bits of SDE tables
                ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace;
                string parsedDbName, parsedOwnerName, parsedTableName;
                nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName);

                // Build the SQL Where Clause depending on the table...
                switch (parsedTableName)
                {
                    case "MapUnitPolys":
                        MapUnitPolysSearch += thisFeature.get_Value(thisFeature.Table.FindField("MapUnitPolys_ID")) + "' OR MapUnitPolys_ID = '";
                        break;
                    case "DataSourcePolys":
                        DataSourcePolysSearch += thisFeature.get_Value(thisFeature.Table.FindField("DataSourcePolys_ID")) + "' OR DataSourcePolys_ID = '";
                        break;
                    case "OtherPolys":
                        OtherPolysSearch += thisFeature.get_Value(thisFeature.Table.FindField("OtherPolys_ID")) + "' OR OtherPolys_ID = '";
                        break;
                    case "ContactsAndFaults":
                        ContactsAndFaultsSearch += thisFeature.get_Value(thisFeature.Table.FindField("ContactsAndFaults_ID")) + "' OR ContactsAndFaults_ID = '";
                        break;
                    case "GeologicLines":
                        GeologicLinesSearch += thisFeature.get_Value(thisFeature.Table.FindField("GeologicLines_ID")) + "' OR GeologicLines_ID = '";
                        break;
                    case "Stations":
                        StationsSearch += thisFeature.get_Value(thisFeature.Table.FindField("Stations_ID")) + "' OR Stations_ID = '";
                        break;
                    case "GenericSamples":
                        GenericSamplesSearch += thisFeature.get_Value(thisFeature.Table.FindField("GenericSamples_ID")) + "' OR GenericSamples_ID = '";
                        break;
                    case "OrientationPoints":
                        OrientationPointsSearch += thisFeature.get_Value(thisFeature.Table.FindField("OrientationPoints_ID")) + "' OR OrientationPoints_ID = '";
                        break;
                }

                // Iterate the enumeration
                thisFeature = selectionEnum.Next();
            }

            #region "Build Dictionary"
            // Clean up the Where Clauses, create the data access classes, and then add it to the dictionary

            // MapUnitPolys
            if (MapUnitPolysSearch != "MapUnitPolys_ID = '")
            {
                MapUnitPolysSearch = MapUnitPolysSearch.Remove(MapUnitPolysSearch.Length - 23);
                MapUnitPolysAccess MapUnitPolysRecords = new MapUnitPolysAccess(m_theWorkspace);
                MapUnitPolysRecords.AddMapUnitPolys(MapUnitPolysSearch);
                dataAccessClasses.Add("MapUnitPolys", MapUnitPolysRecords);
            }

            if (DataSourcePolysSearch != "DataSourcePolys_ID = '")
            {
                DataSourcePolysSearch = DataSourcePolysSearch.Remove(DataSourcePolysSearch.Length - 25);
                DataSourcePolysAccess DataSourcePolysRecords = new DataSourcePolysAccess(m_theWorkspace);
                DataSourcePolysRecords.AddDataSourcePolys(DataSourcePolysSearch);
                dataAccessClasses.Add("DataSourcePolys", DataSourcePolysRecords);
            }

            // OtherPolys
            if (OtherPolysSearch != "OtherPolys_ID = '")
            {
                OtherPolysSearch = OtherPolysSearch.Remove(OtherPolysSearch.Length - 23);
                OtherPolysAccess OtherPolysRecords = new OtherPolysAccess(m_theWorkspace);
                OtherPolysRecords.AddOtherPolys(OtherPolysSearch);
                dataAccessClasses.Add("OtherPolys", OtherPolysRecords);
            }

            // ContactsAndFaults
            if (ContactsAndFaultsSearch != "ContactsAndFaults_ID = '")
            {
                ContactsAndFaultsSearch = ContactsAndFaultsSearch.Remove(ContactsAndFaultsSearch.Length - 28);
                ContactsAndFaultsAccess ContactsAndFaultsRecords = new ContactsAndFaultsAccess(m_theWorkspace);
                ContactsAndFaultsRecords.AddContactsAndFaults(ContactsAndFaultsSearch);
                dataAccessClasses.Add("ContactsAndFaults", ContactsAndFaultsRecords);
            }

            // GeologicLines
            if (GeologicLinesSearch != "GeologicLines_ID = '")
            {
                GeologicLinesSearch = GeologicLinesSearch.Remove(GeologicLinesSearch.Length - 24);
                GeologicLinesAccess GeologicLinesRecords = new GeologicLinesAccess(m_theWorkspace);
                GeologicLinesRecords.AddGeologicLines(GeologicLinesSearch);
                dataAccessClasses.Add("GeologicLines", GeologicLinesRecords);
            }

            // Stations
            if (StationsSearch != "Stations_ID = '")
            {
                StationsSearch = StationsSearch.Remove(StationsSearch.Length - 19);
                StationsAccess StationsRecords = new StationsAccess(m_theWorkspace);
                StationsRecords.AddStations(StationsSearch);
                dataAccessClasses.Add("Stations", StationsRecords);
            }

            // GenericSamples
            if (GenericSamplesSearch != "GenericSamples_ID = '")
            {
                GenericSamplesSearch = GenericSamplesSearch.Remove(GenericSamplesSearch.Length - 23);
                GenericSamplesAccess GenericSamplesRecords = new GenericSamplesAccess(m_theWorkspace);
                GenericSamplesRecords.AddGenericSamples(GenericSamplesSearch);
                dataAccessClasses.Add("GenericSamples", GenericSamplesRecords);
            }

            // OrientationPoints
            if (OrientationPointsSearch != "OrientationPoints_ID = '")
            {
                OrientationPointsSearch = OrientationPointsSearch.Remove(OrientationPointsSearch.Length - 32);
                OrientationPointsAccess OrientationPointsRecords = new OrientationPointsAccess(m_theWorkspace);
                OrientationPointsRecords.AddOrientationPoints(OrientationPointsSearch);
                dataAccessClasses.Add("OrientationPoints", OrientationPointsRecords);
            }

            #endregion

            #endregion

            #region Selected TABLE ROWS
            // Loop through the tables in the map
            IStandaloneTableCollection tableCollection = ArcMap.Document.FocusMap as IStandaloneTableCollection;
            for (int i = 0; i <= tableCollection.StandaloneTableCount - 1; i++)
            {
                // Get one of the tables
                IStandaloneTable thisTable = tableCollection.StandaloneTable[i];
                string tableName = null;
                if (thisTable.Table == null)
                    tableName = thisTable.Name;
                else
                    tableName = (thisTable.Table as IDataset).Name;

                // Parse the table name in order to strip out unneccessary bits of SDE tables
                ISQLSyntax nameParser = (ISQLSyntax)m_theWorkspace;
                string parsedDbName, parsedOwnerName, parsedTableName;
                nameParser.ParseTableName(tableName, out parsedDbName, out parsedOwnerName, out parsedTableName);

                // Find the selection
                ITableSelection selectedRows = thisTable as ITableSelection;
                ISelectionSet theSelection = selectedRows.SelectionSet;

                // Iterate if there are no selected rows
                if (theSelection == null)
                    continue;
                else
                    if (theSelection.Count == 0)
                        continue;

                // Loop through selected rows, build the where clauses up.
                ICursor theCursor;
                theSelection.Search(null, false, out theCursor);

                IRow theRow = theCursor.NextRow();
                while (theRow != null)
                {
                    switch (parsedTableName)
                    {
                        case "Glossary":
                            GlossarySearch += theRow.get_Value(thisTable.Table.FindField("Glossary_ID")) + "' OR Glossary_ID = '";
                            break;
                        case "DataSources":
                            DataSourcesSearch += theRow.get_Value(thisTable.Table.FindField("DataSources_ID")) + "' OR DataSources_ID = '";
                            break;
                        case "DescriptionOfMapUnits":
                            DescriptionOfMapUnitsSearch += theRow.get_Value(thisTable.Table.FindField("DescriptionOfMapUnits_ID")) + "' OR DescriptionOfMapUnits_ID = '";
                            break;
                    }

                    // Iterate
                    theRow = theCursor.NextRow();
                }
            }

            #region Build Dictionary
            // Clean up the Where Clauses, create the data access classes, and then add it to the dictionary

            // Glossary
            if (GlossarySearch != "Glossary_ID = '")
            {
                GlossarySearch = GlossarySearch.Remove(GlossarySearch.Length - 19);
                GlossaryAccess GlossaryRecords = new GlossaryAccess(m_theWorkspace);
                GlossaryRecords.AddGlossary(GlossarySearch);
                dataAccessClasses.Add("Glossary", GlossaryRecords);
            }

            // DataSources
            if (DataSourcesSearch != "DataSources_ID = '")
            {
                DataSourcesSearch = DataSourcesSearch.Remove(DataSourcesSearch.Length - 22);
                DataSourcesAccess DataSourcesRecords = new DataSourcesAccess(m_theWorkspace);
                DataSourcesRecords.AddDataSources(DataSourcesSearch);
                dataAccessClasses.Add("DataSources", DataSourcesRecords);
            }

            // DescriptionOfMapUnits
            if (DescriptionOfMapUnitsSearch != "DescriptionOfMapUnits_ID = '")
            {
                DescriptionOfMapUnitsSearch = DescriptionOfMapUnitsSearch.Remove(DescriptionOfMapUnitsSearch.Length - 32);
                DescriptionOfMapUnitsAccess DescriptionOfMapUnitsRecords = new DescriptionOfMapUnitsAccess(m_theWorkspace);
                DescriptionOfMapUnitsRecords.AddDescriptionOfMapUnits(DescriptionOfMapUnitsSearch);
                dataAccessClasses.Add("DescriptionOfMapUnits", DescriptionOfMapUnitsRecords);
            }

            #endregion

            #endregion

            // Okay! Return the dictionary that has been built
            return dataAccessClasses;
        }