DBHandlerFactory.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Configuration;
  3. namespace ETD.Data
  4. {
  5. /// <summary>
  6. /// 数据库类创建工厂
  7. /// </summary>
  8. public class DBHandlerFactory
  9. {
  10. /// <summary>
  11. /// 获得连接数据的类型
  12. /// </summary>
  13. private static string DefaultconnectionType = ConfigurationManager.AppSettings["DefaultDBConnectionType"];
  14. /// <summary>
  15. /// 是否是同一个数据库
  16. /// </summary>
  17. private static string IsSameDB = ConfigurationManager.AppSettings["IsSameDB"];
  18. /// <summary>
  19. /// 各个模块的连接数据库类型的字符串
  20. /// </summary>
  21. private static string moduleconnectionType = string.Empty;
  22. /// <summary>
  23. /// 创建数据库连接对象
  24. /// </summary>
  25. /// <returns>数据库连接对象</returns>
  26. public static IDBHandlerble CreateDBHander()
  27. {
  28. switch (DefaultconnectionType.ToString().ToLower().Trim())
  29. {
  30. case "mssql":
  31. return new SQLDBHandler();
  32. case "mysql":
  33. return new MySQLDBHandler();
  34. case "access":
  35. return new AccessDBHandler();
  36. //case "oracle":
  37. // return new ORACLEDBHandler();
  38. default:
  39. return new SQLDBHandler();
  40. }
  41. }
  42. /// <summary>
  43. /// 创建数据库连接对象,(暂时不使用)
  44. /// </summary>
  45. /// <param name="module">某一个模块的关键字</param>
  46. /// <returns>数据库连接对象</returns>
  47. public static IDBHandlerble CreateDBHander(string module)
  48. {
  49. if (!(IsSameDB == "0"))
  50. {
  51. return CreateDBHander();
  52. }
  53. if (module == string.Empty)
  54. {
  55. module = "Default";
  56. }
  57. moduleconnectionType = ConfigurationManager.AppSettings[module + "DBConnectionType"];
  58. switch (moduleconnectionType.ToString().ToLower().Trim())
  59. {
  60. case "mssql":
  61. return new SQLDBHandler(module);
  62. case "mysql":
  63. return new MySQLDBHandler(module);
  64. case "access":
  65. return new AccessDBHandler(module);
  66. //case "oracle":
  67. // return new ORACLEDBHandler(module);
  68. default:
  69. return new SQLDBHandler(module);
  70. }
  71. }
  72. }
  73. }