12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Configuration;
- namespace ETD.Data
- {
- /// <summary>
- /// 数据库类创建工厂
- /// </summary>
- public class DBHandlerFactory
- {
- /// <summary>
- /// 获得连接数据的类型
- /// </summary>
- private static string DefaultconnectionType = ConfigurationManager.AppSettings["DefaultDBConnectionType"];
- /// <summary>
- /// 是否是同一个数据库
- /// </summary>
- private static string IsSameDB = ConfigurationManager.AppSettings["IsSameDB"];
- /// <summary>
- /// 各个模块的连接数据库类型的字符串
- /// </summary>
- private static string moduleconnectionType = string.Empty;
- /// <summary>
- /// 创建数据库连接对象
- /// </summary>
- /// <returns>数据库连接对象</returns>
- public static IDBHandlerble CreateDBHander()
- {
- switch (DefaultconnectionType.ToString().ToLower().Trim())
- {
- case "mssql":
- return new SQLDBHandler();
- case "mysql":
- return new MySQLDBHandler();
- case "access":
- return new AccessDBHandler();
- //case "oracle":
- // return new ORACLEDBHandler();
- default:
- return new SQLDBHandler();
- }
- }
- /// <summary>
- /// 创建数据库连接对象,(暂时不使用)
- /// </summary>
- /// <param name="module">某一个模块的关键字</param>
- /// <returns>数据库连接对象</returns>
- public static IDBHandlerble CreateDBHander(string module)
- {
- if (!(IsSameDB == "0"))
- {
- return CreateDBHander();
- }
- if (module == string.Empty)
- {
- module = "Default";
- }
- moduleconnectionType = ConfigurationManager.AppSettings[module + "DBConnectionType"];
- switch (moduleconnectionType.ToString().ToLower().Trim())
- {
- case "mssql":
- return new SQLDBHandler(module);
- case "mysql":
- return new MySQLDBHandler(module);
- case "access":
- return new AccessDBHandler(module);
- //case "oracle":
- // return new ORACLEDBHandler(module);
- default:
- return new SQLDBHandler(module);
- }
- }
- }
- }
|