StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



BO's BeforeSave EventExpand / Collapse
Author
Message
Posted 01/23/2006 5:20:31 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 02/04/2008 8:43:02 AM
Posts: 176, Visits: 1,519
In the BeforeSave event on my BO I am adding records to a secondary table using another BO.  This secondary BO is adding the records correctly,  but it appears that the BeforeSave event on the primary BO is fireing twice.  Any suggestion on what I should be checking.

Scott

Post #464
Posted 01/24/2006 8:45:01 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 11:24:42 AM
Posts: 2,686, Visits: 1,889
Are you saving through the form, or directly on the BO? Maybe you could post a little code snippet of where you're actually calling the save and how your business objects are configured...


www.bungie.net
Post #465
Posted 01/24/2006 10:07:01 AM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 02/04/2008 8:43:02 AM
Posts: 176, Visits: 1,519
I am using a Maintenance form and the only thing that is set on the BO is the required fields collection.  Here are some of the methods on the BO itself.

        private void SFCategoryBO_CheckRulesOnCurrentRow(CheckRulesEventArgs e)

        {

            if (!this.CategoryDescriptionIsUnique())

                this.AddBrokenRule(SFCategoryBOFieldNames.CatDesc,

                    Localization.RetrieveTextValue("DuplicateCategoryDescription"));

        }

        private void SFCategoryBO_SetDefaultValues()

        {

            this.Created = DateTime.Now;

            this.CreatedUsrID = oApp.oUser.UserID;

        }

        private void SFCategoryBO_BeforeSave(MicroFour.StrataFrame.Data.BeforeSaveUndoEventArgs e)

        {

            System.Console.WriteLine("Before Save Event - " + DateTime.Now.ToString());

            this.LastUpd = DateTime.Now;

            this.LastUpdUsrID = oApp.oUser.UserID;

        }

I end up with two "Before Save Event" messages in the console.

Post #468
Posted 01/24/2006 12:46:01 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 11:24:42 AM
Posts: 2,686, Visits: 1,889
Within your InitializeComponent() method, of the business object, you should find a line similar to:

this.BeforeSave += new BeforeSaveEventHandler(SFCategoryBO_BeforeSave);

Make sure you don't have two of those lines.

Also, are you doing anything special like using the business object on a child form that's shown through a ChildFormDialog, or within a UserControl?

I've checked, and there's no place that the event is being raised twice, but it's possible that the event handler is being added twice...


www.bungie.net
Post #470
Posted 01/24/2006 1:33:14 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 02/04/2008 8:43:02 AM
Posts: 176, Visits: 1,519
Did not find any duplicate handlers.  Try this,  I went to the Strataframe sample windows application and added a beforesave event by double clicking on the event in the property sheet.  I then put the following code in the event:

System.Console.WriteLine("Before Save Event")

run the form, locate a record, click the edit button, (do nothing) click the save button, and look in the console, there is two "Before Save Event" messages. Is this the expected result?  I hope I just am not miss-understanding how the event is supposed to work.

Post #472
Posted 01/25/2006 8:47:46 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 11:24:42 AM
Posts: 2,686, Visits: 1,889
OK, found the problem... there was an event that was being raised from within the DataLayer, not the BusinessLayer, and it was getting bubbled up and re-raised from within the BusinessLayer. I'll get the update posted on the Developers blog shortly (running all of my unit tests right now) and then we'll get the install rebuilt.

So, no, your concept of the BeforeSave event is the same as our concept of the BeforeSave event... it should only be firing once.


www.bungie.net
Post #473
Posted 01/25/2006 10:25:41 AM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 02/04/2008 8:43:02 AM
Posts: 176, Visits: 1,519
Great.  Nice to know I am not going crazy and starting to understand how the framework works.  How would you debug something like an event anyway?  I wouldn't even know the first place to start.

Scott

Post #475
Posted 01/26/2006 9:48:33 AM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: Today @ 11:24:42 AM
Posts: 2,686, Visits: 1,889
Hehe, events are special... it's quite difficult to debug them. Within the framework, where we call RaiseEvent, you can step into the line and you will step into all of the methods attached to that event.

BTW, the update is posted on the Developers Blog.


www.bungie.net
Post #477
Posted 01/26/2006 10:43:10 AM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 02/04/2008 8:43:02 AM
Posts: 176, Visits: 1,519
Thanks for the update.  Works great.
Post #481