public void RunChangeRules()
{
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)
{
if (MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantAsk_2a") + totalCount + A4LGSharedFunctions.Localizer.GetString("AttributeAssistantAsk_2b"),
A4LGSharedFunctions.Localizer.GetString("Confirm"), System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
ESRI.ArcGIS.esriSystem.ITrackCancel trackCancel = new ESRI.ArcGIS.Display.CancelTrackerClass();
ESRI.ArcGIS.Framework.IProgressDialogFactory progressDialogFactory = new ESRI.ArcGIS.Framework.ProgressDialogFactoryClass();
// Set the properties of the Step Progressor
System.Int32 int32_hWnd = ArcMap.Application.hWnd;
ESRI.ArcGIS.esriSystem.IStepProgressor stepProgressor = progressDialogFactory.Create(trackCancel, int32_hWnd);
stepProgressor.MinRange = 1;
stepProgressor.MaxRange = totalCount;
stepProgressor.StepValue = 1;
stepProgressor.Message = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_2a");
// Create the ProgressDialog. This automatically displays the dialog
ESRI.ArcGIS.Framework.IProgressDialog2 progressDialog2 = (ESRI.ArcGIS.Framework.IProgressDialog2)stepProgressor; // Explict Cast
// Set the properties of the ProgressDialog
progressDialog2.CancelEnabled = true;
progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantDesc_2a") + totalCount.ToString() + ".";
progressDialog2.Title = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantTitle_2a");
progressDialog2.Animation = ESRI.ArcGIS.Framework.esriProgressAnimationTypes.esriProgressGlobe;
// Step. Do your big process here.
System.Boolean boolean_Continue = false;
boolean_Continue = true;
System.Int32 progressVal = 0;
ESRI.ArcGIS.esriSystem.IStatusBar statusBar = ArcMap.Application.StatusBar;
ran = true;
editor.StartOperation();
//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
{
// AAState.StopChangeMonitor();
while ((layer = enumLayer.Next()) != null)
{
// Verify that this is a valid, visible layer and that this layer is editable
fLayer = (IFeatureLayer)layer;
bool bIsEditableFabricLayer = (fLayer is ICadastralFabricSubLayer2);
if (bIsEditableFabricLayer)
{
IDataset pDS = (IDataset)fLayer.FeatureClass;
IWorkspace pFabWS = pDS.Workspace;
bIsEditableFabricLayer = (bIsEditableFabricLayer && pFabWS.Equals(editor.EditWorkspace));
}
if (fLayer.Valid && (eLayers.IsEditable(fLayer) || bIsEditableFabricLayer))//fLayer.Visible &&
{
// Verify that this layer has selected features
IFeatureClass fc = fLayer.FeatureClass;
fSel = (IFeatureSelection)fLayer;
if ((fc != null) && (fSel.SelectionSet.Count > 0))
{
fSel.SelectionSet.Search(null, false, out cursor);
fCursor = cursor as IFeatureCursor;
IFeature feat;
while ((feat = (IFeature)fCursor.NextFeature()) != null)
{
progressVal++;
progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantProc_2a") + progressVal + A4LGSharedFunctions.Localizer.GetString("Of") + totalCount.ToString() + ".";
stepProgressor.Step();
statusBar.set_Message(0, progressVal.ToString());
lastLay = fLayer.Name;
lastOID = feat.OID;
IObject pObj = feat as IObject;
AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_2c"));
AAState._editEvents.OnChangeFeature -= AAState.FeatureChange;
try
{
AAState.FeatureChange(pObj);
feat.Store();
}
catch
{
}
AAState._editEvents.OnChangeFeature += AAState.FeatureChange;
AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_2b"));
//Check if the cancel button was pressed. If so, stop process
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
break;
}
}
if (feat != null)
Marshal.ReleaseComObject(feat);
}
}
else
{
if (fLayer.Valid)
{
// Verify that this layer has selected features
IFeatureClass fc = fLayer.FeatureClass;
fSel = (IFeatureSelection)fLayer;
if (fSel.SelectionSet.Count > 0)
{
progressVal = progressVal + fSel.SelectionSet.Count;
stepProgressor.OffsetPosition(progressVal);
stepProgressor.Step();
}
}
}
}
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}
catch (Exception ex)
{
editor.AbortOperation();
ran = false;
MessageBox.Show("RunChangeRule\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source);
return;
}
finally
{
// AAState.StartChangeMonitor();
try
{
// Stop the edit operation
editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantDone_2a"));
}
catch (Exception ex)
{ }
}
editor.StartOperation();
try
{
AAState.StopChangeMonitor();
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)
{
progressVal++;
progressDialog2.Description = A4LGSharedFunctions.Localizer.GetString("AttributeAssistantProc_2a") + progressVal + A4LGSharedFunctions.Localizer.GetString("Of") + totalCount.ToString() + ".";
stepProgressor.Step();
statusBar.set_Message(0, progressVal.ToString());
lastOID = pRow.OID;
lastLay = stTable.Name;
IObject pObj = pRow as IObject;
AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_2c"));
AAState._editEvents.OnChangeFeature -= AAState.FeatureChange;
try
{
AAState.FeatureChange(pObj);
pRow.Store();
}
catch
{
}
AAState._editEvents.OnChangeFeature += AAState.FeatureChange;
AAState.WriteLine(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantMess_2b"));
//Check if the cancel button was pressed. If so, stop process
boolean_Continue = trackCancel.Continue();
if (!boolean_Continue)
{
break;
}
}
if (pRow != null)
Marshal.ReleaseComObject(pRow);
pRow = null;
}
}
}
}
catch (Exception ex)
{
editor.AbortOperation();
MessageBox.Show("RunChangeRules\n" + ex.Message + " \n" + lastLay + ": " + lastOID, ex.Source);
ran = false;
return;
}
finally
{
AAState.StartChangeMonitor();
try
{
// Stop the edit operation
editor.StopOperation(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantDone_2a"));
}
catch (Exception ex)
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantEditorWarn_14a") + " " + ex.Message);
}
}
// Done
trackCancel = null;
stepProgressor = null;
progressDialog2.HideDialog();
progressDialog2 = null;
}
}
else
{
MessageBox.Show(A4LGSharedFunctions.Localizer.GetString("AttributeAssistantError_2a"));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + " \n" + "RunChangeRules", 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);
}
}