Prevent specific field editing for specific users in ArcMap

1514
5
08-09-2011 12:58 AM
DmitrySharov
New Contributor
Hi, I have a task to lock fields editing for specific users. I started to check IEditEvents_Event with it's OnChangeFeature event, but I can't understand what exactly was changed and what was the original value. Also I failed all my attempts to undo changes. If I use IEditor.AbortOperation() it breaks ArcMap, if I use throw new COMException(msg, (int)0x80004005L) it does nothing.

As workaround for detecting field changes I came up with:
[PHP]
private void FeatureChanged(IObject feature)
        {
            var editor = _editor as IEditor;

            if (editor != null)
            {
                var workspaceEdit = (editor.EditWorkspace as IWorkspaceEdit2);
                var changes = workspaceEdit.get_EditDataChanges(esriEditDataChangesType.esriEditDataChangesWithinOperation);
                var classes = changes.ModifiedClasses;

                var @class = classes.Next();

                var cursor = changes.ExtractEx(@class, esriDifferenceType.esriDifferenceTypeUpdateNoChange);

                // Prepare the output parameters.
                int featureID = -1;
                IRow sourceRow = null;
                IRow differenceRow = null;
                ILongArray fieldIndexes = null;

                // Iterate through the cursor.
                cursor.Next(out featureID, out sourceRow, out differenceRow, out fieldIndexes);
                while (featureID != -1)
                {
                    for (int i = 0; i < fieldIndexes.Count; i++)
                    {
                        var index = fieldIndexes.get_Element(i);

                        if (index >= 3) // Stub
                        {

                        }
                    }

                    cursor.Next(out featureID, out sourceRow, out differenceRow, out fieldIndexes);
                }
            }
        }
[/PHP]

But the logic is very disgusting as I don't work with feature which came in handler.

So the question is - how to detect feature attribute changes for concrete columns, and undo it in some cases correctly?
0 Kudos
5 Replies
DubravkoAntonic
New Contributor III
What if you extension is not active and ArcMap is connected to the database? User can edit data in the DB with no restriction except DB permission.

Maybe faster way is on the DB side.
http://www.mssqltips.com/tip.asp?tip=2124


For row values, changes use IRowChanges
http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esrigeodatabase/IRowChanges.htm
0 Kudos
DmitrySharov
New Contributor

Maybe faster way is on the DB side.
http://www.mssqltips.com/tip.asp?tip=2124


Yes it will help with ArcSDE users, but I need to check local shape and gdb file changes.

The problem is not to allow changes, which are made by mistake.
0 Kudos
DubravkoAntonic
New Contributor III
Some kind of pseudo

in some static part of extension preffetch all featureClass ObjectClassID that you need to filter
public/private static List<int> watchedFeatureClass = new List<int>();
// for each FC you should add field indexes that you need to watch
public/private Dictionary<int, List<int>> watchedFields = new Dictionary<int, List<int>>();


I rather prefer Object approach to create some class that will do this with some descriptive methods:
private static List<int>...
private static Dictionary...
public bool IsChanged(IFeature pFeature)
public void RestoreOriginalValue()



// in changed event
IObject feature;
IFeature pFeature = feature as IFeature;

// use target ObjectClassID to determine if this is watched FC
watchedFeatureClass .Contains(pFeature.Class.ObjectClassID)


IRowChanges pRowChanges = pFeature as IRowChange;
if(pRowChanges.ValueChanged)
... do some stuf like looping through Fields and test if
http://resources.esri.com/help/9.3/ArcGISDesktop/ArcObjects/esrigeodatabase/IRowChanges_ValueChanged...

I hope this hints will help.

Or you can combine my method with yours.
0 Kudos
DmitrySharov
New Contributor
Dubravko Antoni�?, thank you a lot. IRowChanges solved almost all my problems. Do you know if there is a good way of aborting edit operation or there is only a way of restoring field data?
0 Kudos
DubravkoAntonic
New Contributor III
No I don't know for this kind of event but you can listen OnSaveEdits and OnStopEditing to prevent saving edits to base.
0 Kudos