public void SaveDataCollectionThroughCollection(Boolean requiredTransaction, String conName, params IEnumerable[] saveItems) { CommandExecutor command; Boolean blnBeginTrans = false; CustomList<BaseItem> itemNew; CustomList<BaseItem> itemUpdate; CustomList<BaseItem> itemDelete; try { if (saveItems.IsNull() || saveItems.Count().IsZero()) { throw new Exception("Collection not Initialized"); } if (requiredTransaction.IsFalse()) { if (conName.Length > 0) { OpenConnection(conName); } else { OpenConnection(String.Empty); } } if (disconnection.IsNotNull()) { if (requiredTransaction.IsFalse()) { transaction = disconnection.BeginTransaction(IsolationLevel.ReadUncommitted); blnBeginTrans = true; } else { if (transaction.IsNull()) { throw new Exception("Transaction is not initialized"); } blnBeginTrans = true; } } else { throw new Exception("Connection is not initialized"); } //For Delete saveItems = saveItems.Reverse(); foreach (IEnumerable saveList in saveItems) { CustomList<BaseItem> saveItemBase = saveList.ToCustomList<BaseItem>(); itemDelete = saveItemBase.GetChanges(ItemState.Deleted); switch (ProviderType) { case Util.ConnectionLibrary.SQlClient: command = new CommandExecutor(transaction, ProviderType); if (itemDelete.IsNotNull() && itemDelete.Count.NotEquals(0)) { command.Update(itemDelete, Util.OperationType.Delete); } break; } } //For Insert Update saveItems = saveItems.Reverse(); foreach (IEnumerable saveList in saveItems) { CustomList<BaseItem> saveItemBase = saveList.ToCustomList<BaseItem>(); itemNew = saveItemBase.GetChanges(ItemState.Added); itemUpdate = saveItemBase.GetChanges(ItemState.Modified); switch (ProviderType) { case Util.ConnectionLibrary.SQlClient: command = new CommandExecutor(transaction, ProviderType); if (itemNew.IsNotNull() && itemNew.Count.NotEquals(0)) { command.Update(itemNew, Util.OperationType.Insert); } if (itemUpdate.IsNotNull() && itemUpdate.Count.NotEquals(0)) { command.Update(itemUpdate, Util.OperationType.Update); } break; } } if (requiredTransaction.IsFalse()) { if (blnBeginTrans) { transaction.Commit(); blnBeginTrans = false; } disconnection.Close(); disconnection.Dispose(); disconnection = null; } } catch (OleDbException exOleDb) { if (blnBeginTrans && requiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (exOleDb); } catch (DBConcurrencyException exDbce) { if (blnBeginTrans && requiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (exDbce); } catch (Exception ex) { if (blnBeginTrans && requiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (ex); } }
//zaki - Insert record and get Scope_Identity() public object SaveDataCollectionThroughCollection(Boolean requiredTransaction, String conName, Util.CrudType opMode, IEnumerable saveItem) { CommandExecutor command; Boolean blnBeginTrans = false; CustomList<BaseItem> itemNew; try { if (saveItem.IsNull()) { throw new Exception("Collection not Initialized"); } if (requiredTransaction.IsFalse()) { if (conName.Length > 0) { OpenConnection(conName); } else { OpenConnection(String.Empty); } } if (disconnection.IsNotNull()) { if (requiredTransaction.IsFalse()) { transaction = disconnection.BeginTransaction(IsolationLevel.ReadUncommitted); blnBeginTrans = true; } else { if (transaction.IsNull()) { throw new Exception("Transaction is not initialized"); } blnBeginTrans = true; } } else { throw new Exception("Connection is not initialized"); } CustomList<BaseItem> saveItemBase = saveItem.ToCustomList<BaseItem>(); itemNew = saveItemBase.GetChanges(ItemState.Added); object retVal = null; switch (ProviderType) { case Util.ConnectionLibrary.SQlClient: command = new CommandExecutor(transaction, ProviderType); if (itemNew.IsNotNull() && itemNew.Count.NotEquals(0)) { retVal = command.Insert(itemNew, Util.OperationType.Insert); } break; default: break; } if (requiredTransaction.IsFalse()) { if (blnBeginTrans) { transaction.Commit(); blnBeginTrans = false; } disconnection.Close(); disconnection.Dispose(); disconnection = null; } return retVal; } catch (OleDbException exOleDb) { if (blnBeginTrans && requiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (exOleDb); } catch (DBConcurrencyException exDbce) { if (blnBeginTrans && requiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (exDbce); } catch (Exception ex) { if (blnBeginTrans && requiredTransaction.IsFalse()) { transaction.Rollback(); if (disconnection.IsNotNull()) { if (disconnection.State == ConnectionState.Open) { disconnection.Close(); } disconnection.Dispose(); disconnection = null; } } throw (ex); } }