public void RunManualRules() { ICursor cursor = null; IFeatureCursor fCursor = null; bool ran = false; try { //Get list of editable layers IEditor editor = _editor; IEditLayers eLayers = (IEditLayers)editor; long lastOID = -1; string lastLay = ""; if (_editor.EditState != esriEditState.esriStateEditing) { return; } IMap map = editor.Map; IActiveView activeView = map as IActiveView; IStandaloneTable stTable; ITableSelection tableSel; IStandaloneTableCollection stTableColl = (IStandaloneTableCollection)map; long rowCount = stTableColl.StandaloneTableCount; long rowSelCount = 0; for (int i = 0; i < stTableColl.StandaloneTableCount; i++) { stTable = stTableColl.get_StandaloneTable(i); tableSel = (ITableSelection)stTable; if (tableSel.SelectionSet != null) { rowSelCount = rowSelCount + tableSel.SelectionSet.Count; } } long featCount = map.SelectionCount; int totalCount = (Convert.ToInt32(rowSelCount) + Convert.ToInt32(featCount)); if (totalCount >= 1) { editor.StartOperation(); if (MessageBox.Show("Are you sure you wish to apply attribute assistant manual rules for the selected " + totalCount + " rows and features?", "Confirm", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { ran = true; //bool test = false; //Get list of feature layers UID geoFeatureLayerID = new UIDClass(); geoFeatureLayerID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}"; IEnumLayer enumLayer = map.get_Layers(((ESRI.ArcGIS.esriSystem.UID)geoFeatureLayerID), true); IFeatureLayer fLayer; IFeatureSelection fSel; ILayer layer; // Step through each geofeature layer in the map enumLayer.Reset(); // Create an edit operation enabling undo/redo try { while ((layer = enumLayer.Next()) != null) { // Verify that this is a valid, visible layer and that this layer is editable fLayer = (IFeatureLayer)layer; if (fLayer.Valid && eLayers.IsEditable(fLayer))//fLayer.Visible && { // Verify that this layer has selected features IFeatureClass fc = fLayer.FeatureClass; fSel = (IFeatureSelection)fLayer; if ((fc != null) && (fSel.SelectionSet.Count > 0)) { // test = true; fSel.SelectionSet.Search(null, false, out cursor); fCursor = cursor as IFeatureCursor; IFeature feat; while ((feat = (IFeature)fCursor.NextFeature()) != null) { lastLay = fLayer.Name; lastOID = feat.OID; IObject pObj = feat as IObject; AAState.FeatureManual(pObj); feat.Store(); } if (feat != null) { Marshal.ReleaseComObject(feat); } } } } } catch (Exception ex) { editor.AbortOperation(); ran = false; MessageBox.Show("RunManualRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source); return; } finally { //try //{ // // Stop the edit operation // editor.StopOperation("Run Manual Rules - Features"); //} //catch (Exception ex) //{ } } try { for (int i = 0; i < stTableColl.StandaloneTableCount; i++) { stTable = stTableColl.get_StandaloneTable(i); tableSel = (ITableSelection)stTable; if (tableSel.SelectionSet != null) { if (tableSel.SelectionSet.Count > 0) { tableSel.SelectionSet.Search(null, false, out cursor); IRow pRow; while ((pRow = (IRow)cursor.NextRow()) != null) { lastOID = pRow.OID; lastLay = stTable.Name; IObject pObj = pRow as IObject; AAState.FeatureManual(pObj); pRow.Store(); } if (pRow != null) { Marshal.ReleaseComObject(pRow); } } } } } catch (Exception ex) { editor.AbortOperation(); MessageBox.Show("RunManualRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source); ran = false; return; } finally { //try //{ // Stop the edit operation // editor.StopOperation("Run Manual Rules - Features"); //} //catch (Exception ex) //{ } } try { editor.StopOperation("Run Manual Rules - Features"); } catch { } } } else { MessageBox.Show("Please select some features or rows to run this process."); } } catch (Exception ex) { MessageBox.Show(ex.Message + " \n" + "RunManualRules", ex.Source); ran = false; return; } finally { if (ran) { MessageBox.Show("Process has completed successfully"); } if (cursor != null) { Marshal.ReleaseComObject(cursor); } if (fCursor != null) { Marshal.ReleaseComObject(fCursor); } } }