private void CreateMenuItem(StringBuilder html, List <SYS_Menu> menus, SYS_Menu menu, bool flag) { html.AppendLine("<li class='layui-nav-item " + (index == 0 ? "layui-this" : "") + "'>"); var childMenus = menus.Where(x => x.MenuParentID == menu.MenuID).OrderBy(x => x.OrderBy).ToList(); if (index == 0) { html.AppendLine(@"<a title='" + menu.MenuName + "' href='javascript:;' class='menu site-demo-active' data-type='tabAdd' nonce='0'><i class='layui-icon " + menu.IconCode + "'></i> <span>" + menu.MenuName + "</span></a>"); } else if (!flag) { html.AppendLine(@"<a title='" + menu.MenuName + "' href='javascript:;' class='menu'><i class='layui-icon " + menu.IconCode + "'></i> <span>" + menu.MenuName + "</span></a>"); } else { html.AppendLine(@"<a title='" + menu.MenuName + "' href='javascript:;' lay-href='" + menu.MenuUrl + "' class='menu site-demo-active' data-type='tabAdd' nonce='" + index + "'> <span>" + menu.MenuName + "</span></a>"); } index++; if (childMenus.Count != 0) { html.AppendLine("<dl class='layui-nav-child'>"); foreach (var child in childMenus) { html.AppendLine("<dd>"); CreateMenuItem(html, menus, child, true); html.AppendLine("</dd>"); } html.AppendLine("</dl>"); } html.AppendLine("</li>"); }
/// <summary> /// 删除菜单 /// </summary> /// <param name="id">菜单ID</param> /// <returns></returns> public bool DeleteMenu(Guid id) { using (var db = base.GDDSVSPDb) { SYS_Menu menu = db.SYS_Menu.SingleOrDefault(p => p.MenuID == id); db.SYS_Menu.Remove(menu); return(db.SaveChanges() > 0); } }
public JsonResult InsertMenu(SYS_Menu menu) { JsonResult result = new JsonResult(); try { bool isSuccess = menuService.InsertMenu(menu); log.Info("添加成功"); } catch (Exception e) { log.Error(e.Message); } finally { result = Json(new { msg = "添加成功" }, JsonRequestBehavior.AllowGet); } return(result); }
protected void BindTreeView(string strMenu) { tvModel.Nodes.Clear(); DataSet ds = dal.GetSYSMenuIndustryByWhere(" a.[Parent] = '' "); foreach (DataRow row in ds.Tables[0].Rows) { SYS_Menu model = DataConvert.DataRowToModel <SYS_Menu>(row); string name = model.Name; string id = model.No; TreeNode td = new TreeNode(name, id); if (strMenu.Contains(id)) { td.Checked = true; } td.SelectAction = TreeNodeSelectAction.None; BindChildTree(td, strMenu); tvModel.Nodes.Add(td); } tvModel.ExpandAll(); }
/// <summary> /// 添加菜单 /// </summary> /// <param name="menu">菜单对象</param> /// <returns></returns> public bool InsertMenu(SYS_Menu menu) { try { using (var transaction = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted })) { using (var db = base.GDDSVSPDb) { menu.MenuID = Guid.NewGuid(); db.SYS_Menu.Add(menu); int ndel = Convert.ToInt32(IsDel.未删除); int isdel = Convert.ToInt32(IsDel.已删除); List <SYS_Button> btnList = db.SYS_Button.Where(p => p.IsDel == ndel).ToList(); List <SYS_REL_MenuButton> mblist = new List <SYS_REL_MenuButton>(); foreach (var item in btnList) { SYS_REL_MenuButton mb = new SYS_REL_MenuButton() { ID = Guid.NewGuid(), BtnCode = item.BtnCode, MenuCode = menu.MenuCode, State = isdel }; mblist.Add(mb); } db.SYS_REL_MenuButton.BulkInsert(mblist); db.BulkSaveChanges(); } transaction.Complete(); } } catch (DbEntityValidationException ex) { throw ex; } return(true); }
public static string DeleteSysMenu(string menu_id, string user_id, string RequestID) { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "delete")) { throw new Exception("No Access."); } LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); SYS_Menu the_record = (from sysm in dc.SYS_Menus where sysm.MenuID == menu_id && sysm.Active == true select sysm).FirstOrDefault(); if (the_record == null) { return("Error ~ We can't find"); } the_record.Active = false; the_record.ModifiedOn = DateTime.Now; the_record.ModifiedBy = user_id; the_record.LastAction = Guid.NewGuid().ToString(); dc.SubmitChanges(); return("Success~"); }
/// <summary> /// 修改菜单 /// </summary> /// <param name="obj">菜单对象</param> /// <returns></returns> public bool UpdateMenu(MenuVO obj) { try { using (var db = base.GDDSVSPDb) { SYS_Menu menu = db.SYS_Menu.SingleOrDefault(p => p.MenuID == obj.MenuID); menu.MenuID = obj.MenuID; menu.MenuName = obj.MenuName; menu.MenuParentID = obj.MenuParentID; menu.MenuCode = obj.MenuCode; menu.MenuUrl = obj.MenuUrl; menu.OrderBy = obj.OrderBy; menu.IconCode = obj.IconCode; return(db.SaveChanges() > 0); } } catch (DbEntityValidationException ex) { throw ex; } }
public static string ChangeSysMenu(string menu_ids, string oldnoteMenuID, string noteMenuID, string RequestID) { LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); //List<SYS_MenuView> childMenus = (from c in dc.SYS_MenuViews where c.NoteMenuID == noteMenuID && c.Active == true orderby c.MenuSeq select c).ToList(); string[] menu_child_ids = menu_ids.Split(','); for (int i = 0; i < menu_child_ids.Length; i++) { SYS_Menu child_menu = (from c in dc.SYS_Menus where c.MenuID == menu_child_ids[i] && c.Active == true select c).FirstOrDefault(); if (oldnoteMenuID != noteMenuID) { if (noteMenuID == "#") { child_menu.IsNode = true; child_menu.NoteMenuID = ""; } else { child_menu.NoteMenuID = noteMenuID; child_menu.IsNode = false; } } child_menu.ModifiedBy = RequestID; child_menu.ModifiedOn = DateTime.Now; child_menu.MenuSeq = i + 2; child_menu.LastAction = Guid.NewGuid().ToString(); try { dc.SubmitChanges(); } catch (Exception ex) { return("Fail~"); } } return("Success~"); }
public static string SaveSysMenu(string menu_id, string user_id, string menu_name, string menu_label, string menu_icon, string menu_linkpage, string menu_onclick, string menu_seq, string is_node, string noteMenuID, string RequestID) { try { LINQ_SystemDataContext dc = new LINQ_SystemDataContext(); SYS_Menu the_record = new SYS_Menu(); if (menu_id == "" || menu_id == null) { the_record = (from sysm in dc.SYS_Menus where sysm.MenuID == menu_id && sysm.Active == true select sysm).FirstOrDefault(); if (the_record == null) { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "create")) { throw new Exception("No Access."); } the_record = new SYS_Menu() { CreatedBy = user_id, CreatedOn = DateTime.Now, Active = true, MenuID = Guid.NewGuid().ToString(), LastAction = Guid.NewGuid().ToString(), NoteMenuID = Guid.NewGuid().ToString() }; dc.SYS_Menus.InsertOnSubmit(the_record); } } else { //Security Check if (!Controller_User_Access.CheckProgramAccess(AccessProgramCode, RequestID, "update")) { throw new Exception("No Access."); } the_record = (from sysm in dc.SYS_Menus where sysm.MenuID == menu_id && sysm.Active == true select sysm).FirstOrDefault(); if (the_record == null) { throw new Exception("System cannot find the record"); } } the_record.ModifiedBy = user_id; the_record.ModifiedOn = DateTime.Now; the_record.LastAction = Guid.NewGuid().ToString(); the_record.MenuName = menu_name; the_record.MenuLabel = menu_label; the_record.IconClass = menu_icon; the_record.MenuLinkPage = menu_linkpage; the_record.MenuOnClick = menu_onclick; the_record.MenuSeq = Convert.ToDecimal(menu_seq.ToString()); if (is_node == "true") { the_record.IsNode = true; the_record.NoteMenuID = ""; } else { the_record.IsNode = false; the_record.NoteMenuID = noteMenuID; } dc.SubmitChanges(); return("Success~" + the_record.MenuName); } catch (Exception ex) { return("Error~" + ex.Message); } }