SysDbInfo.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using SqlSugar;
  2. using System;
  3. using System.Configuration;
  4. namespace WMS.Core
  5. {
  6. public class SysDbInfo: ConfigurationSection
  7. {
  8. /// <summary>
  9. /// 获取配置信息
  10. /// </summary>
  11. /// <returns></returns>
  12. public static SysDbInfo GetConfig()
  13. {
  14. return GetConfig("databaseconfig");
  15. }
  16. /// <summary>
  17. /// 获取配置信息
  18. /// </summary>
  19. /// <param name="sectionName">xml节点名称</param>
  20. /// <returns></returns>
  21. public static SysDbInfo GetConfig(string sectionName)
  22. {
  23. var t = ConfigurationManager.GetSection(sectionName);
  24. SysDbInfo section = (SysDbInfo)t;
  25. if (section == null)
  26. throw new ConfigurationErrorsException("Section " + sectionName + " is not found.");
  27. return section;
  28. }
  29. /// <summary>
  30. /// 数据库连接名
  31. /// </summary>
  32. [ConfigurationProperty("DbSetNo", IsRequired = false, DefaultValue = "BaseDB")]
  33. public string DbSetNo
  34. {
  35. get
  36. {
  37. return base["DbSetNo"].ToString();
  38. }
  39. set
  40. {
  41. base["DbSetNo"] = value;
  42. }
  43. }
  44. /// <summary>
  45. /// 数据库连接字符串
  46. /// </summary>
  47. [ConfigurationProperty("ConnectionString", IsRequired = false)]
  48. public string ConnectionString
  49. {
  50. get
  51. {
  52. return base["ConnectionString"].ToString();
  53. }
  54. set
  55. {
  56. base["ConnectionString"] = value;
  57. }
  58. }
  59. /// <summary>
  60. /// 必填, 数据库类型
  61. /// </summary>
  62. [ConfigurationProperty("DataBaseType", IsRequired = false, DefaultValue = DbType.SqlServer)]
  63. public DbType DataBaseType
  64. {
  65. get
  66. {
  67. return (DbType)base["DataBaseType"];
  68. }
  69. set
  70. {
  71. base["DataBaseType"] = value;
  72. }
  73. }
  74. /// <summary>
  75. /// 默认SystemTable, 字段信息读取, 如:该属性是不是主键,是不是标识列等等信息
  76. /// </summary>
  77. [ConfigurationProperty("InitKey", IsRequired = false, DefaultValue = InitKeyType.SystemTable)]
  78. public InitKeyType InitKey
  79. {
  80. get
  81. {
  82. return (InitKeyType)base["InitKey"];
  83. }
  84. set
  85. {
  86. base["InitKey"] = value;
  87. }
  88. }
  89. /// <summary>
  90. /// 默认false, 时候知道关闭数据库连接, 设置为true无需使用using或者Close操作
  91. /// </summary>
  92. [ConfigurationProperty("IsAutoCloseConn", IsRequired = false, DefaultValue=true)]
  93. public bool IsAutoCloseConn
  94. {
  95. get
  96. {
  97. return (bool)base["IsAutoCloseConn"];
  98. }
  99. set
  100. {
  101. base["IsAutoCloseConn"] = value;
  102. }
  103. }
  104. }
  105. }