Transaction on a form with "save" button from toolstrip... posible?


Author
Message
Fabian R Silva, -
Fabian R Silva, -
StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)StrataFrame User (267 reputation)
Group: StrataFrame Users
Posts: 153, Visits: 1.2K
Greetings Strataframe Forum.
 I'm happy to be using StrataFrame again Smilemy boss has renewed my license today, because that for one or another reasons we had to postpone the development of our system until this month after a long long  time of inactivity.

where... I will start with a question to wam up engines Laugh

I'm building a "base" form to inherit from this in all my system's forms later. I see that the "Save" method of the form doen't allow to make a transaction automatically with all the BOs that are marked with "incluideInFormSave", then I suppose that if I have 2 BOs (Parent-Child) and the child have errors the Parent BO be saved and the child not.... (this is not transactional)

I overrides the form's Save method and wrap the base save method with a transaction... it appears to work but I not sure if I doing it well.
the code that I used is in the end of this post...

I'm doing this OK or there is a better and automated way setting a property or something else that do it automatically? 

Thanks, Fabian.

This is the wrapper code: 
        /// <summary>
        /// Saves the changes of all business objects on the form marked with IncludeInFormSave.
        /// </summary>
        /// <returns></returns>
        public override SaveUndoResult Save()
        {
            if (!SaveWithTransaction)
                return base.Save(false, ""); //if not save with transaction call base routine to save each BO and return...

            // ----------------------------------------------------------------------------------
            // If this form SaveWithTransaction continues here...
            SaveUndoResult saveUndoResult = SaveUndoResult.Success;

            //-- Add a try around the transaction processing
            // This enables the process to call TransactionRollback()
            // if anything bad happens during the transaction process.
            try
            {
                //-- Start the transaction
                BusinessLayer.TransactionBegin(DataSourceKey, IsolationLevel.ReadCommitted);

                //-- Save the business objects on the transaction
                saveUndoResult = base.Save(SaveWithTransaction); //<-- here I call that all the BOs be saved in the started transaction (not yet commited to DB)

                //-- When business objects are saved on the transaction, the pending changes to their internal DataTables are NOT saved until TransactionCommit() is called... 
                // Call transaction commit and  queries AND accept the pending changes on all of the business objects
                // that participated in the transaction.
                BusinessLayer.TransactionCommit(DataSourceKey);

                // IF the COMMIT IS succefull this line CLOSE the form WITH a DIALOGresult.OK, otherwise CATCH block IS executed AND rethrow the DB exception....
                CloseFormWithDialogResult(DialogResult.OK);
            }
            catch (Exception ex)
            {
                //-- If an exception occurs during the saving of the records, then 
                // abort the transaction.
                BusinessLayer.TransactionRollback(DataSourceKey);
                throw;
            }

            return saveUndoResult;
        }

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