DataBaseLinkController.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using Lottomat.Application.Busines.SystemManage;
  2. using Lottomat.Application.Code;
  3. using Lottomat.Application.Entity.SystemManage;
  4. using Lottomat.Util;
  5. using Lottomat.Util.WebControl;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Web.Mvc;
  9. using Lottomat.Utils;
  10. namespace Lottomat.Application.Admin.Areas.SystemManage.Controllers
  11. {
  12. /// <summary>
  13. /// 版 本 1.0
  14. /// Copyright (c) 2016-2017
  15. /// 创建人:赵轶
  16. /// 日 期:2015.11.18 11:02
  17. /// 描 述:数据库连接管理
  18. /// </summary>
  19. public class DataBaseLinkController : MvcControllerBase
  20. {
  21. private DataBaseLinkBLL databaseLinkBLL = new DataBaseLinkBLL();
  22. #region 视图功能
  23. /// <summary>
  24. /// 库连接管理
  25. /// </summary>
  26. /// <returns></returns>
  27. [HttpGet]
  28. [HandlerAuthorize(PermissionMode.Enforce)]
  29. public ActionResult Index()
  30. {
  31. return View();
  32. }
  33. /// <summary>
  34. /// 库连接表单
  35. /// </summary>
  36. /// <returns></returns>
  37. [HttpGet]
  38. [HandlerAuthorize(PermissionMode.Enforce)]
  39. public ActionResult Form()
  40. {
  41. return View();
  42. }
  43. #endregion
  44. #region 获取数据
  45. /// <summary>
  46. /// 库连接列表
  47. /// </summary>
  48. /// <param name="keyword">关键字查询</param>
  49. /// <returns>返回树形Json</returns>
  50. [HttpGet]
  51. public ActionResult GetTreeJson(string keyword)
  52. {
  53. var data = databaseLinkBLL.GetList();
  54. var dataIp = data.Distinct(new Comparint<DataBaseLinkEntity>("ServerAddress"));
  55. var treeList = new List<TreeEntity>();
  56. foreach (DataBaseLinkEntity item in dataIp)
  57. {
  58. TreeEntity tree = new TreeEntity();
  59. tree.id = item.ServerAddress;
  60. tree.text = item.ServerAddress;
  61. tree.value = item.ServerAddress;
  62. tree.parentId = "0";
  63. tree.isexpand = true;
  64. tree.complete = true;
  65. tree.hasChildren = true;
  66. treeList.Add(tree);
  67. }
  68. foreach (DataBaseLinkEntity item in data)
  69. {
  70. TreeEntity tree = new TreeEntity();
  71. tree.id = item.DatabaseLinkId;
  72. tree.text = item.DBAlias;
  73. tree.value = item.DatabaseLinkId;
  74. tree.title = item.DBName;
  75. tree.parentId = item.ServerAddress;
  76. tree.isexpand = true;
  77. tree.complete = true;
  78. tree.hasChildren = false;
  79. treeList.Add(tree);
  80. }
  81. return Content(treeList.TreeToJson());
  82. }
  83. /// <summary>
  84. /// 库连接列表
  85. /// </summary>
  86. /// <param name="keyword">关键字查询</param>
  87. /// <returns>返回树形列表Json</returns>
  88. [HttpGet]
  89. public ActionResult GetListJson(string keyword)
  90. {
  91. var data = databaseLinkBLL.GetList();
  92. //测试环境防止用户获得连接串
  93. //foreach (var item in data)
  94. //{
  95. // item.ServerAddress = "******";
  96. // item.DbConnection = "******";
  97. //}
  98. return ToJsonResult(data);
  99. }
  100. /// <summary>
  101. /// 库连接实体
  102. /// </summary>
  103. /// <param name="keyValue">主键值</param>
  104. /// <returns>返回对象Json</returns>
  105. [HttpGet]
  106. public ActionResult GetFormJson(string keyValue)
  107. {
  108. var data = databaseLinkBLL.GetEntity(keyValue);
  109. //测试环境防止用户获得连接串
  110. //data.ServerAddress = "******";
  111. //data.DbConnection = "******";
  112. return ToJsonResult(data);
  113. }
  114. #endregion
  115. #region 提交数据
  116. /// <summary>
  117. /// 删除库连接
  118. /// </summary>
  119. /// <param name="keyValue">主键值</param>
  120. /// <returns></returns>
  121. [HttpPost]
  122. [ValidateAntiForgeryToken]
  123. [AjaxOnly]
  124. [HandlerAuthorize(PermissionMode.Enforce)]
  125. public ActionResult RemoveForm(string keyValue)
  126. {
  127. databaseLinkBLL.RemoveForm(keyValue);
  128. return Success("删除成功。");
  129. }
  130. /// <summary>
  131. /// 保存库连接表单(新增、修改)
  132. /// </summary>
  133. /// <param name="keyValue">主键值</param>
  134. /// <param name="databaseLinkEntity">库连接实体</param>
  135. /// <returns></returns>
  136. [HttpPost]
  137. [ValidateAntiForgeryToken]
  138. [AjaxOnly]
  139. public ActionResult SaveForm(string keyValue, DataBaseLinkEntity databaseLinkEntity)
  140. {
  141. //测试环境防止用户修改连接串
  142. if (!string.IsNullOrEmpty(keyValue))
  143. {
  144. return Success("测试环境,修改数据库连接无效。");
  145. }
  146. databaseLinkBLL.SaveForm(keyValue, databaseLinkEntity);
  147. return Success("操作成功。");
  148. }
  149. #endregion
  150. }
  151. }