using Lottomat.Application.Busines.SystemManage; using Lottomat.Application.Code; using Lottomat.Application.Entity.SystemManage; using Lottomat.Util; using Lottomat.Util.WebControl; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Lottomat.Utils; namespace Lottomat.Application.Admin.Areas.SystemManage.Controllers { /// /// 版 本 1.0 /// Copyright (c) 2016-2017 /// 创建人:赵轶 /// 日 期:2015.11.18 11:02 /// 描 述:数据库连接管理 /// public class DataBaseLinkController : MvcControllerBase { private DataBaseLinkBLL databaseLinkBLL = new DataBaseLinkBLL(); #region 视图功能 /// /// 库连接管理 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Index() { return View(); } /// /// 库连接表单 /// /// [HttpGet] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult Form() { return View(); } #endregion #region 获取数据 /// /// 库连接列表 /// /// 关键字查询 /// 返回树形Json [HttpGet] public ActionResult GetTreeJson(string keyword) { var data = databaseLinkBLL.GetList(); var dataIp = data.Distinct(new Comparint("ServerAddress")); var treeList = new List(); foreach (DataBaseLinkEntity item in dataIp) { TreeEntity tree = new TreeEntity(); tree.id = item.ServerAddress; tree.text = item.ServerAddress; tree.value = item.ServerAddress; tree.parentId = "0"; tree.isexpand = true; tree.complete = true; tree.hasChildren = true; treeList.Add(tree); } foreach (DataBaseLinkEntity item in data) { TreeEntity tree = new TreeEntity(); tree.id = item.DatabaseLinkId; tree.text = item.DBAlias; tree.value = item.DatabaseLinkId; tree.title = item.DBName; tree.parentId = item.ServerAddress; tree.isexpand = true; tree.complete = true; tree.hasChildren = false; treeList.Add(tree); } return Content(treeList.TreeToJson()); } /// /// 库连接列表 /// /// 关键字查询 /// 返回树形列表Json [HttpGet] public ActionResult GetListJson(string keyword) { var data = databaseLinkBLL.GetList(); //测试环境防止用户获得连接串 //foreach (var item in data) //{ // item.ServerAddress = "******"; // item.DbConnection = "******"; //} return ToJsonResult(data); } /// /// 库连接实体 /// /// 主键值 /// 返回对象Json [HttpGet] public ActionResult GetFormJson(string keyValue) { var data = databaseLinkBLL.GetEntity(keyValue); //测试环境防止用户获得连接串 //data.ServerAddress = "******"; //data.DbConnection = "******"; return ToJsonResult(data); } #endregion #region 提交数据 /// /// 删除库连接 /// /// 主键值 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] [HandlerAuthorize(PermissionMode.Enforce)] public ActionResult RemoveForm(string keyValue) { databaseLinkBLL.RemoveForm(keyValue); return Success("删除成功。"); } /// /// 保存库连接表单(新增、修改) /// /// 主键值 /// 库连接实体 /// [HttpPost] [ValidateAntiForgeryToken] [AjaxOnly] public ActionResult SaveForm(string keyValue, DataBaseLinkEntity databaseLinkEntity) { //测试环境防止用户修改连接串 if (!string.IsNullOrEmpty(keyValue)) { return Success("测试环境,修改数据库连接无效。"); } databaseLinkBLL.SaveForm(keyValue, databaseLinkEntity); return Success("操作成功。"); } #endregion } }