private void InternalUpdateEntity(DataRow[] Rows, ValidationErrorCollection vaeCollection, UpdateAction UpdateAction, Boolean DoCommit)
{
object Entity = null;
if(Rows.Length == 1)
Entity = Rows[0];
else if(Rows.Length > 1 && Rows[0].Table != null)
Entity = Rows[0].Table;
else
return;
if(vaeCollection.IsCollectionValid && Entity != null)
{
Boolean ConcurrencyError = false;
using(TransactionScope Ts = ( (this.ParentTransaction == null) ? new TransactionScope() : new TransactionScope(this.ParentTransaction)))
{
try
{
if(this.ParentTransaction == null)
this.ParentTransaction = Transaction.Current.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
if(UpdateAction == UpdateAction.Update)
{
if(Entity is ISaveable || Entity is ISaveMultipleRows)
{
if(Entity is ISaveMultipleRows && Rows.Length > 1)
((ISaveMultipleRows)Entity).Save(Rows);
else
((ISaveable)Entity).Save();
}
}
else if(UpdateAction == UpdateAction.Delete)
{
if(Entity is IDeleteable || Entity is IDeleteMultipleRows)
{
if(Entity is IDeleteMultipleRows && Rows.Length > 1)
{
((IDeleteMultipleRows)Entity).DeleteObject(Rows);
if(DoCommit)
((IDeleteMultipleRows)Entity).CommitDeletedObject(Rows);
}
else
{
((IDeleteable)Entity).DeleteObject();
if(DoCommit)
((IDeleteable)Entity).CommitDeletedObject();
}
}
}
Ts.Complete();
}
catch(TransactionAbortedException ex)
{
if(this.DatabaseUpdateError != null)
{
string Message = "Fehler\r\n";
if(ex.InnerException != null)
Message += ex.InnerException.Message + "\r\nStacktrace:" + ex.InnerException.StackTrace;
else
Message += ex.Message + "\r\nStacktrace:" + ex.StackTrace;
this.DatabaseUpdateError(new ExceptionEventArgs(Message));
}
else if(ex.InnerException != null)
throw ex.InnerException;
else
throw ex;
}
catch(DBConcurrencyException dex)
{
if(ConcurrencyErrorOccured != null)
this.ConcurrencyErrorOccured(dex.Row, new EventArgs());
//ConcurrencyError = true;
Ts.Dispose();
return;
}
}
}
}
|