/* * 单页内容 */ using System; using System.Web; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using MySystem.BsModels; using Library; using LitJson; using MySystemLib; namespace MySystem.Areas.Admin.Controllers { [Area("Admin")] [Route("Admin/[controller]/[action]")] public class RightDicNewController : BaseController { public RightDicNewController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { OtherMySqlConn.connstr = ConfigurationManager.AppSettings["BsSqlConnStr"].ToString(); } #region 单页内容列表 /// /// 根据条件查询单页内容列表 /// /// public IActionResult Index(RightDicNew data, string right) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; return View(); } #endregion #region 根据条件查询单页内容列表 /// /// 单页内容列表 /// /// public JsonResult IndexData(RightDicNew data, int page = 1, int limit = 30) { List diclist = bsdb.RightDicNew.OrderBy(m => m.Id).ToList(); foreach (RightDicNew dic in diclist) { int nameLength = dic.Id.Split('_').Length; for (int i = 1; i < nameLength; i++) { dic.Title = "  " + dic.Title; } } Dictionary obj = new Dictionary(); obj.Add("code", 0); obj.Add("msg", ""); obj.Add("count", diclist.Count); obj.Add("data", diclist); return Json(obj); } #endregion #region 添加 /// /// 添加 /// /// public IActionResult Add(string right) { ViewBag.RightInfo = RightInfo; ViewBag.right = right; return View(); } [HttpPost] public string AddPost(RightDicNew data, string PColId) { RightDicNew adddic = new RightDicNew(); string words = "123456789abcdefghijklmnopqrstuvwxyz"; if (!string.IsNullOrEmpty(PColId)) { int Len = PColId.Length + 2; int checkcount = bsdb.RightDicNew.Count(m => m.Id.StartsWith(PColId) && m.Id.Length == Len); if (checkcount > 0) { RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.StartsWith(PColId) && m.Id.Length == Len).OrderByDescending(m => m.Id).FirstOrDefault(); string last_id = ""; string[] idlist = checkdic.Id.Split('_'); last_id = idlist[idlist.Length - 1]; last_id = words.Substring(words.IndexOf(last_id) + 1, 1); adddic.Id = PColId + "_" + last_id; } else { adddic.Id = PColId + "_1"; } } else { int checkcount = bsdb.RightDicNew.Count(m => m.Id.Length == 1); if (checkcount > 0) { RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.Length == 1).OrderByDescending(m => m.Id).FirstOrDefault(); string last_id = words.Substring(words.IndexOf(checkdic.Id) + 1, 1); adddic.Id = PColId + "_" + last_id; } else { adddic.Id = "1"; } } adddic.Name = data.Name; adddic.Icon = data.Icon; adddic.Path = data.Path; adddic.Title = data.Title; // adddic.MainMenu = data.MainMenu; // adddic.MainStat = data.MainStat; // adddic.MainDataList = data.MainDataList; adddic.Url = data.Url; adddic.RightLevel = adddic.Id.Split('_').Length; bsdb.RightDicNew.Add(adddic); AddSysLog(0, "RightDicNew", "add"); bsdb.SaveChanges(); return "success"; } #endregion #region 修改 /// /// 修改 /// /// public IActionResult Edit(string right, string Id = "") { ViewBag.RightInfo = RightInfo; ViewBag.right = right; RightDicNew editData = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id) ?? new RightDicNew(); ViewBag.data = editData; string PColId = ""; if (editData.Id.Contains("_")) { PColId = editData.Id.Substring(0, editData.Id.LastIndexOf("_")); } else { PColId = editData.Id; } ViewBag.OldPColId = PColId; ViewBag.PColId = PColId; return View(); } [HttpPost] public string EditPost(RightDicNew data, string OldPColId, string PColId) { RightDicNew adddic = new RightDicNew(); bool op = false; RightDicNew dic = bsdb.RightDicNew.FirstOrDefault(m => m.Id == data.Id); if (dic != null) { if (OldPColId != PColId) { string words = "123456789abcdefghijklmnopqrstuvwxyz"; if (!string.IsNullOrEmpty(PColId)) { int Len = PColId.Length + 2; int checkcount = bsdb.RightDicNew.Count(m => m.Id.StartsWith(PColId) && m.Id.Length == Len); if (checkcount > 0) { RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.StartsWith(PColId) && m.Id.Length == Len).OrderByDescending(m => m.Id).FirstOrDefault(); string last_id = ""; string[] idlist = checkdic.Id.Split('_'); last_id = idlist[idlist.Length - 1]; last_id = words.Substring(words.IndexOf(last_id) + 1, 1); adddic.Id = PColId + "_" + last_id; } else { adddic.Id = PColId + "_1"; } } else { int checkcount = bsdb.RightDicNew.Count(m => m.Id.Length == 1); if (checkcount > 0) { RightDicNew checkdic = bsdb.RightDicNew.Where(m => m.Id.Length == 1).OrderByDescending(m => m.Id).FirstOrDefault(); string last_id = words.Substring(words.IndexOf(checkdic.Id) + 1, 1); adddic.Id = PColId + "_" + last_id; } else { adddic.Id = "1"; } } adddic.Name = data.Name; adddic.Icon = data.Icon; adddic.Path = data.Path; adddic.Title = data.Title; // adddic.MainMenu = data.MainMenu; // adddic.MainStat = data.MainStat; // adddic.MainDataList = data.MainDataList; adddic.Url = dic.Url; adddic.RightLevel = adddic.Id.Split('_').Length; bsdb.RightDicNew.Remove(dic); op = true; } else { dic.Name = data.Name; dic.Icon = data.Icon; dic.Path = data.Path; dic.Title = data.Title; dic.Url = dic.Url; // dic.MainMenu = data.MainMenu; // dic.MainStat = data.MainStat; // dic.MainDataList = data.MainDataList; } } AddSysLog(data.Id.ToString(), "RightDicNew", "update"); bsdb.SaveChanges(); if (op) { bsdb.RightDicNew.Add(adddic); bsdb.SaveChanges(); } return "success"; } #endregion #region 修改 /// /// 修改 /// /// public IActionResult RightSet(string Id = "") { List rights = bsdb.OperateRightList.ToList(); ViewBag.rights = rights; ViewBag.Id = Id; List RightList = new List(); List MenuRights = bsdb.MenuRightNew.Where(m => m.MenuId.StartsWith(Id)).ToList(); foreach (MenuRightNew sub in MenuRights) { RightList.Add(sub.MenuId.Replace(Id + "_", "") + "_" + sub.Name); } ViewBag.RightList = RightList; RightDicNew editData = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id) ?? new RightDicNew(); ViewBag.OtherRight = editData.OtherRight; return View(); } [HttpPost] public string RightSetPost(string Id, string OtherRight, string RightList) { IQueryable MenuRights = bsdb.MenuRightNew.Where(m => m.MenuId.StartsWith(Id)); foreach (MenuRightNew sub in MenuRights) { bsdb.MenuRightNew.Remove(sub); } bsdb.SaveChanges(); if (!string.IsNullOrEmpty(RightList)) { string[] Rights = RightList.TrimEnd(',').Split(','); foreach (string Right in Rights) { string[] list = Right.Split('_'); bsdb.MenuRightNew.Add(new MenuRightNew() { MenuId = Id + "_" + list[0], Name = list[1], }); } } RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id); if(edit != null) { edit.OtherRight = OtherRight; } bsdb.SaveChanges(); return "success"; } #endregion #region 删除 /// /// 删除 /// /// public string Delete(string Id) { string[] idlist = Id.Split(new char[] { ',' }); foreach (string subid in idlist) { RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == subid); if(edit != null) { bsdb.RightDicNew.Remove(edit); } } AddSysLog(Id, "RightDicNew", "del"); bsdb.SaveChanges(); return "success"; } #endregion #region 排序 /// /// 排序 /// /// public string Sort(string Id, int Sort) { RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id); if (edit != null) { edit.Sort = Sort; bsdb.SaveChanges(); } return "success"; } #endregion #region 设置快捷方式 /// /// 设置快捷方式 /// /// public string SetMainMenu(string Id, bool value) { RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id); if (edit != null) { if (value) { edit.MainMenu = 1; } else { edit.MainMenu = 0; } bsdb.SaveChanges(); } return "success"; } #endregion #region 统计 /// /// 统计 /// /// public string SetMainStat(string Id, bool value) { RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id); if (edit != null) { if (value) { edit.MainStat = 1; } else { edit.MainStat = 0; } bsdb.SaveChanges(); } return "success"; } #endregion #region 主界面数据列表 /// /// 主界面数据列表 /// /// public string SetMainDataList(string Id, bool value) { RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id); if (edit != null) { if (value) { edit.MainDataList = 1; } else { edit.MainDataList = 0; } bsdb.SaveChanges(); } return "success"; } #endregion #region 设置图标 /// /// 设置图标 /// /// public string SetIcon(string Id, string value) { RightDicNew edit = bsdb.RightDicNew.FirstOrDefault(m => m.Id == Id); if (edit != null) { edit.Icon = value; bsdb.SaveChanges(); } return "success"; } #endregion } }