Error in Lab2 -- possible fix

Topics: CAB & Smart Client Software Factory
Oct 3, 2005 at 4:07 PM
originally posted by: RTA_SPUD

This may have already been reported but here is what I found and how I fixed it. If this is already known and fixed please excuse the note and let me know the workaround; otherwise, here is what I found and how I fixed it.

Lab 2 uses multiple WorkItems (MDIWorkspace). The problem arises if you attempt to edit more than one Customer ( two MDI windows) at a time. To reproduce .. (1) Accept Changes (2) Select Customer 1 (3) Accept Changes (4) Select Customer 2 (5) Switch back to Customer 1

The above should cause an exception because the Dictionaries attempt to add w/o first checking to see if the item already exists. See the following code -- I have #ifdef to show what WAS and what I changed it to. I'm a newbie to this code so if you see improvements/fixes, etc. please let me know. Otherwise, this was my work around.


#if WAS
Control spcontrol = WorkspaceUtilities.GetSmartPartControl(smartPart);
Form mdiChild = new Form();
SetChildProperties(smartPartInfo, spcontrol, mdiChild);

// the two items will cause a fault with duplicates
this.smartPartDictionary.Add(mdiChild, spcontrol);
this.windowDictionary.Add(spcontrol, mdiChild);

#else
Control spcontrol = WorkspaceUtilities.GetSmartPartControl(smartPart);
Form mdiChild = null;

// check only one, as the other will be based on the first
if (this.windowDictionary.ContainsKey(spcontrol) == false)
{
mdiChild = new Form();
this.windowDictionary.Add(spcontrol, mdiChild);
this.smartPartDictionary.Add(mdiChild, spcontrol);
}
else
{
// just replace for now -- actually, the second statement
// may not be necessary
mdiChild = this.windowDictionaryspcontrol as Form;
// may not be needed -- but ...
this.smartPartDictionarymdiChild = spcontrol;
}
SetChildProperties(smartPartInfo, spcontrol, mdiChild);
#endif