コード例 #1
0
        private static void DbExecute <T>(GetResultList <T> getResultList, TransactionStateType transactionStateType, ref DbTransaction trans, ref IList <T> iList, DbConnection dbConnection, DbCommand dbCommand)
        {
            bool tranBoolValue = false;

            try
            {
                if (transactionStateType == TransactionStateType.Open)
                {
                    tranBoolValue = true;
                }
                if (tranBoolValue)
                {
                    trans = dbConnection.BeginTransaction();
                }
                if (tranBoolValue)
                {
                    dbCommand.Transaction = trans;
                }

                if (getResultList != null)
                {
                    iList = getResultList(dbCommand);
                }
                if (tranBoolValue)
                {
                    trans.Commit();
                }
            }
            catch (Exception ex)
            {
                if (tranBoolValue)
                {
                    trans.Rollback();
                }
                throw new Exception(GetCommandString(dbCommand), ex);
            }
        }
コード例 #2
0
        private static void DbExecute <T>(GetResult <T> getResult, IList <IList <DbParameter> > ListDataParameter, TransactionStateType transactionStateType, ref DbTransaction trans, ref T t, DbConnection dbConnection, DbCommand dbCommand)
        {
            bool tranBoolValue = false;

            try
            {
                if (transactionStateType == TransactionStateType.Open)
                {
                    tranBoolValue = true;
                }
                if (tranBoolValue)
                {
                    trans = dbConnection.BeginTransaction();
                }
                if (tranBoolValue)
                {
                    dbCommand.Transaction = trans;
                }

                if (ListDataParameter != null)
                {
                    DbCommand SingleDbCommand = null;
                    for (int i = 0; i < ListDataParameter.Count; i++)
                    {
                        SingleDbCommand = dbCommand;
                        SingleDbCommand.Parameters.Clear();
                        if (ListDataParameter[i] != null)
                        {
                            for (int j = 0; j < ListDataParameter[i].Count; j++)
                            {
                                SingleDbCommand.Parameters.Add(ListDataParameter[i][j]);
                            }
                        }
                        if (getResult != null)
                        {
                            t = getResult(SingleDbCommand);
                        }
                    }
                }

                if (tranBoolValue)
                {
                    trans.Commit();
                }
            }
            catch (Exception ex)
            {
                if (tranBoolValue)
                {
                    trans.Rollback();
                }
                t = default(T);
                string str = GetCommandString(dbCommand);
                // LogHelper.WriterError(EnumLogCategory.Data, str, typeof(DbHelper), ex);
                throw new Exception(str, ex);
            }
        }
コード例 #3
0
        private static void DbExecute <T>(GetResult <T> getResult, IList <DbParameter> ListDataParameter, TransactionStateType transactionStateType, ref DbTransaction trans, ref T t, DbConnection dbConnection, DbCommand dbCommand)
        {
            IList <IList <DbParameter> > TempListDbParm = new List <IList <DbParameter> >();

            TempListDbParm.Add(ListDataParameter);
            DbExecute <T>(getResult, TempListDbParm, transactionStateType, ref trans, ref t, dbConnection, dbCommand);
        }
コード例 #4
0
        public IList <T> GetDataList <T>(string SqlStr, CommandType commandType, GetResultList <T> getResultList, IList <DbParameter> ListDataParameter, TransactionStateType transactionStateType)
        {
            trans = null;
            IList <T> iList = new List <T>();

            using (DbConnection dbConnection = this.CreateConnection())
            {
                dbConnection.Open();

                DbCommand dbCommand = GetDbCommand(dbConnection, SqlStr, commandType);
                dbCommand.CommandTimeout = 180;
                SetParameter(ListDataParameter, dbCommand);

                DbExecute <T>(getResultList, transactionStateType, ref trans, ref iList, dbConnection, dbCommand);

                dbConnection.Close();
            }
            return(iList);
        }
コード例 #5
0
 public IList <T> GetDataList <T>(string SqlStr, CommandType commandType, GetResultList <T> getResultList, TransactionStateType transactionStateType)
 {
     return(GetDataList <T>(SqlStr, commandType, getResultList, null, transactionStateType));
 }
コード例 #6
0
        public T GetData <T>(IList <string> SqlStrList, CommandType commandType, GetResult <T> getResult, IList <IList <DbParameter> > ListDataParameter, TransactionStateType transactionStateType) where T : new()
        {
            trans = null;
            T t = default(T);

            using (DbConnection dbConnection = this.CreateConnection())
            {
                dbConnection.Open();
                DbCommand dbCommand = null;
                dbCommand = GetDbCommand(dbConnection, null, commandType);

                DbExecute <T>(getResult, ListDataParameter, transactionStateType, ref trans, ref t, dbConnection, dbCommand, SqlStrList);

                dbConnection.Close();
            }
            return(t);
        }
コード例 #7
0
        public T GetData <T>(string SqlStr, CommandType commandType, GetResult <T> getResult, TransactionStateType transactionStateType) where T : new()
        {
            IList <DbParameter> ListDataParameter = null;

            return(GetData <T>(SqlStr, commandType, getResult, ListDataParameter, transactionStateType));
        }