/// <summary> /// 删除权限 /// </summary> public void DeleteAction(int actionId, ref string errMsg) { try { List <SYS_Action> deleteList = null; using (HISDataEntities appEntities = new HISDataEntities()) { SYS_Action actionItem = appEntities.SYS_Action.Where(o => o.ID == actionId).FirstOrDefault(); if (actionItem == null) { errMsg = "查无数据"; return; } actionItem.Flag = 0; deleteList = DeleteActionChildren(appEntities, actionId); deleteList.Add(actionItem); //更新菜单中的ActionNum SYS_ITEMMENU findMenu = appEntities.SYS_ITEMMENU.Where(o => o.ActionNum == actionItem.ActionNum).FirstOrDefault(); if (findMenu != null) { findMenu.ActionNum = string.Empty; } // 保存 appEntities.SaveChanges(); } } catch (Exception e) { errMsg = e.Message; } }
public JsonResult SaveMenu(SYS_ITEMMENU menuItem) { if (menuItem == null) { return(Json(new { result = "error", message = "部门数据不正确" })); } string errMsg = ""; if (menuItem.ParentID == null) { menuItem.ParentID = 0; } if (menuItem.ID == 0) { menuItem.CREATETIME = DateTime.Now; //add menuBll.AddMenu(menuItem, ref errMsg); //Common.LogHelper.InsertLog(String.Format("新增菜单,ID-{0}", menuItem.ToString()), 50, "菜单列表"); } else { //edit menuBll.EditMenu(menuItem, ref errMsg); //Common.LogHelper.InsertLog(String.Format("编辑菜单,ID-{0}", menuItem.ToString()), 50, "菜单列表"); } var result = new { result = "ok", message = "操作成功" }; if (!string.IsNullOrEmpty(errMsg)) { result = new { result = "error", message = errMsg }; } return(Json(result, JsonRequestBehavior.AllowGet)); }
private string CreateMenuNum(SYS_ITEMMENU menu) { string actionCount = "01"; string menuNum = "MN"; SYS_ITEMMENU parentMenu = null; SYS_ITEMMENU lastMenu = null; using (HISDataEntities hisEntities = new HISDataEntities()) { //查找上级菜单 parentMenu = hisEntities.SYS_ITEMMENU.Where(o => o.ID == menu.ParentID).FirstOrDefault(); //查询菜单下最大编号不包括自己和已经删除的 lastMenu = hisEntities.SYS_ITEMMENU.Where(o => o.ParentID == menu.ParentID).OrderByDescending(o => o.MenuNum).FirstOrDefault(); } if (lastMenu != null) { var str = lastMenu.MenuNum.Substring(lastMenu.MenuNum.Length - 2, 2); int number = Convert.ToInt32(str) + 1; actionCount = number.ToString().PadLeft(2, '0'); } if (parentMenu != null) { menuNum = parentMenu.MenuNum + actionCount; return(menuNum); } return(menuNum + actionCount); }
/// <summary> /// 添加菜单 /// </summary> /// <param name="menuItem"></param> /// <param name="errMsg"></param> public void AddMenu(SYS_ITEMMENU menuItem, ref string errMsg) { try { using (HISDataEntities hisEntities = new HISDataEntities()) { menuItem.MenuNum = CreateMenuNum(menuItem); menuItem.CREATETIME = DateTime.Now; menuItem.STATE = "open"; //更新上级菜单state 为 closeed var findItem = hisEntities.SYS_ITEMMENU.Where(o => o.ID == menuItem.ParentID).FirstOrDefault(); if (findItem != null) { findItem.STATE = "closed"; } menuItem.CHECKED = true; menuItem.SEQ = 1;//排序 hisEntities.SYS_ITEMMENU.Add(menuItem); hisEntities.SaveChanges(); } } catch (Exception e) { errMsg = e.Message; } }
private Hashtable InitMenuGridTreeChildren(List <SYS_ITEMMENU> menuList, SYS_ITEMMENU item) { Hashtable ht = new Hashtable(); ht.Add("ID", item.ID); ht.Add("Text", item.TEXT); ht.Add("MenuNum", item.MenuNum); ht.Add("Url", item.URL); ht.Add("IconCls", item.ICON); //ht.Add("Disc", item.Disc); ht.Add("MenuState", item.STATE); ht.Add("CreateTime", Convert.ToDateTime(item.CREATETIME).ToString("yyyy-MM-dd HH:mm:ss")); ht.Add("ParentID", item.ParentID); ht.Add("OrderIndex", item.ORDERINDEX); var childrenList = menuList.Where(o => o.ParentID == item.ID).OrderBy(o => o.ORDERINDEX); if (childrenList.Count() > 0) { List <Hashtable> htList = new List <Hashtable>(); foreach (SYS_ITEMMENU childrenItem in childrenList) { Hashtable childrenHt = InitMenuGridTreeChildren(menuList, childrenItem); htList.Add(childrenHt); } ht.Add("children", htList); } return(ht); }
public ActionResult Dialog(int Id) { if (Id < 1) { SYS_ITEMMENU addItem = new SYS_ITEMMENU() { MenuNum = "自动生成" }; return(View(addItem)); } string errMsg = string.Empty; SYS_ITEMMENU menuItem = menuBll.GetAppMenuByID(Id, ref errMsg); if (!string.IsNullOrEmpty(errMsg)) { return(View(new SYS_ITEMMENU())); } return(View(menuItem)); }
/// <summary> /// 编辑菜单 /// </summary> /// <param name="menuItem"></param> /// <param name="errMsg"></param> public void EditMenu(SYS_ITEMMENU menuItem, ref string errMsg) { try { using (HISDataEntities appEntities = new HISDataEntities()) { var findItem = appEntities.SYS_ITEMMENU.Where(o => o.ID == menuItem.ID).FirstOrDefault(); findItem.TEXT = menuItem.TEXT; findItem.ParentID = menuItem.ParentID; findItem.MenuNum = menuItem.MenuNum; //findItem.Disc = menuItem.Disc; findItem.ICON = menuItem.ICON; findItem.URL = menuItem.URL; findItem.ORDERINDEX = menuItem.ORDERINDEX; appEntities.SaveChanges(); } } catch (Exception e) { errMsg = e.Message; } }