DatabaseLinkBLL.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Lottomat.Application.Entity.SystemManage;
  2. using Lottomat.Application.IService.SystemManage;
  3. using Lottomat.Application.Service.SystemManage;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data.Common;
  7. using System.Data.SqlClient;
  8. namespace Lottomat.Application.Busines.SystemManage
  9. {
  10. /// <summary>
  11. /// 版 本 1.0
  12. /// Copyright (c) 2016-2017
  13. /// 创建人:赵轶
  14. /// 日 期:2015.11.18 11:02
  15. /// 描 述:数据库连接管理
  16. /// </summary>
  17. public class DataBaseLinkBLL
  18. {
  19. private IDataBaseLinkService service = new DataBaseLinkService();
  20. #region 获取数据
  21. /// <summary>
  22. /// 库连接列表
  23. /// </summary>
  24. /// <returns></returns>
  25. public IEnumerable<DataBaseLinkEntity> GetList()
  26. {
  27. return service.GetList();
  28. }
  29. /// <summary>
  30. /// 库连接实体
  31. /// </summary>
  32. /// <param name="keyValue">主键值</param>
  33. /// <returns></returns>
  34. public DataBaseLinkEntity GetEntity(string keyValue)
  35. {
  36. return service.GetEntity(keyValue);
  37. }
  38. #endregion
  39. #region 提交数据
  40. /// <summary>
  41. /// 删除库连接
  42. /// </summary>
  43. /// <param name="keyValue">主键</param>
  44. public void RemoveForm(string keyValue)
  45. {
  46. try
  47. {
  48. service.RemoveForm(keyValue);
  49. }
  50. catch (Exception)
  51. {
  52. throw;
  53. }
  54. }
  55. /// <summary>
  56. /// 保存库连接表单(新增、修改)
  57. /// </summary>
  58. /// <param name="keyValue">主键值</param>
  59. /// <param name="databaseLinkEntity">库连接实体</param>
  60. /// <returns></returns>
  61. public void SaveForm(string keyValue, DataBaseLinkEntity databaseLinkEntity)
  62. {
  63. try
  64. {
  65. #region 测试连接数据库
  66. DbConnection dbConnection = null;
  67. string ServerAddress = "";
  68. switch (databaseLinkEntity.DbType)
  69. {
  70. case "SqlServer":
  71. dbConnection = new SqlConnection(databaseLinkEntity.DbConnection);
  72. ServerAddress = dbConnection.DataSource;
  73. break;
  74. default:
  75. break;
  76. }
  77. dbConnection.Close();
  78. databaseLinkEntity.ServerAddress = ServerAddress;
  79. #endregion
  80. service.SaveForm(keyValue, databaseLinkEntity);
  81. }
  82. catch (Exception)
  83. {
  84. throw;
  85. }
  86. }
  87. #endregion
  88. }
  89. }