﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Transaction on a form with "save" button from toolstrip... posible?</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Sat, 02 May 2026 11:33:23 GMT</lastBuildDate><ttl>20</ttl><item><title>Transaction on a form with "save" button from toolstrip... posible?</title><link>http://forum.strataframe.net/FindPost30532.aspx</link><description>&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Arial; background-color: rgb(245, 245, 245); font-size: medium; "&gt;Greetings&lt;/span&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&amp;nbsp;Strataframe Forum.&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&amp;nbsp;I'm happy to be using StrataFrame again :).&amp;nbsp;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;my boss&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: rgb(245, 245, 245); "&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;has renewed&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: rgb(245, 245, 245); "&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;my license today&lt;/span&gt;, because that for one or another reasons&amp;nbsp;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;we had to postpone&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: rgb(245, 245, 245); "&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;the development of&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: rgb(245, 245, 245); "&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;our system until&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: rgb(245, 245, 245); "&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;this month after&lt;/span&gt;&lt;span class="Apple-style-span" style="background-color: rgb(245, 245, 245); "&gt;&amp;nbsp;&lt;/span&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;a long long &amp;nbsp;time of inactivity.&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;br/&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;where... I will start with a question to wam up engines&amp;nbsp;&lt;span&gt;:laugh:&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;br/&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;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)&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;br/&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;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.&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;the code that I used is in the end of this post...&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;br/&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;I'm doing this OK or there is a better and automated way setting a property or something else that do it automatically?&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;br/&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;Thanks,&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-family: Arial; background-color: rgb(245, 245, 245); font-size: medium; "&gt;Fabian.&lt;/span&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;br/&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;This is the wrapper code:&amp;nbsp;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;span&gt;[codesnippet]&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;span&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /// &amp;lt;summary&amp;gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /// Saves the changes of all business objects on the form marked with IncludeInFormSave.&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /// &amp;lt;/summary&amp;gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public override SaveUndoResult Save()&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (!SaveWithTransaction)&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return base.Save(false, ""); //if not save with transaction call base routine to save each BO and return...&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // ----------------------------------------------------------------------------------&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // If this form SaveWithTransaction continues here...&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SaveUndoResult saveUndoResult = SaveUndoResult.Success;&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //-- Add a try around the transaction processing&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // This enables the process to call TransactionRollback()&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // if anything bad happens during the transaction process.&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; try&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //-- Start the transaction&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BusinessLayer.TransactionBegin(DataSourceKey, IsolationLevel.ReadCommitted);&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //-- Save the business objects on the transaction&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; saveUndoResult = base.Save(SaveWithTransaction); //&amp;lt;-- here I call that all the BOs be saved in the started transaction (not yet commited to DB)&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //-- When business objects are saved on the transaction, the pending changes to their internal DataTables are NOT saved until TransactionCommit() is called...&amp;nbsp;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // Call transaction commit and &amp;nbsp;queries AND accept the pending changes on all of the business objects&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // that participated in the transaction.&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BusinessLayer.TransactionCommit(DataSourceKey);&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // IF the COMMIT IS succefull this line CLOSE the form WITH a DIALOGresult.OK, otherwise CATCH block IS executed AND rethrow the DB exception....&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CloseFormWithDialogResult(DialogResult.OK);&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch (Exception ex)&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; //-- If an exception occurs during the saving of the records, then&amp;nbsp;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; // abort the transaction.&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BusinessLayer.TransactionRollback(DataSourceKey);&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; throw;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return saveUndoResult;&lt;div&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;&lt;div&gt;&lt;font class="Apple-style-span" size="3" face="Arial" color="#000000"&gt;&lt;span class="hps" style="background-color: rgb(245, 245, 245); "&gt;&lt;span&gt;[/codesnippet]&lt;/span&gt;&lt;/span&gt;&lt;/font&gt;</description><pubDate>Mon, 02 Jan 2012 11:53:48 GMT</pubDate><dc:creator>Fabian R Silva, -</dc:creator></item><item><title>RE: Transaction on a form with "save" button from toolstrip... posible?</title><link>http://forum.strataframe.net/FindPost30761.aspx</link><description>&lt;div&gt;thanks for the reply and advice on child BOs, As I'm using a wrapper and calling base.Save() like the overrided method, I suppose that it have to work as expected and the BO will manage relationships and save all BOs automatically. the diference is that I calling a begin and commit (or rollback) transaction in the override to make it work as a transaction, anything else works as usually using base.Save().&lt;br/&gt;&lt;br/&gt;&lt;div&gt;If I encounter problems later will report it in the forum asking for possible solutions.&lt;br/&gt;&lt;br/&gt;&lt;div&gt;Kind regards and hope a good 2012 for you, all the forum users and all the world :)&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;div&gt;&amp;nbsp;[quote][b]Edhy Rijo (11/8/2011)[/b][hr]Hi Fabian,&lt;br/&gt;I am not a C# developer, but your code looks just fine.&amp;nbsp; One thing to have in may is that when you have related business objects, if you issue a Save() in the child BO, this will automatically trigger a Save() in the parent in order to get the Parent PK Value to be saved in the child BO.&amp;nbsp; I don't recall if that functionality can be overwritten but just in case, in your Save() method make sure you are saving the Parent BO first, then all the child BOs.[/quote]</description><pubDate>Mon, 02 Jan 2012 11:53:48 GMT</pubDate><dc:creator>Fabian R Silva, -</dc:creator></item><item><title>RE: Transaction on a form with "save" button from toolstrip... posible?</title><link>http://forum.strataframe.net/FindPost30547.aspx</link><description>Hi Fabian,&lt;br/&gt;I am not a C# developer, but your code looks just fine.&amp;nbsp; One thing to have in may is that when you have related business objects, if you issue a Save() in the child BO, this will automatically trigger a Save() in the parent in order to get the Parent PK Value to be saved in the child BO.&amp;nbsp; I don't recall if that functionality can be overwritten but just in case, in your Save() method make sure you are saving the Parent BO first, then all the child BOs.</description><pubDate>Tue, 08 Nov 2011 08:34:36 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Transaction on a form with "save" button from toolstrip... posible?</title><link>http://forum.strataframe.net/FindPost30546.aspx</link><description>&lt;span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: arial, sans-serif; font-size: 24px; background-color: rgb(245, 245, 245); "&gt;somebody?&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: arial, sans-serif; font-size: 24px; background-color: rgb(245, 245, 245); "&gt;&lt;br/&gt;&lt;/span&gt;</description><pubDate>Tue, 08 Nov 2011 07:57:08 GMT</pubDate><dc:creator>Fabian R Silva, -</dc:creator></item></channel></rss>