Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have an interesting situation.Suppose a user creates 10 features in ArcMap in an edit session. Now the user tries to save this edits by clicking save edits or stop edits button. I would be performing some checks at this point(by listening to OnStopEditing/OnSaveEdits events). If the result of this check is not satisfactory, I would want ArcMap not to commit these changes. Also the state of edits not should be the same as it was before the Save Edits/Stop Edits button was pressed.

So in the case of failed checks, the 10 digitized features would stay ther in map, without permanantly committing to the database.

I hope I am not complicating things. Another way to describe the situation is, If the validations fail, ArcMap should just behave as if the user had not presed the StopEdits/SaveEdits button.

How can I do this using ArcObjects? I tried as shown below. But it simply saves edits and then stops editing. Anyone got ideas?

void editor_OnStopEditing(bool save)
{
  if (save == true)
  {
    if(HasMyValidationFailed())
    {
      //do not stop edit here..
      return; //did not work..
      //throw; //did not work..
    }
  }
}
share|improve this question
1  
I would suggest running a edit listener per edit event (e.g. OnChangeFeature or AfterDrawSketch), not on the save event. This way an editor will not have to re-peat data or feature creation (e.g. re-creating 10 features). –  artwork21 Jan 25 '13 at 14:31
1  
Did you try BeforeStopEditing? –  Kirk Kuykendall Jan 25 '13 at 14:32
    
@KirkKuykendall -yes with the same result..changes get saved and stop edit happens.. –  vinayan Jan 26 '13 at 6:27
add comment

2 Answers

I have done something like this in arcObjects. In my case, I have to add some points in a point feature class at user's mouse click point. After clicking add button, user starts adding points. After adding, if user click "cancel" button rather then "ok", all added points in that session, deleted. And if user choose "ok", then points will be in feature class. But I didn't do it in a edit session(I don't know is there any constraints that these things should happen in edit session). For my work I use following algorithm:

  1. get user clicked point.
  2. create feature for that point.
  3. add this feature in a list of IFeature
  4. Do 1,2,3 till "ok"/ "cancel" button is clicked.
  5. If button == "ok", store all features of feature list in feature class
  6. If button == "cancel", delete all features from feature list.
share|improve this answer
    
When the count and types of edits gets more and more, this method would be very difficult.. –  vinayan Jan 28 '13 at 12:49
    
How many point one person going to add by clicking points –  Emi Jan 28 '13 at 15:47
    
user could be adding/deleting/modifying geometries(line,point,polygon,annotation..)..users can make it real fun once an edit session is provided :) –  vinayan Jan 28 '13 at 16:37
add comment

Typically with event models at the completion of a task the event is called after the event is assumed to be completed. I know, doesn't make much sense, see code comments.

void editor_OnStopEditing(bool save)
{
  // I have already queued this operation for saving.  You need to stop me.
  // if (save == true)
  // Other:  Please never do this is makes programmers cry
  if (save)
  {
    if(HasMyValidationFailed())
    {
      return; //did work.  But I have already decided to save.
      throw; //did work.  But I threw an error for this event and not for this edit

    }
  }
}

You need to call UndoEditOperation most likely this. I am not sure your implementation since you didn't post all of it, but that method will help you out. Also your should check the HasEdits Method before you check for your Validation and other operations.

It has to be set up this way since assuming that you don't want to save creates a headache for the system. Listeners are optional (and very nice). If it is assumed that at the end of this operation that you don't want to save then everyone would have to create a listener to and explicitly say save or the system would have to check and see if another listener besides the already existing listeners has been added and then based on checking all the listeners decide that the system should save.

share|improve this answer
    
thanks for the comments..but UndoEditOperation simply undoes the last edit operation..I have a bunch of edit operations and do not want to lose edits the user has captued on the map.. –  vinayan Jan 28 '13 at 12:52
    
Of course. The idea was to rollback until the user was in a set a positive validation. If the scenario is that the first part could be valid then the second part invalid and then the third invalid, please update your question and I'll try to find something for you. –  user13395 Jan 28 '13 at 13:33
    
my validations have nothing to do with geometry..say i want to check if my network cable is unplugged :) –  vinayan Jan 28 '13 at 13:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.