DBConnection.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace LYFZ.WanYuKeFuData.Model
  6. {
  7. public class DBConnection : LYFZ.WinAPI.IDBConnection
  8. {
  9. public DBConnection()
  10. {
  11. }
  12. public DBConnection(string enterpriseID, string ip, int port)
  13. {
  14. this.SetBJBCloudServerDBString(enterpriseID,ip,port);
  15. }
  16. string _DataBaseServer;
  17. /// <summary>
  18. /// 数据库服务器地址(服务器名)
  19. /// </summary>
  20. public string DataBaseServer
  21. {
  22. get { return _DataBaseServer; }
  23. set { _DataBaseServer = value; }
  24. }
  25. int _DataBasePort;
  26. /// <summary>
  27. /// 端口
  28. /// </summary>
  29. public int DataBasePort
  30. {
  31. get { return _DataBasePort; }
  32. set { _DataBasePort = value; }
  33. }
  34. string _DataBaseUser;
  35. /// <summary>
  36. /// 用户
  37. /// </summary>
  38. public string DataBaseUser
  39. {
  40. get { return _DataBaseUser; }
  41. set { _DataBaseUser = value; }
  42. }
  43. string _DataBasePass;
  44. /// <summary>
  45. /// 密码
  46. /// </summary>
  47. public string DataBasePass
  48. {
  49. get { return _DataBasePass; }
  50. set { _DataBasePass = value; }
  51. }
  52. string _DataBaseName;
  53. /// <summary>
  54. /// 数据库名
  55. /// </summary>
  56. public string DataBaseName
  57. {
  58. get { return _DataBaseName; }
  59. set { _DataBaseName = value; }
  60. }
  61. /// <summary>
  62. /// 获取数据库连接字任串
  63. /// </summary>
  64. [Newtonsoft.Json.JsonIgnore]
  65. public string DBConnectionString
  66. {
  67. get
  68. {
  69. return GetDBConnectionString();
  70. }
  71. }
  72. /// <summary>
  73. /// 设置铂金版云数据库
  74. /// </summary>
  75. /// <param name="enterpriseID"></param>
  76. public void SetBJBCloudServerDBString(string enterpriseID,string ip,int port)
  77. {
  78. this.DataBaseServer = ip;
  79. this.DataBasePort = port;
  80. this.DataBaseName = "DB" + enterpriseID;
  81. this.DataBaseUser = "SA" + enterpriseID;
  82. this.DataBasePass = "PW@" + enterpriseID;
  83. }
  84. /// <summary>
  85. /// 获取数据库连接字任串
  86. /// </summary>
  87. /// <returns></returns>
  88. public string GetDBConnectionString()
  89. {
  90. string temp_DataBaseServer = _DataBaseServer;
  91. if (_DataBasePort > 0)
  92. {
  93. temp_DataBaseServer = string.Format("{0},{1}", _DataBaseServer, _DataBasePort.ToString());
  94. }
  95. return String.Format("Data Source={0};Initial Catalog={1};User ID={2};Password={3}", temp_DataBaseServer, _DataBaseName, _DataBaseUser, _DataBasePass);
  96. }
  97. }
  98. }