private void ApplyFeatureTemplates()
        {
            // Get a reference to the selected FeatureTemplate
            IEditor3 templateEditor = ArcMap.Editor as IEditor3;
            IEditTemplate theCurrentTemplate = templateEditor.CurrentTemplate;

            // If they didn't select a template, they'll need to
            if (theCurrentTemplate == null) { MessageBox.Show("No FeatureTemplate was selected.", "NCGMP Tools"); return; }

            // Find out what FeatureClass the selected template belongs to, and what its geometry is
            IFeatureClass templateFC = ((IFeatureLayer)theCurrentTemplate.Layer).FeatureClass;
            switch (templateFC.ShapeType)
            {
                case esriGeometryType.esriGeometryPolyline:
                    // Look for feature selected in line FeatureClasses
                    #region ContactsAndFaults
                    IFeatureLayer contactsAndFaultsFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "ContactsAndFaults");
                    if (contactsAndFaultsFL != null)
                    {
                        // Found ContactsAndFaults. Check for a selection
                        IFeatureSelection selectedFeatures = contactsAndFaultsFL as IFeatureSelection;
                        if (selectedFeatures.SelectionSet.Count > 0)
                        {
                            // ContactsAndFaults were selected. Pass the selection into a cursor.
                            ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet;
                            ICursor theCursor;
                            featureSelectionSet.Search(null, false, out theCursor);
                            IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor;

                            // Some variables to declare before the loops
                            int idFld = theFeatureCursor.FindField("ContactsAndFaults_ID");
                            IFeature theFeature;
                            string thisId;

                            // Construct a dummy feature to get attributes from
                            IFeature dummyFeature = templateFC.CreateFeature();
                            theCurrentTemplate.SetDefaultValues(dummyFeature);
                            string ExistenceConfidence = dummyFeature.get_Value(templateFC.FindField("ExistenceConfidence")).ToString();
                            string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString();
                            string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString();
                            double LocationConfidenceMeters;
                            bool result = double.TryParse(dummyFeature.get_Value(templateFC.FindField("LocationConfidenceMeters")).ToString(), out LocationConfidenceMeters);
                            string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString();
                            string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString();
                            string Type = dummyFeature.get_Value(templateFC.FindField("Type")).ToString();
                            int IsConcealed = 0;
                            if (contactsAndFaultsFL.FeatureClass.Equals(templateFC) == true)
                            {
                                result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("IsConcealed")).ToString(), out IsConcealed);
                            }

                            // Destroy the dummy feature - must happen within an edit operation
                            ArcMap.Editor.StartOperation();
                            dummyFeature.Delete();
                            ArcMap.Editor.StopOperation("Remove Dummy Feature");

                            //Is the FeatureTemplate also for ContactsAndFaults?
                            switch (contactsAndFaultsFL.FeatureClass.Equals(templateFC))
                            {
                                case true:
                                    // Update the features to the FeatureTemplate
                                    ContactsAndFaultsAccess ContactsAndFaultsUpdater = new ContactsAndFaultsAccess(m_theWorkspace);

                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the ContactsAndFaults feature to update
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        ContactsAndFaultsUpdater.AddContactsAndFaults("ContactsAndFaults_ID = '" + thisId + "'");
                                        ContactsAndFaultsAccess.ContactsAndFault thisContactsAndFault = ContactsAndFaultsUpdater.ContactsAndFaultsDictionary[thisId];

                                        // Assign values from the FeatureTemplate
                                        thisContactsAndFault.ExistenceConfidence = ExistenceConfidence;
                                        thisContactsAndFault.IdentityConfidence = IdentityConfidence;
                                        thisContactsAndFault.Label = Label;
                                        thisContactsAndFault.LocationConfidenceMeters = LocationConfidenceMeters;
                                        thisContactsAndFault.Notes = Notes;
                                        thisContactsAndFault.Symbol = Symbol;
                                        thisContactsAndFault.Type = Type;
                                        thisContactsAndFault.IsConcealed = IsConcealed;

                                        // Update the feature
                                        ContactsAndFaultsUpdater.UpdateContactsAndFault(thisContactsAndFault);

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }

                                    // Save changes
                                    ContactsAndFaultsUpdater.SaveContactsAndFaults();
                                    break;
                                case false:
                                    // Copy the features into the templateFC using the selected template as a guide

                                    // Build DataAccess Classes for target FeatureClasses
                                    OtherLinesAccess OtherLinesInserter = new OtherLinesAccess(m_theWorkspace);

                                    // Find the target FeatureClass Name
                                    string tableName = (templateFC 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);

                                    // Will need to remove the selected feature from ContactsAndFaults
                                    ContactsAndFaultsAccess ContactsAndFaultsRemover = new ContactsAndFaultsAccess(m_theWorkspace);

                                    // Loop through the selected ContactsAndFaults
                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the ContactsAndFaults feature to remove
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        ContactsAndFaultsRemover.AddContactsAndFaults("ContactsAndFaults_ID = '" + thisId + "'");
                                        ContactsAndFaultsAccess.ContactsAndFault thisContactsAndFault = ContactsAndFaultsRemover.ContactsAndFaultsDictionary[thisId];

                                        // Setup attributes
                                        string DataSourceID = thisContactsAndFault.DataSourceID;
                                        IPolyline Shape = thisContactsAndFault.Shape;

                                        // Create the new feature in the template FeatureClass
                                        switch (parsedTableName)
                                        {
                                            case "OtherLines":
                                                // Insert the new OtherLines
                                                OtherLinesInserter.NewOtherLine(Type, LocationConfidenceMeters, ExistenceConfidence, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape);
                                                OtherLinesInserter.SaveOtherLines();

                                                // Clear out the dictionary so lines don't get added more than once.
                                                OtherLinesInserter.ClearOtherLines();

                                                // Delete the old one
                                                ContactsAndFaultsRemover.DeleteContactsAndFaults(thisContactsAndFault);
                                                break;
                                            default:
                                                // This would happen if there's some other polyline featuretemplate selected. Just need to exit gracefully.
                                                break;
                                        }

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }
                                    break;
                            }
                        }
                    }
                    #endregion

                    #region OtherLines
                    IFeatureLayer OtherLinesFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "OtherLines");
                    if (OtherLinesFL != null)
                    {
                        // Found OtherLines. Check for a selection
                        IFeatureSelection selectedFeatures = OtherLinesFL as IFeatureSelection;
                        if (selectedFeatures.SelectionSet.Count > 0)
                        {
                            // OtherLines were selected. Pass the selection into a cursor.
                            ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet;
                            ICursor theCursor;
                            featureSelectionSet.Search(null, false, out theCursor);
                            IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor;

                            // Some variables to declare before the loops
                            int idFld = theFeatureCursor.FindField("OtherLines_ID");
                            IFeature theFeature;
                            string thisId;

                            // Construct a dummy feature to get attributes from
                            IFeature dummyFeature = templateFC.CreateFeature();
                            theCurrentTemplate.SetDefaultValues(dummyFeature);
                            string ExistenceConfidence = dummyFeature.get_Value(templateFC.FindField("ExistenceConfidence")).ToString();
                            string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString();
                            string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString();
                            double LocationConfidenceMeters;
                            bool result = double.TryParse(dummyFeature.get_Value(templateFC.FindField("LocationConfidenceMeters")).ToString(), out LocationConfidenceMeters);
                            string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString();
                            string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString();
                            string Type = dummyFeature.get_Value(templateFC.FindField("Type")).ToString();
                            int IsConcealed = 0;
                            if (templateFC.Equals(commonFunctions.OpenFeatureClass(m_theWorkspace, "ContactsAndFaults")) == true)
                            {
                                result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("IsConcealed")).ToString(), out IsConcealed);
                            }

                            // Destroy the dummy feature - must happen within an edit operation
                            ArcMap.Editor.StartOperation();
                            dummyFeature.Delete();
                            ArcMap.Editor.StopOperation("Remove Dummy Feature");

                            //Is the FeatureTemplate also for OtherLines?
                            switch (OtherLinesFL.FeatureClass.Equals(templateFC))
                            {
                                case true:
                                    // Update the features to the FeatureTemplate
                                    OtherLinesAccess OtherLinesUpdater = new OtherLinesAccess(m_theWorkspace);

                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the OtherLines feature to update
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        OtherLinesUpdater.AddOtherLines("OtherLines_ID = '" + thisId + "'");
                                        OtherLinesAccess.OtherLine thisOtherLine = OtherLinesUpdater.OtherLinesDictionary[thisId];

                                        // Assign values from the FeatureTemplate
                                        thisOtherLine.ExistenceConfidence = ExistenceConfidence;
                                        thisOtherLine.IdentityConfidence = IdentityConfidence;
                                        thisOtherLine.Label = Label;
                                        thisOtherLine.LocationConfidenceMeters = LocationConfidenceMeters;
                                        thisOtherLine.Notes = Notes;
                                        thisOtherLine.Symbol = Symbol;
                                        thisOtherLine.Type = Type;

                                        // Update the feature
                                        OtherLinesUpdater.UpdateOtherLine(thisOtherLine);

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }

                                    // Save changes
                                    OtherLinesUpdater.SaveOtherLines();
                                    break;
                                case false:
                                    // Copy the features into the templateFC using the selected template as a guide

                                    // Build DataAccess Classes for target FeatureClasses
                                    ContactsAndFaultsAccess ContactsAndFaultsInserter = new ContactsAndFaultsAccess(m_theWorkspace);

                                    // Find the target FeatureClass Name
                                    string tableName = (templateFC 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);

                                    // Will need to remove the selected feature from OtherLines
                                    OtherLinesAccess OtherLinesRemover = new OtherLinesAccess(m_theWorkspace);

                                    // Loop through the selected OtherLines
                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the OtherLines feature to remove
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        OtherLinesRemover.AddOtherLines("OtherLines_ID = '" + thisId + "'");
                                        OtherLinesAccess.OtherLine thisOtherLine = OtherLinesRemover.OtherLinesDictionary[thisId];

                                        // Setup attributes
                                        string DataSourceID = thisOtherLine.DataSourceID;
                                        IPolyline Shape = thisOtherLine.Shape;

                                        // Create the new feature in the template FeatureClass
                                        switch (parsedTableName)
                                        {
                                            case "ContactsAndFaults":
                                                // Insert the new OtherLines
                                                ContactsAndFaultsInserter.NewContactsAndFault(Type, IsConcealed, LocationConfidenceMeters, ExistenceConfidence, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape);
                                                ContactsAndFaultsInserter.SaveContactsAndFaults();

                                                // Clear out the dictionary so lines don't get added more than once.
                                                ContactsAndFaultsInserter.ClearContactsAndFaults();

                                                // Delete the old one
                                                OtherLinesRemover.DeleteOtherLines(thisOtherLine);
                                                break;
                                            default:
                                                // This would happen if there's some other polyline featuretemplate selected. Just need to exit gracefully.
                                                break;
                                        }

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }
                                    break;
                            }
                        }
                    }
                    #endregion

                    break;
                case esriGeometryType.esriGeometryPoint:
                    // Look for features selected in point FeatureClasses
                    //  Note: I don't care about FeatureTemplates in Station or Sample featureclasses.
                    #region OrientationDataPoints
                    IFeatureLayer OrientationDataPointsFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "OrientationDataPoints");
                    if (OrientationDataPointsFL != null)
                    {
                        // Found OrientationDataPoints. Check for a selection
                        IFeatureSelection selectedFeatures = OrientationDataPointsFL as IFeatureSelection;
                        if (selectedFeatures.SelectionSet.Count > 0)
                        {
                            // OrientationDataPoints were selected. Pass the selection into a cursor.
                            ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet;
                            ICursor theCursor;
                            featureSelectionSet.Search(null, false, out theCursor);
                            IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor;

                            // Some variables to declare before the loops
                            int idFld = theFeatureCursor.FindField("OrientationDataPoints_ID");
                            IFeature theFeature;
                            string thisId;

                            // Construct a dummy feature to get attributes from
                            IFeature dummyFeature = templateFC.CreateFeature();
                            theCurrentTemplate.SetDefaultValues(dummyFeature);
                            string Type = dummyFeature.get_Value(templateFC.FindField("Type")).ToString();
                            string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString();
                            string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString();
                            int PlotAtScale;
                            bool result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("PlotAtScale")).ToString(), out PlotAtScale);
                            double OrientationConfidenceDegrees;
                            result = double.TryParse(dummyFeature.get_Value(templateFC.FindField("OrientationConfidenceDegrees")).ToString(), out OrientationConfidenceDegrees);
                            string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString();
                            int Symbol;
                            result = int.TryParse(dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString(), out Symbol);

                            // Destroy the dummy feature - must happen within an edit operation
                            ArcMap.Editor.StartOperation();
                            dummyFeature.Delete();
                            ArcMap.Editor.StopOperation("Remove Dummy Feature");

                            //Is the FeatureTemplate also for OrientationDataPoints?
                            switch (OrientationDataPointsFL.FeatureClass.Equals(templateFC))
                            {
                                case true:
                                    // Update the features to the FeatureTemplate
                                    OrientationDataPointsAccess OrientationDataPointsUpdater = new OrientationDataPointsAccess(m_theWorkspace);

                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the OrientationDataPoints feature to update
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        OrientationDataPointsUpdater.AddOrientationDataPoints("OrientationDataPoints_ID = '" + thisId + "'");
                                        OrientationDataPointsAccess.OrientationDataPoint thisOrientationDataPoint = OrientationDataPointsUpdater.OrientationDataPointsDictionary[thisId];

                                        // Assign values from the FeatureTemplate

                                        thisOrientationDataPoint.Type = Type;
                                        thisOrientationDataPoint.IdentityConfidence = IdentityConfidence;
                                        thisOrientationDataPoint.Label = Label;
                                        thisOrientationDataPoint.PlotAtScale = PlotAtScale;
                                        thisOrientationDataPoint.OrientationConfidenceDegrees = OrientationConfidenceDegrees;
                                        thisOrientationDataPoint.Notes = Notes;
                                        thisOrientationDataPoint.Symbol = Symbol;

                                        // Update the feature
                                        OrientationDataPointsUpdater.UpdateOrientationDataPoint(thisOrientationDataPoint);

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }

                                    // Save changes
                                    OrientationDataPointsUpdater.SaveOrientationDataPoints();
                                    break;
                                case false:
                                    // User needs to select an appropriate feature template
                                    MessageBox.Show("Please select a FeatureTemplate appropriate for the type of features you've selected" + Environment.NewLine + "You've selected some Orientation Data on the map but have not selected a structural FeatureTemplate.");

                                    break;
                            }
                        }
                    }
                    #endregion

                    break;
                case esriGeometryType.esriGeometryPolygon:
                    // Look for features selected in polygon FeatureClasses
                    #region MapUnitPolys
                    IFeatureLayer MapUnitPolysFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "MapUnitPolys");
                    if (MapUnitPolysFL != null)
                    {
                        // Found MapUnitPolys. Check for a selection
                        IFeatureSelection selectedFeatures = MapUnitPolysFL as IFeatureSelection;
                        if (selectedFeatures.SelectionSet.Count > 0)
                        {
                            // MapUnitPolys were selected. Pass the selection into a cursor.
                            ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet;
                            ICursor theCursor;
                            featureSelectionSet.Search(null, false, out theCursor);
                            IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor;

                            // Some variables to declare before the loops
                            int idFld = theFeatureCursor.FindField("MapUnitPolys_ID");
                            IFeature theFeature;
                            string thisId;

                            // Construct a dummy feature to get attributes from
                            IFeature dummyFeature = templateFC.CreateFeature();
                            theCurrentTemplate.SetDefaultValues(dummyFeature);
                            string MapUnit = dummyFeature.get_Value(templateFC.FindField("MapUnit")).ToString();
                            string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString();
                            string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString();
                            string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString();
                            string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString();

                            // Destroy the dummy feature - must happen within an edit operation
                            ArcMap.Editor.StartOperation();
                            dummyFeature.Delete();
                            ArcMap.Editor.StopOperation("Remove Dummy Feature");

                            //Is the FeatureTemplate also for MapUnitPolys?
                            switch (MapUnitPolysFL.FeatureClass.Equals(templateFC))
                            {
                                case true:
                                    // Update the features to the FeatureTemplate
                                    MapUnitPolysAccess MapUnitPolysUpdater = new MapUnitPolysAccess(m_theWorkspace);

                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the MapUnitPolys feature to update
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        MapUnitPolysUpdater.AddMapUnitPolys("MapUnitPolys_ID = '" + thisId + "'");
                                        MapUnitPolysAccess.MapUnitPoly thisMapUnitPoly = MapUnitPolysUpdater.MapUnitPolysDictionary[thisId];

                                        // Assign values from the FeatureTemplate
                                        thisMapUnitPoly.MapUnit = MapUnit;
                                        thisMapUnitPoly.IdentityConfidence = IdentityConfidence;
                                        thisMapUnitPoly.Label = Label;
                                        thisMapUnitPoly.Notes = Notes;
                                        thisMapUnitPoly.Symbol = Symbol;

                                        // Update the feature
                                        MapUnitPolysUpdater.UpdateMapUnitPoly(thisMapUnitPoly);

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }

                                    // Save changes
                                    MapUnitPolysUpdater.SaveMapUnitPolys();
                                    break;
                                case false:
                                    // Copy the features into the templateFC using the selected template as a guide

                                    // Build DataAccess Classes for target FeatureClasses
                                    OverlayPolysAccess OverlayPolysInserter = new OverlayPolysAccess(m_theWorkspace);

                                    // Find the target FeatureClass Name
                                    string tableName = (templateFC 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);

                                    // Will need to remove the selected feature from MapUnitPolys
                                    MapUnitPolysAccess MapUnitPolysRemover = new MapUnitPolysAccess(m_theWorkspace);

                                    // Loop through the selected MapUnitPolys
                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the MapUnitPolys feature to remove
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        MapUnitPolysRemover.AddMapUnitPolys("MapUnitPolys_ID = '" + thisId + "'");
                                        MapUnitPolysAccess.MapUnitPoly thisMapUnitPoly = MapUnitPolysRemover.MapUnitPolysDictionary[thisId];

                                        // Setup attributes
                                        string DataSourceID = thisMapUnitPoly.DataSourceID;
                                        IPolygon Shape = thisMapUnitPoly.Shape;

                                        // Create the new feature in the template FeatureClass
                                        switch (parsedTableName)
                                        {
                                            case "OverlayPolys":
                                                // Insert the new OtherLines
                                                OverlayPolysInserter.NewOverlayPoly(MapUnit, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape);
                                                OverlayPolysInserter.SaveOverlayPolys();

                                                // Clear out the dictionary so lines don't get added more than once.
                                                OverlayPolysInserter.ClearOverlayPolys();

                                                // Delete the old one
                                                MapUnitPolysRemover.DeleteMapUnitPolys(thisMapUnitPoly);
                                                break;
                                            default:
                                                // This would happen if there's some other polyline featuretemplate selected. Just need to exit gracefully.
                                                break;
                                        }

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }
                                    break;
                            }
                        }
                    }
                    #endregion

                    #region OverlayPolys
                    IFeatureLayer OverlayPolysFL = commonFunctions.FindFeatureLayer(m_theWorkspace, "OverlayPolys");
                    if (OverlayPolysFL != null)
                    {
                        // Found OverlayPolys. Check for a selection
                        IFeatureSelection selectedFeatures = OverlayPolysFL as IFeatureSelection;
                        if (selectedFeatures.SelectionSet.Count > 0)
                        {
                            // OverlayPolys were selected. Pass the selection into a cursor.
                            ISelectionSet featureSelectionSet = selectedFeatures.SelectionSet;
                            ICursor theCursor;
                            featureSelectionSet.Search(null, false, out theCursor);
                            IFeatureCursor theFeatureCursor = (IFeatureCursor)theCursor;

                            // Some variables to declare before the loops
                            int idFld = theFeatureCursor.FindField("OverlayPolys_ID");
                            IFeature theFeature;
                            string thisId;

                            // Construct a dummy feature to get attributes from
                            IFeature dummyFeature = templateFC.CreateFeature();
                            theCurrentTemplate.SetDefaultValues(dummyFeature);
                            string MapUnit = dummyFeature.get_Value(templateFC.FindField("MapUnit")).ToString();
                            string IdentityConfidence = dummyFeature.get_Value(templateFC.FindField("IdentityConfidence")).ToString();
                            string Label = dummyFeature.get_Value(templateFC.FindField("Label")).ToString();
                            string Notes = dummyFeature.get_Value(templateFC.FindField("Notes")).ToString();
                            string Symbol = dummyFeature.get_Value(templateFC.FindField("Symbol")).ToString();

                            // Destroy the dummy feature - must happen within an edit operation
                            ArcMap.Editor.StartOperation();
                            dummyFeature.Delete();
                            ArcMap.Editor.StopOperation("Remove Dummy Feature");

                            //Is the FeatureTemplate also for OverlayPolys?
                            switch (OverlayPolysFL.FeatureClass.Equals(templateFC))
                            {
                                case true:
                                    // Update the features to the FeatureTemplate
                                    OverlayPolysAccess OverlayPolysUpdater = new OverlayPolysAccess(m_theWorkspace);

                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the OverlayPolys feature to update
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        OverlayPolysUpdater.AddOverlayPolys("OverlayPolys_ID = '" + thisId + "'");
                                        OverlayPolysAccess.OverlayPoly thisOverlayPoly = OverlayPolysUpdater.OverlayPolysDictionary[thisId];

                                        // Assign values from the FeatureTemplate
                                        thisOverlayPoly.MapUnit = MapUnit;
                                        thisOverlayPoly.IdentityConfidence = IdentityConfidence;
                                        thisOverlayPoly.Label = Label;
                                        thisOverlayPoly.Notes = Notes;
                                        thisOverlayPoly.Symbol = Symbol;

                                        // Update the feature
                                        OverlayPolysUpdater.UpdateOverlayPoly(thisOverlayPoly);

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }

                                    // Save changes
                                    OverlayPolysUpdater.SaveOverlayPolys();
                                    break;
                                case false:
                                    // Copy the features into the templateFC using the selected template as a guide

                                    // Build DataAccess Classes for target FeatureClasses
                                    MapUnitPolysAccess MapUnitPolysInserter = new MapUnitPolysAccess(m_theWorkspace);

                                    // Find the target FeatureClass Name
                                    string tableName = (templateFC 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);

                                    // Will need to remove the selected feature from OverlayPolys
                                    OverlayPolysAccess OverlayPolysRemover = new OverlayPolysAccess(m_theWorkspace);

                                    // Loop through the selected OverlayPolys
                                    theFeature = theFeatureCursor.NextFeature();
                                    while (theFeature != null)
                                    {
                                        // Find the OverlayPolys feature to remove
                                        thisId = theFeature.get_Value(idFld).ToString();
                                        OverlayPolysRemover.AddOverlayPolys("OverlayPolys_ID = '" + thisId + "'");
                                        OverlayPolysAccess.OverlayPoly thisOverlayPoly = OverlayPolysRemover.OverlayPolysDictionary[thisId];

                                        // Setup attributes
                                        string DataSourceID = thisOverlayPoly.DataSourceID;
                                        IPolygon Shape = thisOverlayPoly.Shape;

                                        // Create the new feature in the template FeatureClass
                                        switch (parsedTableName)
                                        {
                                            case "MapUnitPolys":
                                                // Insert the new OtherLines
                                                MapUnitPolysInserter.NewMapUnitPoly(MapUnit, IdentityConfidence, Label, Notes, DataSourceID, Symbol, Shape);
                                                MapUnitPolysInserter.SaveMapUnitPolys();

                                                // Clear out the dictionary so lines don't get added more than once.
                                                MapUnitPolysInserter.ClearMapUnitPolys();

                                                // Delete the old one
                                                OverlayPolysRemover.DeleteOverlayPolys(thisOverlayPoly);
                                                break;
                                            default:
                                                // This would happen if there's some other polygon featuretemplate selected. Just need to exit gracefully.
                                                break;
                                        }

                                        // Increment the cursor
                                        theFeature = theFeatureCursor.NextFeature();
                                    }
                                    break;
                            }
                        }
                    }
                    #endregion

                    break;
            }
        }
        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);
            OverlayPolysAccess OverlayPolysAccess = new OverlayPolysAccess(m_theWorkspace);
            ContactsAndFaultsAccess ContactsAndFaultsAccess = new ContactsAndFaultsAccess(m_theWorkspace);
            OtherLinesAccess OtherLinesAccess = new OtherLinesAccess(m_theWorkspace);
            StationPointsAccess StationPointsAccess = new StationPointsAccess(m_theWorkspace);
            SamplePointsAccess SamplePointsAccess = new SamplePointsAccess(m_theWorkspace);
            OrientationDataPointsAccess OrientationDataPointsAccess = new OrientationDataPointsAccess(m_theWorkspace);
            GlossaryAccess GlossaryAccess = new GlossaryAccess(m_theWorkspace);
            NotesAccess NotesAccess = new NotesAccess(m_theWorkspace);
            RelatedDocumentsAccess RelatedDocumentsAccess = new RelatedDocumentsAccess(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 "OverlayPolys":
                        OverlayPolysAccess thisOverlayPolysAccess = (OverlayPolysAccess)anEntry.Value;
                        foreach (KeyValuePair<string, OverlayPolysAccess.OverlayPoly> OverlayPolysToUpdate in thisOverlayPolysAccess.OverlayPolysDictionary)
                        {
                            OverlayPolysAccess.OverlayPoly thisOverlayPoly = (OverlayPolysAccess.OverlayPoly)OverlayPolysToUpdate.Value;
                            thisOverlayPoly.DataSourceID = dataSourceID;
                            OverlayPolysAccess.UpdateOverlayPoly(thisOverlayPoly);
                        }
                        OverlayPolysAccess.SaveOverlayPolys();
                        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 "OtherLines":
                        OtherLinesAccess thisOtherLinesAccess = (OtherLinesAccess)anEntry.Value;
                        foreach (KeyValuePair<string, OtherLinesAccess.OtherLine> OtherLinesToUpdate in thisOtherLinesAccess.OtherLinesDictionary)
                        {
                            OtherLinesAccess.OtherLine thisOtherLine = (OtherLinesAccess.OtherLine)OtherLinesToUpdate.Value;
                            thisOtherLine.DataSourceID = dataSourceID;
                            OtherLinesAccess.UpdateOtherLine(thisOtherLine);
                        }
                        OtherLinesAccess.SaveOtherLines();
                        break;
                    case "StationPoints":
                        StationPointsAccess thisStationPointsAccess = (StationPointsAccess)anEntry.Value;
                        foreach (KeyValuePair<string, StationPointsAccess.StationPoint> StationPointsToUpdate in thisStationPointsAccess.StationPointsDictionary)
                        {
                            StationPointsAccess.StationPoint thisStationPoint = (StationPointsAccess.StationPoint)StationPointsToUpdate.Value;
                            thisStationPoint.DataSourceID = dataSourceID;
                            StationPointsAccess.UpdateStationPoint(thisStationPoint);
                        }
                        StationPointsAccess.SaveStationPoints();
                        break;
                    case "SamplePoints":
                        SamplePointsAccess thisSamplePointsAccess = (SamplePointsAccess)anEntry.Value;
                        foreach (KeyValuePair<string, SamplePointsAccess.SamplePoint> SamplePointsToUpdate in thisSamplePointsAccess.SamplePointsDictionary)
                        {
                            SamplePointsAccess.SamplePoint thisSamplePoint = (SamplePointsAccess.SamplePoint)SamplePointsToUpdate.Value;
                            thisSamplePoint.DataSourceID = dataSourceID;
                            SamplePointsAccess.UpdateSamplePoint(thisSamplePoint);
                        }
                        SamplePointsAccess.SaveSamplePoints();
                        break;
                    case "OrientationDataPoints":
                        OrientationDataPointsAccess thisOrientationDataPointsAccess = (OrientationDataPointsAccess)anEntry.Value;
                        foreach (KeyValuePair<string, OrientationDataPointsAccess.OrientationDataPoint> OrientationDataPointsToUpdate in thisOrientationDataPointsAccess.OrientationDataPointsDictionary)
                        {
                            OrientationDataPointsAccess.OrientationDataPoint thisOrientationDataPoint = (OrientationDataPointsAccess.OrientationDataPoint)OrientationDataPointsToUpdate.Value;
                            thisOrientationDataPoint.DataSourceID = dataSourceID;
                            OrientationDataPointsAccess.UpdateOrientationDataPoint(thisOrientationDataPoint);
                        }
                        OrientationDataPointsAccess.SaveOrientationDataPoints();
                        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 "Notes":
                        NotesAccess thisNotesAccess = (NotesAccess)anEntry.Value;
                        foreach (KeyValuePair<string, NotesAccess.Note> NotesToUpdate in thisNotesAccess.NotesDictionary)
                        {
                            NotesAccess.Note thisNote = (NotesAccess.Note)NotesToUpdate.Value;
                            thisNote.DataSourceID = dataSourceID;
                            NotesAccess.UpdateNote(thisNote);
                        }
                        NotesAccess.SaveNotes();
                        break;
                    case "RelatedDocuments":
                        RelatedDocumentsAccess thisRelatedDocumentsAccess = (RelatedDocumentsAccess)anEntry.Value;
                        foreach (KeyValuePair<string, RelatedDocumentsAccess.RelatedDocument> RelatedDocumentsToUpdate in thisRelatedDocumentsAccess.RelatedDocumentsDictionary)
                        {
                            RelatedDocumentsAccess.RelatedDocument thisRelatedDocument = (RelatedDocumentsAccess.RelatedDocument)RelatedDocumentsToUpdate.Value;
                            thisRelatedDocument.DataSourceID = dataSourceID;
                            RelatedDocumentsAccess.UpdateRelatedDocument(thisRelatedDocument);
                        }
                        RelatedDocumentsAccess.SaveRelatedDocuments();
                        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;
                }
            }
        }