StrataFrame Forum

Using GetEnumerable

http://forum.strataframe.net/Topic20270.aspx

By Bill Cunnien - 10/22/2008

I have the following method:


private void cmdApplyAll_Click(object sender, EventArgs e)
{
   
MessageFunctionType mMft = MessageForm.ShowMessage("Aspire Confirmation", "Are you sure that you want to apply the change to all selected parts?", 1001", MessageFunction.YesNo, MessagingIcon.Question, MessagingSounds.Question);
   
if (mMft == MessageFunctionType.Yes)
    {
        waitWindow1.DisplayTitle =
true;
        waitWindow1.Title =
"Updating Parts";
        waitWindow1.Message =
"Updating the following parts . . . \r";
        waitWindow1.ShowWaitWindow();
       
foreach (PartsBO mBO in partsBO1.GetEnumerable())
        {
            waitWindow1.Message += mBO.partnum +
"\r";
            
mBO.Edit();
           
if (chkProdAppend.Checked) { mBO.prodnotes += txtNewNote.Text; }
           
if (chkProdReplace.Checked) { mBO.prodnotes = txtNewNote.Text; }
           
if (chkShipAppend.Checked) { mBO.shipnotes += txtNewNote.Text; }
           
if (chkShipReplace.Checked) { mBO.shipnotes = txtNewNote.Text; }
            mBO.Save();
        }

        waitWindow1.HideWaitWindow();

    }
}

The code ends up in an infinite loop after the second trip through the partsBO1 BOs.  It keeps repeating the second record.  What am I doing wrong?

Thanks!
Bill

By Edhy Rijo - 10/22/2008

Hi Bill,

I believe the problem is the mBO.Edit() and mBO.Save() enumerating the same BO.  I think you can update all the records you need and do a single partsBO1.Save() at the end of the loop.

By Bill Cunnien - 10/23/2008

Thanks, Edhy!  That was it...I really appreciate the code review. 

Have a great day!
Bill

By Trent L. Taylor - 10/23/2008

Good answer, Edhy. Smile
By Edhy Rijo - 10/23/2008

You are welcome guys! Smile