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; }
private void UpdateDataSources(Dictionary<string, object> dataAccessClasses) { // Get the Data Source to set string dataSourceID = commonFunctions.GetCurrentDataSourceID(); // Bail if there isn't one if (dataSourceID == null) { return; } // Get DataAccess Classes to perform updates MapUnitPolysAccess mapUnitPolysAccess = new MapUnitPolysAccess(m_theWorkspace); DataSourcePolysAccess dataSourcePolysAccess = new DataSourcePolysAccess(m_theWorkspace); OtherPolysAccess OtherPolysAccess = new OtherPolysAccess(m_theWorkspace); ContactsAndFaultsAccess ContactsAndFaultsAccess = new ContactsAndFaultsAccess(m_theWorkspace); GeologicLinesAccess GeologicLinesAccess = new GeologicLinesAccess(m_theWorkspace); StationsAccess StationsAccess = new StationsAccess(m_theWorkspace); GenericSamplesAccess GenericSamplesAccess = new GenericSamplesAccess(m_theWorkspace); OrientationPointsAccess OrientationPointsAccess = new OrientationPointsAccess(m_theWorkspace); GlossaryAccess GlossaryAccess = new GlossaryAccess(m_theWorkspace); DescriptionOfMapUnitsAccess DescriptionOfMapUnitsAccess = new DescriptionOfMapUnitsAccess(m_theWorkspace); // Loop through the dictionary foreach (KeyValuePair<string, object> anEntry in dataAccessClasses) { // What table does this come from? switch (anEntry.Key) { case "MapUnitPolys": // Loop through the records in the data access object that comes in MapUnitPolysAccess thisMapUnitPolysAccess = (MapUnitPolysAccess)anEntry.Value; foreach (KeyValuePair<string, MapUnitPolysAccess.MapUnitPoly> MapUnitPolysToUpdate in thisMapUnitPolysAccess.MapUnitPolysDictionary) { MapUnitPolysAccess.MapUnitPoly thisMapUnitPoly = (MapUnitPolysAccess.MapUnitPoly)MapUnitPolysToUpdate.Value; thisMapUnitPoly.DataSourceID = dataSourceID; mapUnitPolysAccess.UpdateMapUnitPoly(thisMapUnitPoly); } mapUnitPolysAccess.SaveMapUnitPolys(); break; case "DataSourcePolys": // Loop through the records in the data access object that comes in DataSourcePolysAccess thisDataSourcePolysAccess = (DataSourcePolysAccess)anEntry.Value; foreach (KeyValuePair<string, DataSourcePolysAccess.DataSourcePoly> DataSourcePolysToUpdate in thisDataSourcePolysAccess.DataSourcePolysDictionary) { DataSourcePolysAccess.DataSourcePoly thisDataSourcePoly = (DataSourcePolysAccess.DataSourcePoly)DataSourcePolysToUpdate.Value; thisDataSourcePoly.DataSourceID = dataSourceID; dataSourcePolysAccess.UpdateDataSourcePoly(thisDataSourcePoly); } dataSourcePolysAccess.SaveDataSourcePolys(); break; case "OtherPolys": OtherPolysAccess thisOtherPolysAccess = (OtherPolysAccess)anEntry.Value; foreach (KeyValuePair<string, OtherPolysAccess.OtherPoly> OtherPolysToUpdate in thisOtherPolysAccess.OtherPolysDictionary) { OtherPolysAccess.OtherPoly thisOtherPoly = (OtherPolysAccess.OtherPoly)OtherPolysToUpdate.Value; thisOtherPoly.DataSourceID = dataSourceID; OtherPolysAccess.UpdateOtherPoly(thisOtherPoly); } OtherPolysAccess.SaveOtherPolys(); break; case "ContactsAndFaults": ContactsAndFaultsAccess thisContactsAndFaultsAccess = (ContactsAndFaultsAccess)anEntry.Value; foreach (KeyValuePair<string, ContactsAndFaultsAccess.ContactsAndFault> ContactsAndFaultsToUpdate in thisContactsAndFaultsAccess.ContactsAndFaultsDictionary) { ContactsAndFaultsAccess.ContactsAndFault thisContactsAndFault = (ContactsAndFaultsAccess.ContactsAndFault)ContactsAndFaultsToUpdate.Value; thisContactsAndFault.DataSourceID = dataSourceID; ContactsAndFaultsAccess.UpdateContactsAndFault(thisContactsAndFault); } ContactsAndFaultsAccess.SaveContactsAndFaults(); break; case "GeologicLines": GeologicLinesAccess thisGeologicLinesAccess = (GeologicLinesAccess)anEntry.Value; foreach (KeyValuePair<string, GeologicLinesAccess.GeologicLine> GeologicLinesToUpdate in thisGeologicLinesAccess.GeologicLinesDictionary) { GeologicLinesAccess.GeologicLine thisGeologicLine = (GeologicLinesAccess.GeologicLine)GeologicLinesToUpdate.Value; thisGeologicLine.DataSourceID = dataSourceID; GeologicLinesAccess.UpdateGeologicLine(thisGeologicLine); } GeologicLinesAccess.SaveGeologicLines(); break; case "Stations": StationsAccess thisStationsAccess = (StationsAccess)anEntry.Value; foreach (KeyValuePair<string, StationsAccess.Station> StationsToUpdate in thisStationsAccess.StationsDictionary) { StationsAccess.Station thisStation = (StationsAccess.Station)StationsToUpdate.Value; thisStation.DataSourceID = dataSourceID; StationsAccess.UpdateStation(thisStation); } StationsAccess.SaveStations(); break; case "GenericSamples": GenericSamplesAccess thisGenericSamplesAccess = (GenericSamplesAccess)anEntry.Value; foreach (KeyValuePair<string, GenericSamplesAccess.GenericSample> GenericSamplesToUpdate in thisGenericSamplesAccess.GenericSamplesDictionary) { GenericSamplesAccess.GenericSample thisGenericSample = (GenericSamplesAccess.GenericSample)GenericSamplesToUpdate.Value; thisGenericSample.DataSourceID = dataSourceID; GenericSamplesAccess.UpdateGenericSample(thisGenericSample); } GenericSamplesAccess.SaveGenericSamples(); break; case "OrientationPoints": OrientationPointsAccess thisOrientationPointsAccess = (OrientationPointsAccess)anEntry.Value; foreach (KeyValuePair<string, OrientationPointsAccess.OrientationPoint> OrientationPointsToUpdate in thisOrientationPointsAccess.OrientationPointsDictionary) { OrientationPointsAccess.OrientationPoint thisOrientationPoint = (OrientationPointsAccess.OrientationPoint)OrientationPointsToUpdate.Value; thisOrientationPoint.DataSourceID = dataSourceID; OrientationPointsAccess.UpdateOrientationPoint(thisOrientationPoint); } OrientationPointsAccess.SaveOrientationPoints(); break; case "Glossary": GlossaryAccess thisGlossaryAccess = (GlossaryAccess)anEntry.Value; foreach (KeyValuePair<string, GlossaryAccess.Glossary> GlossaryToUpdate in thisGlossaryAccess.GlossaryDictionary) { GlossaryAccess.Glossary thisGlossary = (GlossaryAccess.Glossary)GlossaryToUpdate.Value; thisGlossary.DefinitionSourceID = dataSourceID; GlossaryAccess.UpdateGlossary(thisGlossary); } GlossaryAccess.SaveGlossary(); break; case "DescriptionOfMapUnits": DescriptionOfMapUnitsAccess thisDescriptionOfMapUnitsAccess = (DescriptionOfMapUnitsAccess)anEntry.Value; foreach (KeyValuePair<string, DescriptionOfMapUnitsAccess.DescriptionOfMapUnit> DescriptionOfMapUnitsToUpdate in thisDescriptionOfMapUnitsAccess.DescriptionOfMapUnitsDictionary) { DescriptionOfMapUnitsAccess.DescriptionOfMapUnit thisDescriptionOfMapUnit = (DescriptionOfMapUnitsAccess.DescriptionOfMapUnit)DescriptionOfMapUnitsToUpdate.Value; thisDescriptionOfMapUnit.DescriptionSourceID = dataSourceID; DescriptionOfMapUnitsAccess.UpdateDescriptionOfMapUnit(thisDescriptionOfMapUnit); } DescriptionOfMapUnitsAccess.SaveDescriptionOfMapUnits(); break; } } }