using System;
using System.Configuration;
namespace ETD.Data
{
///
/// 数据库类创建工厂
///
public class DBHandlerFactory
{
///
/// 获得连接数据的类型
///
private static string DefaultconnectionType = ConfigurationManager.AppSettings["DefaultDBConnectionType"];
///
/// 是否是同一个数据库
///
private static string IsSameDB = ConfigurationManager.AppSettings["IsSameDB"];
///
/// 各个模块的连接数据库类型的字符串
///
private static string moduleconnectionType = string.Empty;
///
/// 创建数据库连接对象
///
/// 数据库连接对象
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();
}
}
///
/// 创建数据库连接对象,(暂时不使用)
///
/// 某一个模块的关键字
/// 数据库连接对象
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);
}
}
}
}