Exemple #1
0
        /// <summary>
        /// 创建DBHelper实例
        /// </summary>
        /// <param name="connectionString">指定连接字符串</param>
        /// <param name="dataBaseType">指定数据库类型</param>
        /// <returns></returns>
        public static IDBHelper GetDBHelper(string connectionString = null, DataBaseType dataBaseType = DataBaseType.Auto)
        {
            IDBHelper helper = null;

            if (dataBaseType == DataBaseType.Auto)
            {
                dataBaseType = DbConnections.DbType;
            }

            switch (dataBaseType)
            {
            case DataBaseType.SqlServer:
                helper = ReflectHelper.GetInstance("SQLHelper.dll", "SQLHelper.SQLHelper", connectionString) as IDBHelper;
                break;

            case DataBaseType.MySql:
                helper = ReflectHelper.GetInstance("MySQLHelper.dll", "MySQLHelper.MySQLHelper", connectionString) as IDBHelper;
                break;

            case DataBaseType.Oracle:
                helper = ReflectHelper.GetInstance("OracleHelper.dll", "OracleHelper.OracleHelper", connectionString) as IDBHelper;
                break;

            case DataBaseType.Sqlite:
                helper = ReflectHelper.GetInstance("SQLiteHelper.dll", "SQLiteHelper.SQLiteHelper", connectionString) as IDBHelper;
                break;

            default:
                throw new Exception("未知数据库类型");
            }

            return(helper);
        }
Exemple #2
0
        /// <summary>
        /// 获得DAL层实例对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="t"></param>
        /// <returns></returns>
        public static T GetDALInstance <T>()
        {
            string className = typeof(T).Name.Substring(1);
            string spaceName = GetAllDALClassSpace()[TmoShare.currentDBType];
            string path      = string.Format("{0}.{1}Dal", spaceName, className);
            object instance  = ReflectHelper.GetInstance(TmoShare.GetRootPath() + "\\DBDAL.dll", path);

            return((T)instance);
        }
Exemple #3
0
        /// <summary>
        /// 创建DBHelper实例
        /// </summary>
        /// <param name="connectionString">指定连接字符串</param>
        /// <param name="dataBaseType">指定数据库类型</param>
        /// <returns></returns>
        public static IDBHelper GetDBHelper(string connectionString = null, DataBaseType dataBaseType = DataBaseType.Auto)
        {
            IDBHelper helper = null;

            if (dataBaseType == DataBaseType.Auto)
            {
                dataBaseType = DbConnections.DbType;
            }

            Monitor.Enter(_dbHelperCache);
            if (_dbHelperCache.ContainsKey(dataBaseType))
            {
                Monitor.Exit(_dbHelperCache);
                return(_dbHelperCache[dataBaseType]);
            }

            if (connectionString == null)
            {
                connectionString = DbConnections.GetDbConnectionString(dataBaseType);
            }

            switch (dataBaseType)
            {
            case DataBaseType.SqlServer:
                helper = ReflectHelper.GetInstance("SQLHelper.dll", "SQLHelper.SQLHelper", connectionString) as IDBHelper;
                break;

            case DataBaseType.MySql:
                helper = ReflectHelper.GetInstance("MySQLHelper.dll", "MySQLHelper.MySQLHelper", connectionString) as IDBHelper;
                break;

            case DataBaseType.Oracle:
                helper = ReflectHelper.GetInstance("OracleHelper.dll", "OracleHelper.OracleHelper", connectionString) as IDBHelper;
                break;

            case DataBaseType.Sqlite:
                helper = ReflectHelper.GetInstance("SQLiteHelper.dll", "SQLiteHelper.SQLiteHelper", connectionString) as IDBHelper;
                break;

            default:
                Monitor.Exit(_dbHelperCache);
                throw new Exception("未知数据库类型");
            }
            if (helper != null)
            {
                _dbHelperCache.Add(dataBaseType, helper);
            }
            Monitor.Exit(_dbHelperCache);
            return(helper);
        }