BO's BeforeSave Event


Author
Message
Scott
Scott
StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)
Group: Forum Members
Posts: 176, Visits: 1.5K
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

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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...
Scott
Scott
StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)
Group: Forum Members
Posts: 176, Visits: 1.5K
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.

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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...
Scott
Scott
StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)
Group: Forum Members
Posts: 176, Visits: 1.5K
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.


StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.
Scott
Scott
StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)
Group: Forum Members
Posts: 176, Visits: 1.5K
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

StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
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.
Scott
Scott
StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)StrataFrame User (270 reputation)
Group: Forum Members
Posts: 176, Visits: 1.5K
Thanks for the update.  Works great.
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
No problem, we'll get the install rebuilt and posted as soon as we can Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search