Hi,
I'm trying to figure out where I am going wrong in my edit sequence. What I am doing is selecting newly created features that have no attribute information entered. The user then runs the tool and an attribute get populated. The field is a numeric field and there is some code that looks for the last entered number (ie. the current highest number) and increases it by 1 for the new feature.
So, for example the user adds 3 new hydrants and selects them all, then runs the tool. If there are already 10 hydrants the 3 new hydrants should get the numbers 11, 12, and 13 added into the SEQUENCENO attribute for the new features.
My problem is that the 11 and 12 get added, but then third feature gets 12 added again. If I have 10 features selected, the same sort of pattern happens. The 11 and 12 get added, but then the remaining 8 would also get 12.
I only want one item to show on the Undo stack, and each edit will affect the next, so that is why I am using ChainedOperation, but I just don't think I am implementing it correctly.
Below is the code where it loops though all the selected features and assigns the next number.
If you can offer some advice on how to get this working I'd appreciate it.
<SPAN class="comment token">//Create the MAIN edit operation...this will show up on the Undo Stack</SPAN>
<SPAN class="keyword token">var</SPAN> editOperation <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Editing<SPAN class="punctuation token">.</SPAN>EditOperation</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
editOperation<SPAN class="punctuation token">.</SPAN>Name <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Create new IDs"</SPAN><SPAN class="punctuation token">;</SPAN>
editOperation<SPAN class="punctuation token">.</SPAN>EditOperationType <SPAN class="operator token">=</SPAN> ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Editing<SPAN class="punctuation token">.</SPAN>EditOperationType<SPAN class="punctuation token">.</SPAN>Long<SPAN class="punctuation token">;</SPAN>
ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Editing<SPAN class="punctuation token">.</SPAN>EditOperation chainedOp <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//create the Inspector Object</SPAN>
<SPAN class="keyword token">var</SPAN> inspector <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Editing<SPAN class="punctuation token">.</SPAN>Attributes<SPAN class="punctuation token">.</SPAN>Inspector</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//create a flag to track the 'main' operation</SPAN>
<SPAN class="keyword token">bool</SPAN> isMainOperation <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">true</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Loop through each selected OBJECTID.</SPAN>
<SPAN class="keyword token">foreach</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">var</SPAN> oid <SPAN class="keyword token">in</SPAN> selectedOIDs<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
inspector<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Clear</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
inspector<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Load</SPAN><SPAN class="punctuation token">(</SPAN>currentLayer<SPAN class="punctuation token">,</SPAN> oid<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//Need to pass a FeatureCLass to the GetNextFaciltyID procedure</SPAN>
FeatureLayer currFLayer <SPAN class="operator token">=</SPAN> currentLayer <SPAN class="keyword token">as</SPAN> FeatureLayer<SPAN class="punctuation token">;</SPAN>
FeatureClass currFClass <SPAN class="operator token">=</SPAN> currFLayer<SPAN class="punctuation token">.</SPAN><SPAN class="token function">GetFeatureClass</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//This is where the sequence number will get incremented each time (in the GetNextFacilityID)</SPAN>
inspector<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"FACILITYID"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="token function">GetNextFacilityID</SPAN><SPAN class="punctuation token">(</SPAN>currFClass<SPAN class="punctuation token">,</SPAN> gridNumber<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
inspector<SPAN class="punctuation token">[</SPAN><SPAN class="string token">"SEQUENCENO"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> sequenceNumber<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>isMainOperation<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
editOperation<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Modify</SPAN><SPAN class="punctuation token">(</SPAN>inspector<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">bool</SPAN> result <SPAN class="operator token">=</SPAN> editOperation<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Execute</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//change the flag so we use the ChainedOp next</SPAN>
isMainOperation <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">false</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">else</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="comment token">//only create the ChainedOp once</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>chainedOp <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN>
chainedOp <SPAN class="operator token">=</SPAN> editOperation<SPAN class="punctuation token">.</SPAN><SPAN class="token function">CreateChainedOperation</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//queue up a Modify</SPAN>
chainedOp<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Modify</SPAN><SPAN class="punctuation token">(</SPAN>inspector<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">//Increase the feature count for the final tally</SPAN>
featureCount<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">else</SPAN>
<SPAN class="punctuation token">{</SPAN>
rejectedCount<SPAN class="operator token">++</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN> <SPAN class="comment token">//go to next selected feature in current layer</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN>chainedOp <SPAN class="operator token">!=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="operator token">!</SPAN>chainedOp<SPAN class="punctuation token">.</SPAN>IsEmpty<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">bool</SPAN> chainedResult <SPAN class="operator token">=</SPAN> chainedOp<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Execute</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>And this is the section of code that determines the next available number. I think the logic here is fine, but because my edits aren't really getting applied (??) properly though the chainedOp, its not getting the right next number.
<SPAN class="comment token">//This will return the next FacilityID</SPAN>
<SPAN class="keyword token">public</SPAN> <SPAN class="keyword token">string</SPAN> <SPAN class="token function">GetNextFacilityID</SPAN><SPAN class="punctuation token">(</SPAN>FeatureClass fClass<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">string</SPAN> gridNum<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">try</SPAN>
<SPAN class="punctuation token">{</SPAN>
QueryFilter queryFilter <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">QueryFilter</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
queryFilter<SPAN class="punctuation token">.</SPAN>WhereClause <SPAN class="operator token">=</SPAN> <SPAN class="string token">"GRIDNO ='"</SPAN> <SPAN class="operator token">+</SPAN> gridNum <SPAN class="operator token">+</SPAN> <SPAN class="string token">"'"</SPAN><SPAN class="punctuation token">;</SPAN>
queryFilter<SPAN class="punctuation token">.</SPAN>SubFields <SPAN class="operator token">=</SPAN> <SPAN class="string token">"SEQUENCENO"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//create an array to hold all of the SEQUENCENO; give it's first member the value zero</SPAN>
ArrayList idList <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">ArrayList</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
idList<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Parse</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"0"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
RowCursor rCursor <SPAN class="operator token">=</SPAN> fClass<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Search</SPAN><SPAN class="punctuation token">(</SPAN>queryFilter<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
Feature feature<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">while</SPAN> <SPAN class="punctuation token">(</SPAN>rCursor<SPAN class="punctuation token">.</SPAN><SPAN class="token function">MoveNext</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">using</SPAN> <SPAN class="punctuation token">(</SPAN>feature <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>Feature<SPAN class="punctuation token">)</SPAN>rCursor<SPAN class="punctuation token">.</SPAN>Current<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">int</SPAN> sequencePosition <SPAN class="operator token">=</SPAN> feature<SPAN class="punctuation token">.</SPAN><SPAN class="token function">FindField</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"SEQUENCENO"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
idList<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Add</SPAN><SPAN class="punctuation token">(</SPAN>Convert<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToInt32</SPAN><SPAN class="punctuation token">(</SPAN>feature<SPAN class="punctuation token">[</SPAN>sequencePosition<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">//sort the list so we can get the highest value of SEQUENCENO</SPAN>
idList<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Sort</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//the next # we want is the current highest number + 1</SPAN>
<SPAN class="keyword token">int</SPAN> number <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">int</SPAN><SPAN class="punctuation token">)</SPAN>idList<SPAN class="punctuation token">[</SPAN>idList<SPAN class="punctuation token">.</SPAN>Count <SPAN class="operator token">-</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN>
sequenceNumber <SPAN class="operator token">=</SPAN> number<SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//convert it to a string so we can add the zero placeholders to the front of it....it needs to be 4 digits.</SPAN>
<SPAN class="keyword token">string</SPAN> finalNum <SPAN class="operator token">=</SPAN> number<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">switch</SPAN> <SPAN class="punctuation token">(</SPAN>finalNum<SPAN class="punctuation token">.</SPAN>Length<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">case</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN>
finalNum <SPAN class="operator token">=</SPAN> <SPAN class="string token">"000"</SPAN> <SPAN class="operator token">+</SPAN> finalNum<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">break</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">case</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">:</SPAN>
finalNum <SPAN class="operator token">=</SPAN> <SPAN class="string token">"00"</SPAN> <SPAN class="operator token">+</SPAN> finalNum<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">break</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">case</SPAN> <SPAN class="number token">3</SPAN><SPAN class="punctuation token">:</SPAN>
finalNum <SPAN class="operator token">=</SPAN> <SPAN class="string token">"0"</SPAN> <SPAN class="operator token">+</SPAN> finalNum<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">break</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token">//return the full facility id, with the STRUCTURETYPE, GRIDNO, and SEQUENCENO</SPAN>
<SPAN class="keyword token">return</SPAN> structureType <SPAN class="operator token">+</SPAN> <SPAN class="string token">"-"</SPAN> <SPAN class="operator token">+</SPAN> gridNumber <SPAN class="operator token">+</SPAN> <SPAN class="string token">"-"</SPAN> <SPAN class="operator token">+</SPAN> finalNum<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">catch</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token class-name">Exception</SPAN> ex<SPAN class="punctuation token">)</SPAN>
<SPAN class="punctuation token">{</SPAN>
ArcGIS<SPAN class="punctuation token">.</SPAN>Desktop<SPAN class="punctuation token">.</SPAN>Framework<SPAN class="punctuation token">.</SPAN>Dialogs<SPAN class="punctuation token">.</SPAN>MessageBox<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Show</SPAN><SPAN class="punctuation token">(</SPAN>ex<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ToString</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>