public void r100Implementation(SystemMenuModel instance) { using (XmlReader reader = XmlReader.Create(HttpContext.Current.Server.MapPath("~/web.sitemap"))) { string title = string.Empty; while (reader.Read()) { if (reader.IsStartElement()) { switch (reader.Name) { case "siteMapNode": string name = reader["title"]; string description = reader["description"]; string url = reader["url"]; string roles = reader["roles"] == null?string.Empty:reader["roles"]; if (!name.Contains('^')) //if (title != null && description != null && url != null && roles != null && !name.Contains('^')) { using (SqlProcedure sp = new SqlProcedure("sp_ConfigSystemMenu")) { if (description != string.Empty) { //sp.AddParameter("@title", title); sp.AddParameter("@name", name); sp.AddParameter("@description", description); sp.AddParameter("@url", url); sp.AddParameter("@roles", roles); sp.AddParameter("@username", Context.User.Identity.Name); sp.ExecuteScalar(); } } //if (description == string.Empty) //{ // title = reader["title"]; //} //else if (title != string.Empty) //{ // using (SqlProcedure sp = new SqlProcedure("sp_ConfigSystemMenu")) // { // sp.AddParameter("@title", title); // sp.AddParameter("@name", name); // sp.AddParameter("@description", description); // sp.AddParameter("@url", url); // sp.AddParameter("@roles", roles); // sp.AddParameter("@username", Context.User.Identity.Name); // sp.ExecuteScalar(); // } //} } break; } } } } }
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { SystemMenuModel systemMenu = (SystemMenuModel)e.Item.DataItem; Repeater repeater = (Repeater)e.Item.FindControl("Repeater1_2"); List <SqlWhere> sqlWhereList = new List <SqlWhere>(); sqlWhereList.Add(new SqlWhere(SystemMenuModel.FATHERID, SqlWhere.Oper.Equal, systemMenu.Pkid)); sqlWhereList.Add(new SqlWhere(SystemMenuModel.ENABLED, SqlWhere.Oper.Equal, true)); List <SystemMenuModel> systemMenuList = bll_systemMenu.GetList(sqlWhereList); repeater.DataSource = systemMenuList; repeater.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { WebUtility.AdminLoginAuth(); systemMenu = bll_systemMenu.GetModel(Request.QueryString["pkid"]); if (systemMenu == null) { systemMenu = new SystemMenuModel(); } if (!Page.IsPostBack) { BindInfo(); } }
public void r101Implementation(SystemMenuModel instance) { System.Collections.ArrayList mass = new System.Collections.ArrayList(); System.Collections.ArrayList key1 = new System.Collections.ArrayList(); System.Collections.ArrayList key2 = new System.Collections.ArrayList(); System.Collections.ArrayList key3 = new System.Collections.ArrayList(); using (SqlText sql = new SqlText(String.Format("SELECT PageName, PageDescription, PageRoles, PageUrl FROM SystemMenu"))) { System.Data.Common.DbDataReader readerSender = sql.ExecuteReader(); while (readerSender.Read()) { //Web.Sitemap XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(HttpContext.Current.Server.MapPath("~/Web.sitemap")); XmlNodeList elementList = xmlDoc.GetElementsByTagName("siteMapNode"); foreach (XmlNode node in elementList) { if (node.Attributes["title"].Value == readerSender["PageName"].ToString()) { XmlAttribute description = xmlDoc.CreateAttribute("description"); node.Attributes.Append(description); node.Attributes["description"].Value = readerSender["PageDescription"].ToString(); XmlAttribute url = xmlDoc.CreateAttribute("url"); node.Attributes.Append(url); node.Attributes["url"].Value = readerSender["PageUrl"].ToString(); XmlAttribute roles = xmlDoc.CreateAttribute("roles"); node.Attributes.Append(roles); node.Attributes["roles"].Value = readerSender["PageRoles"].ToString(); xmlDoc.Save(HttpContext.Current.Server.MapPath("~/Web.sitemap")); } } //Web.config xmlDoc = new XmlDocument(); xmlDoc.Load(HttpContext.Current.Server.MapPath("~/web.config")); bool pathXml = true; elementList = xmlDoc.GetElementsByTagName("location"); foreach (XmlNode node in elementList) { if (node.Attributes["path"].Value == readerSender["PageUrl"].ToString().Substring(2)) { //node.InnerXml pathXml = false; string rp = "<system.web><authorization><allow roles=\"" + readerSender["PageRoles"].ToString() + "\" /><deny users=\" * \" /></authorization></system.web>"; node.InnerXml = rp; xmlDoc.Save(HttpContext.Current.Server.MapPath("~/web.config")); } } if (pathXml && readerSender["PageRoles"].ToString() != "*") { XmlElement locationNode = xmlDoc.CreateElement("location"); locationNode.SetAttribute("path", readerSender["PageUrl"].ToString().Substring(2)); XmlNodeList elementListConfig = xmlDoc.GetElementsByTagName("configuration"); XmlElement swNode = xmlDoc.CreateElement("system.web"); locationNode.AppendChild(swNode); XmlElement authorizationNode = xmlDoc.CreateElement("authorization"); swNode.AppendChild(authorizationNode); XmlElement allowNode = xmlDoc.CreateElement("allow"); allowNode.SetAttribute("roles", readerSender["PageRoles"].ToString()); authorizationNode.AppendChild(allowNode); XmlElement denyNode = xmlDoc.CreateElement("deny"); denyNode.SetAttribute("users", " * "); authorizationNode.AppendChild(denyNode); foreach (XmlNode nodeConfig in elementListConfig) { nodeConfig.AppendChild(locationNode); xmlDoc.Save(HttpContext.Current.Server.MapPath("~/web.config")); } } } readerSender.Close(); readerSender.Dispose(); } }
/// <summary> /// 执行操作的方法 /// </summary> private void Action() { string cmd = Request["cmd"]; if (String.IsNullOrEmpty(cmd)) { return; } string ids = Request.QueryString["ids"]; if (cmd == "moveup") { bll_systemMenu.MoveUp(ids); } else if (cmd == "movedown") { bll_systemMenu.MoveDown(ids); } else if (cmd == "onoff") { bll_systemMenu.UpdateStatus(ids, "onoff"); } else if (cmd == "enab") { bll_systemMenu.UpdateStatus(ids, "enab"); } else if (cmd == "del") { bll_systemMenu.Delete(ids); } else if (cmd == "updateall") { foreach (string key in Request.Form.AllKeys) { if (key.StartsWith("title")) { string title = Request.Form[key]; string url = Request.Form[key.Replace("title", "url")]; if (String.IsNullOrEmpty(title)) { continue; } if (key.IndexOf("#") > 0) { string fid = Request.Form[key.Replace("title", "fid")]; if (!StringHelper.IsNumber(fid)) { continue; } SystemMenuModel systemMenu = new SystemMenuModel(); systemMenu.Title = title; systemMenu.Url = url; systemMenu.FatherId = Convert.ToInt32(fid); bll_systemMenu.Insert(systemMenu); } else { string id = key.Replace("title", ""); SystemMenuModel systemMenu = bll_systemMenu.GetModel(id); if (systemMenu == null) { continue; } systemMenu.Title = title; systemMenu.Url = url; bll_systemMenu.Update(systemMenu); } } } WebUtility.ShowAlertMessage("全部保存成功!", Request.RawUrl); } Response.Redirect(Request.Url.AbsolutePath); }
/// <summary> /// 递归生成树的方法 /// </summary> public StringBuilder CreateTree(int fatherId) { StringBuilder strHtml = new StringBuilder(); List <SystemMenuModel> systemMenuList = bll_systemMenu.GetListByFatherId(fatherId); for (int i = 0; i < systemMenuList.Count; i++) { SystemMenuModel systemMenu = systemMenuList[i]; string nodeStyle = String.Empty; if (systemMenu.ILevel < SystemMenu.MAX_LEVEL && systemMenu.HasChild) { nodeStyle = systemMenu.IsOpen.ToString(); } strHtml.Append("<tr lv=\"").Append(systemMenu.ILevel).Append("\" onoff=\"").Append(nodeStyle).Append("\">"); strHtml.Append("<td align=\"center\"><input type=\"checkbox\" name=\"g1\" value=\"").Append(systemMenu.Pkid).Append("\" /></td>"); strHtml.Append("<td><input name=\"title").Append(systemMenu.Pkid).Append("\" value=\"").Append(systemMenu.Title).Append("\" maxlength=\"10\" type=\"text\" class=\"text\" /></td>"); strHtml.Append("<td><input name=\"url").Append(systemMenu.Pkid).Append("\" value=\"").Append(systemMenu.Url).Append("\" maxlength=\"100\" type=\"text\" class=\"text\" /></td>"); strHtml.Append("<td>").Append(systemMenu.Pkid).Append("</td>"); strHtml.Append("<td class=\"gray\">").Append(bll_systemMenu.GetStatus(systemMenu, "enab")).Append("</td>"); strHtml.Append("<td>"); if (i > 0) { strHtml.Append("<a href=\"javascript:;\" onclick=\"operate('moveup',").Append(systemMenu.Pkid).Append(",null);\" class=\"icon icon_moveup\" title=\"上移\"></a>"); } else { strHtml.Append("<a class=\"icon icon_empty\"></a>"); } if (i < systemMenuList.Count - 1) { strHtml.Append("<a href=\"javascript:;\" onclick=\"operate('movedown',").Append(systemMenu.Pkid).Append(",null);\" class=\"icon icon_movedown\" title=\"下移\"></a>"); } else { strHtml.Append("<a class=\"icon icon_empty\"></a>"); } strHtml.Append("<a href=\"sysMenuEdit.aspx?pkid=").Append(systemMenu.Pkid).Append("\" class=\"icon icon_edit\" title=\"编辑\"></a>"); strHtml.Append("<div class=\"operation\">"); strHtml.Append("<a href=\"javascript:;\" onclick=\"operate('del',").Append(systemMenu.Pkid).Append(",null);\" class=\"icon icon_del\" title=\"删除\"></a>"); strHtml.Append("<div>"); strHtml.Append("</td>"); strHtml.Append("</tr>"); if (systemMenu.ILevel < SystemMenu.MAX_LEVEL) { if (systemMenu.HasChild && systemMenu.IsOpen) { strHtml.Append(CreateTree(systemMenu.Pkid)); } strHtml.Append("<tr lv=\"").Append(systemMenu.ILevel + 1).Append("\" rank=\"last\">"); strHtml.Append("<td></td>"); strHtml.Append("<td colspan=\"5\"><a href=\"javascript:;\" onclick=\"addMenu($(this), ").Append(systemMenu.Pkid).Append(");\" class=\"icon2 icon_add\"> [").Append(systemMenu.Title).Append("] 子菜单</a></td>"); strHtml.Append("</tr>"); } } return(strHtml); }