StrataFrame Forum
Back
Login
Login
Home
»
StrataFrame Application Framework - V1
»
WinForms (How do I?)
»
Transaction on a form with "save" button from toolstrip... posible?
Transaction on a form with "save" button from toolstrip... posible?
Post Reply
Like
3
Transaction on a form with "save" button from toolstrip... posible?
View
Flat Ascending
Flat Descending
Threaded
Options
Subscribe to topic
Print This Topic
RSS Feed
Goto Topics Forum
Author
Message
Fabian R Silva, -
Fabian R Silva, -
posted 13 Years Ago
ANSWER
Topic Details
Share Topic
Group: StrataFrame Users
Posts: 153,
Visits: 1.2K
Greetings
Strataframe Forum.
I'm happy to be using StrataFrame again
.
my 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
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;
}
Tags
Form
Save
Transactions
Reply
Like
3
GO
Merge Selected
Merge into selected topic...
Merge into merge target...
Merge into a specific topic ID...
Open Merge
Threaded View
Threaded View
Transaction on a form with "save" button from toolstrip... posible?
Fabian R Silva, -
-
13 Years Ago
somebody?
Fabian R Silva, -
-
13 Years Ago
Hi Fabian, I am not a C# developer, but your code looks just fine. One...
Edhy Rijo
-
13 Years Ago
thanks for the reply and advice on child BOs, As I'm using a wrapper...
Fabian R Silva, -
-
12 Years Ago
Post Reply
Like
3
Similar Topics
Post Quoted Reply
Reading This Topic
Login
Login
Remember Me
Reset Password
Resend Validation Email
Login
Explore
Messages
Mentions
Search