public static void ThreadTransactionMgrReset() { TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr(); try { if (txMgr.txCount > 0 && txMgr.hasRolledBack == false) { txMgr.RollbackTransaction(); } } catch {} Thread.SetData(txMgrSlot, null); }
virtual public void Save() { if (_dataTable == null) { return; } if (!_canSave) { throw new Exception("Cannot call Save() after Query.AddResultColumn()"); } TransactionMgr txMgr = TransactionMgr.ThreadTransactionMgr(); try { bool needToInsert = false; bool needToUpdate = false; bool needToDelete = false; DataRow row; DataRowCollection rows = _dataTable.Rows; for (int i = 0; i < rows.Count; i++) { row = rows[i]; switch (row.RowState) { case DataRowState.Added: needToInsert = true; break; case DataRowState.Modified: needToUpdate = true; break; case DataRowState.Deleted: needToDelete = true; break; } } if (needToInsert || needToUpdate || needToDelete) { IDbDataAdapter da = this.CreateIDbDataAdapter(); if (needToInsert) { da.InsertCommand = GetInsertCommand(); } if (needToUpdate) { da.UpdateCommand = GetUpdateCommand(); } if (needToDelete) { da.DeleteCommand = GetDeleteCommand(); } txMgr.BeginTransaction(); int txCount = txMgr.NestingCount; if (txCount > 1) { txMgr.AddBusinessEntity(this); } if (needToInsert) { txMgr.Enlist(da.InsertCommand, this); } if (needToUpdate) { txMgr.Enlist(da.UpdateCommand, this); } if (needToDelete) { txMgr.Enlist(da.DeleteCommand, this); } DbDataAdapter dbDataAdapter = ConvertIDbDataAdapter(da); this.HookupRowUpdateEvents(dbDataAdapter); dbDataAdapter.Update(_dataTable); txMgr.CommitTransaction(); if (txCount == 1) { this.AcceptChanges(); } if (needToInsert) { txMgr.DeEnlist(da.InsertCommand, this); } if (needToUpdate) { txMgr.DeEnlist(da.UpdateCommand, this); } if (needToDelete) { txMgr.DeEnlist(da.DeleteCommand, this); } } } catch (Exception ex) { if (txMgr != null) { txMgr.RollbackTransaction(); } throw ex; } }