Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - DBManager(pDBManagerType, pConnectionString)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="pDBManagerType">데이타베이스 관리자 종류</param>
        /// <param name="pConnectionString">연결 문자열</param>
        public DBManager(DBManagerType pDBManagerType, string pConnectionString)
        {
            try
            {
                _pDBManagerType    = pDBManagerType;
                _pConnectionString = pConnectionString;
                _pDbConnection     = GetDbConnection(pDBManagerType, pConnectionString);
                _pDbTransaction    = null;
                _nCommandTimeout   = 300;

                if (_pDbConnection.State == ConnectionState.Open)
                {
                    return;
                }

                _pDbConnection.Open();
            }
            catch (ExceptionManager pExceptionManager)
            {
                throw pExceptionManager;
            }
            catch (Exception pException)
            {
                throw new ExceptionManager
                      (
                          this,
                          "DBManager(pDBManagerType, pConnectionString)",
                          pException
                      );
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 데이타베이스 데이타 어댑터 구하기
        /// </summary>
        /// <param name="pDBManagerType">데이타베이스 관리자 종류</param>
        /// <returns>데이타베이스 데이타 어댑터</returns>
        private DbDataAdapter GetDbDataAdapter(DBManagerType pDBManagerType)
        {
            try
            {
                switch (pDBManagerType)
                {
                case DBManagerType.SQLServer: return(new SqlDataAdapter());

                case DBManagerType.Oracle: return(new OracleDataAdapter());

                case DBManagerType.MySql: return(new MySqlDataAdapter());

                case DBManagerType.OleDB: return(new OleDbDataAdapter());

                default: return(null);
                }
            }
            catch (Exception pException)
            {
                throw new ExceptionManager
                      (
                          this,
                          "GetDbDataAdapter(pDBManagerType)",
                          pException
                      );
            }
        }
Exemplo n.º 3
0
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Static

        #region 생성자 - DBManager()

        /// <summary>
        /// 생성자
        /// </summary>
        static DBManager()
        {
            try
            {
                string strPrimaryDBManagerType = ConfigurationManager.GetApplicationSetting("DBManagerType");

                switch (strPrimaryDBManagerType)
                {
                case "SQLServer": _pPrimaryDBManagerType = DBManagerType.SQLServer; break;

                case "Oracle": _pPrimaryDBManagerType = DBManagerType.Oracle; break;

                case "MySql": _pPrimaryDBManagerType = DBManagerType.MySql; break;

                default: _pPrimaryDBManagerType = DBManagerType.OleDB; break;
                }

                _pPrimaryConnectionString = ConfigurationManager.GetApplicationSetting("ConnectionString");
            }
            catch (ExceptionManager pExceptionManager)
            {
                throw pExceptionManager;
            }
            catch (Exception pException)
            {
                throw new ExceptionManager
                      (
                          typeof(DBManager),
                          "DBManager()",
                          pException
                      );
            }
        }
Exemplo n.º 4
0
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 데이타베이스 연결 구하기 - GetDbConnection(pDBManagerType, pConnectionString)

        /// <summary>
        /// 데이타베이스 연결 구하기
        /// </summary>
        /// <param name="pDBManagerType">데이타베이스 관리자 종류</param>
        /// <param name="pConnectionString">연결 문자열</param>
        /// <returns>데이타베이스 연결</returns>
        private DbConnection GetDbConnection(DBManagerType pDBManagerType, string pConnectionString)
        {
            try
            {
                switch (pDBManagerType)
                {
                case DBManagerType.SQLServer: return(new SqlConnection(pConnectionString));

                case DBManagerType.Oracle: return(new OracleConnection(pConnectionString));

                case DBManagerType.MySql: return(new MySqlConnection(pConnectionString));

                default: return(new OleDbConnection(pConnectionString));
                }
            }
            catch (Exception pException)
            {
                throw new ExceptionManager
                      (
                          this,
                          "GetDbConnection(pDBManagerType, pConnectionString)",
                          pException
                      );
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// 데이타 매개 변수 목록 설정하기
        /// </summary>
        /// <param name="pDBManagerType">데이타베이스 관리자 종류</param>
        /// <param name="pArguments">인자 목록</param>
        /// <returns>데이타 매개 변수 목록</returns>
        private IDataParameter[] GetDataParameters(DBManagerType pDBManagerType, object[] pArguments)
        {
            try
            {
                IDataParameter[] pDataParameters;

                switch (pDBManagerType)
                {
                case DBManagerType.SQLServer: pDataParameters = new SqlParameter[pArguments.Length]; break;

                case DBManagerType.Oracle: pDataParameters = new OracleParameter[pArguments.Length]; break;

                case DBManagerType.MySql: pDataParameters = new MySqlParameter[pArguments.Length]; break;

                case DBManagerType.OleDB: pDataParameters = new OleDbParameter[pArguments.Length]; break;

                default: return(null);
                }

                for (int i = 0; i < pArguments.Length; i++)
                {
                    pDataParameters[i] = GetDbParameter(pDBManagerType);

                    switch (pDBManagerType)
                    {
                    case DBManagerType.SQLServer: pDataParameters[i].ParameterName = string.Format(_strSQLServerParameterFormat, i); break;

                    case DBManagerType.Oracle: pDataParameters[i].ParameterName = string.Format(_strOracleParameterFormat, i); break;

                    case DBManagerType.MySql: pDataParameters[i].ParameterName = string.Format(_strMySQLParameterFormat, i); break;

                    case DBManagerType.OleDB: pDataParameters[i].ParameterName = string.Format(_strOLEDBParameterFormat, i); break;

                    default: pDataParameters[i].ParameterName = string.Format(_strSQLServerParameterFormat, i); break;
                    }

                    pDataParameters[i].Value = pArguments[i];
                }

                return(pDataParameters);
            }
            catch (Exception pException)
            {
                throw new ExceptionManager
                      (
                          this,
                          "GetDataParameterArray(pDBManagerType, pArguments)",
                          pException
                      );
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 데이타베이스 명령 구하기
        /// </summary>
        /// <param name="pDBManagerType">데이타베이스 관리자 종류</param>
        /// <param name="nCommandTimeout">명령 시간 제한</param>
        /// <param name="pCommandType">명령 종류</param>
        /// <param name="strCommandText">명령문</param>
        /// <param name="pDataParameters">데이타 매개 변수 목록</param>
        /// <returns>데이타베이스 명령</returns>
        private DbCommand GetDbCommand(DBManagerType pDBManagerType, int nCommandTimeout, CommandType pCommandType, string strCommandText, IDataParameter[] pDataParameters)
        {
            try
            {
                DbCommand pDbCommand;

                switch (pDBManagerType)
                {
                case DBManagerType.SQLServer: pDbCommand = new SqlCommand(); break;

                case DBManagerType.Oracle: pDbCommand = new OracleCommand(); break;

                case DBManagerType.MySql: pDbCommand = new MySqlCommand(); break;

                case DBManagerType.OleDB: pDbCommand = new OleDbCommand(); break;

                default: return(null);
                }

                pDbCommand.Connection     = _pDbConnection;
                pDbCommand.CommandType    = pCommandType;
                pDbCommand.CommandText    = strCommandText;
                pDbCommand.CommandTimeout = nCommandTimeout;

                if (pDataParameters != null)
                {
                    foreach (DbParameter pDbParameter in pDataParameters)
                    {
                        pDbCommand.Parameters.Add(pDbParameter);
                    }
                }

                if (_pDbTransaction != null)
                {
                    pDbCommand.Transaction = _pDbTransaction;
                }

                return(pDbCommand);
            }
            catch (Exception pException)
            {
                throw new ExceptionManager
                      (
                          this,
                          "GetDbCommand(pDBManagerType, nCommandTimeout, pCommandType, strCommandText, pDataParameters)",
                          pException
                      );
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// 반환 데이타베이스 매개 변수 구하기
 /// </summary>
 /// <param name="pDBManagerType">데이타베이스 관리자 종류</param>
 /// <param name="pDataType">데이타 종류</param>
 /// <param name="nDataSize">데이타 크기</param>
 /// <param name="byDataScale">데이타 정밀도</param>
 /// <returns>데이타베이스 매개 변수</returns>
 private DbParameter GetReturnDbParameter(DBManagerType pDBManagerType, DbType pDataType, int nDataSize, byte byDataScale)
 {
     try
     {
         return(GetDbParameter(pDBManagerType, "ReturnValue", ParameterDirection.ReturnValue, pDataType, nDataSize, byDataScale));
     }
     catch (ExceptionManager pExceptionManager)
     {
         throw pExceptionManager;
     }
     catch (Exception pException)
     {
         throw new ExceptionManager
               (
                   this,
                   "GetReturnDbParameter(pDBManagerType, pDataType, nDataSize, byDataScale)",
                   pException
               );
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// 데이타베이스 매개 변수 구하기
        /// </summary>
        /// <param name="pDBManagerType">데이타베이스 관리자 종류</param>
        /// <param name="strParameterName">매개 변수명</param>
        /// <param name="pParameterDirection">매개 변수 방향</param>
        /// <param name="pDataType">데이타 종류</param>
        /// <param name="nDataSize">데이타 크기</param>
        /// <param name="byDataScale">데이타 정밀도</param>
        /// <returns>데이타베이스 매개 변수</returns>
        private DbParameter GetDbParameter(DBManagerType pDBManagerType, string strParameterName, ParameterDirection pParameterDirection, DbType pDataType, int nDataSize, byte byDataScale)
        {
            try
            {
                DbParameter pDbParameter;

                switch (pDBManagerType)
                {
                case DBManagerType.SQLServer: pDbParameter = new SqlParameter(); break;

                case DBManagerType.Oracle: pDbParameter = new OracleParameter(); break;

                case DBManagerType.MySql: pDbParameter = new MySqlParameter(); break;

                case DBManagerType.OleDB: pDbParameter = new OleDbParameter(); break;

                default: return(null);
                }

                pDbParameter.ParameterName = strParameterName;
                pDbParameter.Direction     = pParameterDirection;
                pDbParameter.DbType        = pDataType;
                pDbParameter.Size          = nDataSize;

                if (pDbParameter.GetType() == typeof(SqlParameter))
                {
                    (pDbParameter as SqlParameter).Scale = byDataScale;
                }

                return(pDbParameter);
            }
            catch (Exception pException)
            {
                throw new ExceptionManager
                      (
                          this,
                          "GetDbParameter(strParameterName, pParameterDirection, pDataType, nDataSize, byDataScale)",
                          pException
                      );
            }
        }