Beispiel #1
0
        public bool DeleteOutright(IList <string> accountGuids)
        {
            bool tmpDeleteResult = false;

            #region DeleteOutrightAccounts

            if (accountGuids != null && accountGuids.Count > 0)
            {
                var tmpDataConnection = ((IDataBase)this).CreateConnection(this.ConnectionString);
                var tmpDeleteCommand  = ((IDataBase)this).CreateCommand( );
                tmpDeleteCommand.Connection  = tmpDataConnection;
                tmpDeleteCommand.CommandType = CommandType.Text;
                tmpDeleteCommand.CommandText = Statement_DeleteByGuid;

                tmpDeleteCommand.Parameters.Add(new SQLiteParameter("@AccountGuid", DbType.String));

                tmpDataConnection.Open( );

                using (DbTransaction tmpDbTransaction = tmpDataConnection.BeginTransaction( ))
                {
                    try
                    {
                        var tmpAttributeAccess = new AccountAttributeSQLiteAccess();
                        foreach (var tmpAccountGuid in accountGuids)
                        {
                            var tmpAccountEntity = this.GetAccountEntityByGuid(tmpAccountGuid, tmpDataConnection);
                            if (tmpAccountEntity != null)
                            {
                                tmpDeleteCommand.Parameters["@AccountGuid"].Value = tmpAccountGuid;
                                tmpDeleteResult = tmpDeleteCommand.ExecuteNonQuery() == 1;
                                if (tmpDeleteResult)
                                {
                                    tmpAttributeAccess.DeleteAccountAttributes(tmpAccountEntity.AccountId, tmpDbTransaction);
                                }
                            }
                        }

                        tmpDbTransaction.Commit( );
                    }
                    catch (System.SystemException exception)
                    {
                        tmpDbTransaction.Rollback( );
                        loger.Error(exception);
                        throw exception;
                    }
                    finally
                    {
                        if (tmpDataConnection.State == ConnectionState.Open)
                        {
                            tmpDataConnection.Close( );
                        }
                        tmpDataConnection.Dispose( );
                    }
                }
            }

            #endregion DeleteOutrightAccounts

            return(tmpDeleteResult);
        }
        public bool EmptyRecycleBin()
        {
            bool tmpDeleteResult = true;

            var tmpAccountEntities = this.GetRecycleBinEntities();

            if (tmpAccountEntities != null && tmpAccountEntities.Count > 0)
            {
                tmpDeleteResult = false;

                var tmpDataConnection = ((IDataBase)this).CreateConnection(this.ConnectionString);
                var tmpDeleteCommand  = ((IDataBase)this).CreateCommand();
                tmpDeleteCommand.Connection  = tmpDataConnection;
                tmpDeleteCommand.CommandType = CommandType.Text;
                tmpDeleteCommand.CommandText = Statement_DeleteOnPK;
                tmpDeleteCommand.Parameters.Add(new SQLiteParameter("@AccountId", DbType.Int32));

                tmpDataConnection.Open();
                var tmpDbTransaction = tmpDataConnection.BeginTransaction();

                var tmpAttributeAccess = new AccountAttributeSQLiteAccess();

                try
                {
                    tmpAccountEntities.ForEach(accountEntity =>
                    {
                        var tmpAccountId = accountEntity.AccountId;
                        tmpDeleteCommand.Parameters["@AccountId"].Value = tmpAccountId;
                        tmpDeleteResult = tmpDeleteCommand.ExecuteNonQuery() > 0;
                        if (tmpDeleteResult)
                        {
                            tmpAttributeAccess.DeleteAccountAttributes(tmpAccountId, tmpDbTransaction);
                        }
                    });

                    tmpDbTransaction.Commit();
                    tmpDeleteResult = true;
                }
                catch (System.SystemException exception)
                {
                    tmpDbTransaction.Rollback();
                    loger.Error(exception);
                    throw exception;
                }
                finally
                {
                    if (tmpDataConnection.State == ConnectionState.Open)
                    {
                        tmpDataConnection.Close();
                    }
                    tmpDataConnection.Dispose();
                }
            }

            return(tmpDeleteResult);
        }