private string _PurBuidTree(Song.Entities.ManageMenu m) { //开始生成 string temp = ""; try { //当前节点对象 Extend.MenuNode n = new Song.Extend.MenuNode(m, _allMM); temp += "<div type=\"nodeline\" class=\"nodeline\">"; //节点前的图标区域//树的连线与图标 temp += "<div style='width:auto;float:left;' state='' "; temp += "type='nodeIco' "; temp += "IsChilds='" + (n.IsChilds ? "True" : "False") + "'>"; temp += this._PurNodeLine(m, 0) + this._PurNodeIco(m); temp += "</div>"; //菜单项文本 temp += this._PurBuildNode(m); temp += "</div>"; if (n.IsChilds) { temp += "<div style=\"float: none;\" type=\"nodePanel\" panelId=\"" + m.MM_Id + "\">"; for (int i = 0; i < n.Childs.Length; i++) { temp += this._PurBuidTree(n.Childs[i]); } temp += "</div>"; } } catch (Exception ex) { Message.ExceptionShow(ex); } return(temp); }
/// <summary> /// 生成菜单项前的链接线 /// </summary> /// <param name="m">当前节点</param> /// <param name="topid">当前节点上溯到最顶节点的id</param> /// <returns></returns> private string _PurNodeLine(Song.Entities.ManageMenu m, int topid) { string temp = ""; Extend.MenuNode mn = new Song.Extend.MenuNode(m, _allMM); //当前菜单项的上级菜单项 Extend.MenuNode p = new Song.Extend.MenuNode(mn.Parent, _allMM); while (p.Item.MM_Id != topid) { //如果是当前子树的最后一个 if (p.Item.MM_PatId == "0") { temp = empty + temp; break; } //如果是最后一个节点 if (p.IsLast) { temp = empty + temp; } else { temp = line + temp; } //temp = empty + temp; p = new Song.Extend.MenuNode(p.Parent, _allMM); } return(temp); }
private string _PurNodeIco(Song.Entities.ManageMenu m) { string temp = ""; Extend.MenuNode n = new Song.Extend.MenuNode(m, _allMM); //如果是根节点 if (n.Parent == null) { return("<img src=\"/Manage/Images/tree/root.gif\"/>"); } //如果有子节点,且是最后一个,等判断 if (n.IsChilds && n.IsLast) { temp += "<img src=\"/Manage/Images/tree/minusBottom.gif\"/>"; } if (n.IsChilds && !n.IsLast) { temp += "<img src=\"/Manage/Images/tree/minus.gif\"/>"; } if (!n.IsChilds && n.IsLast) { temp += "<img src=\"/Manage/Images/tree/joinBottom.gif\"/>"; } if (!n.IsChilds && !n.IsLast) { temp += "<img src=\"/Manage/Images/tree/join.gif\"/>"; } return(temp.ToLower()); }
/// <summary> /// 设置初始界面 /// </summary> private void fill() { try { Song.Entities.ManageMenu mm; if (id != 0) { mm = Business.Do <IManageMenu>().GetSingle(id); //是否显示 cbIsShow.Checked = mm.MM_IsShow; cbIsUse.Checked = mm.MM_IsUse; //是否粗体 cbIsBold.Checked = mm.MM_IsBold; //是否斜体 cbIsItalic.Checked = mm.MM_IsItalic; } else { //如果是新增 mm = new Song.Entities.ManageMenu(); } //名称 tbName.Text = mm.MM_Name; //标识 tbMarker.Text = mm.MM_Marker; //说明 tbIntro.Text = mm.MM_Intro; } catch (Exception ex) { Message.ExceptionShow(ex); } }
//生成下拉菜单,子菜单面板 private string _BuildMenuItem(Song.Entities.ManageMenu mm, int level, string path) { Extend.MenuNode node = new Song.Extend.MenuNode(mm, _allMM); //如果没有子节点,则直接返回 if (!node.IsChilds) { return(""); } // string tmp = ""; //是否根菜单 string itemClass = level == 0 ? "rootItem" : "item"; string panelClass = level == 0 ? "rootPanel" : ""; //一级菜单,即要前台显示的菜单 for (int i = 0; i < node.Childs.Length; i++) { Song.Entities.ManageMenu m = node.Childs[i]; Extend.MenuNode n = new Song.Extend.MenuNode(m, _allMM); tmp += " <div class=\"" + itemClass + " " + (n.IsChilds ? "child" : "") + "\" mid=\"" + m.MM_Id + "\" tax=\"" + i + "\">"; tmp += "<a href=\"" + m.MM_Link + "\" type=\"" + m.MM_Type + "\">" + m.MM_Name + "</a></div>"; if (n.IsChilds) { tmp += "<div class=\"MenuPanel " + panelClass + "\" style=\"display:none;z-index:" + (level + 100) + "\" pid=\"" + m.MM_Id + "\">"; tmp += this._BuildMenuItem(m, level + 1, path + "," + m.MM_Name); tmp += "</div>"; } } return(tmp); }
protected void Page_Load(object sender, EventArgs e) { if (!this.IsPostBack) { Song.Entities.ManageMenu m = Business.Do <IManageMenu>().GetSingle(id); lbName.Text = m.MM_Name; } }
//生成节点项文本 //node:当前节点 //data:完整数据源 //clas:当前节点的style private string _SysBuildNode(Song.Entities.ManageMenu m, string clas, string path) { Extend.MenuNode node = new Song.Extend.MenuNode(m, _allMM); string temp = "<div nodeId=\"" + m.MM_Id + "\""; temp += " nodetype=\"" + m.MM_Type + "\" "; temp += " title='" + (m.MM_Intro == "" ? m.MM_Name : m.MM_Intro) + "'"; temp += " isChild=\"" + node.IsChilds + "\" type=\"" + clas + "\" >"; //菜单节点的自定义样式 string style = " "; if (m.MM_Color != String.Empty && m.MM_Color != null) { style += "color: " + m.MM_Color + ";"; } if (m.MM_IsBold) { style += "font-weight: bold;"; } if (m.MM_IsItalic) { style += "font-style: italic;"; } if (m.MM_Font != String.Empty && m.MM_Font != null) { style += "font-family: '" + m.MM_Font + "';"; } string name = "<span style=\"" + style + "\">" + m.MM_Name + "</span>"; if (m.MM_Link != "") { string link = ""; link += "<{0} href=\""; link += m.MM_Link + "\" isChild=\"" + node.IsChilds + "\" IsUse=\"" + m.MM_IsUse + "\" width=\"" + m.MM_WinWidth + "\" height=\"" + m.MM_WinHeight + "\" path=\"" + path + "\" target=\"_blank\" class=\"a\">"; link += name + "</{0}>"; switch (m.MM_Type.ToLower()) { case "link": link = string.Format(link, "a"); break; default: link = link.Replace("{0}", "span"); break; } temp += link; } else { temp += name; } temp += "</div>"; return(temp); }
//生成节点项文本 //node:当前节点 //data:完整数据源 //clas:当前节点的style private string _SysBuildNode(Song.Entities.ManageMenu m, string clas, string path) { Extend.MenuNode node = new Song.Extend.MenuNode(m, _allMM); string temp = ""; try { temp = "<div nodeId=\"" + m.MM_Id + "\""; temp += " nodetype=\"" + m.MM_Type + "\" "; temp += " title='" + (m.MM_Intro == "" ? m.MM_Name : m.MM_Intro) + "'"; temp += " isChild=\"" + node.IsChilds + "\" type=\"" + clas + "\" >"; //菜单节点的自定义样式 string style = "font-size: 13px; "; if (m.MM_Color != String.Empty && m.MM_Color != null) { style += "color: " + m.MM_Color + ";"; } if (m.MM_IsBold) { style += "font-weight: bold;"; } if (m.MM_IsItalic) { style += "font-style: italic;"; } if (m.MM_Font != String.Empty && m.MM_Font != null) { style += "font-family: '" + m.MM_Font + "';"; } string name = "<span style=\"" + style + "\">" + m.MM_Name + "</span>"; if (m.MM_Link != "") { //如果是javascript事件 if (m.MM_Type.ToLower() == "event") { temp += "<a href=\"javascript:" + m.MM_Link + "\" isChild=\"" + node.IsChilds + "\" IsUse=\"" + m.MM_IsUse + "\" path=\"" + path + "\" target=\"_blank\">" + name + "</a>"; } else { temp += "<a href=\"" + m.MM_Link + "\" isChild=\"" + node.IsChilds + "\" IsUse=\"" + m.MM_IsUse + "\" path=\"" + path + "\" target=\"_blank\">" + name + "</a>"; } } else { temp += name; } temp += "</div>"; } catch (Exception ex) { Message.ExceptionShow(ex); } return(temp); }
/// <summary> /// 生成权限菜单的节点文件项 /// </summary> /// <param name="m"></param> /// <returns></returns> private string _PurBuildNode(Song.Entities.ManageMenu m) { string temp = ""; try { Extend.MenuNode node = new Song.Extend.MenuNode(m, _allMM); temp += "<div style='width:auto;float:left;' state=\"nosel\" type=\"select\" nodeId=\"" + m.MM_Id + "\" "; temp += "IsChilds='" + (node.IsChilds ? "True" : "False") + "'>"; temp += "<img src=\"/Manage/Images/tree/noSel.gif\"/>"; temp += "</div>"; temp += "<div style=\"width:auto;line-height: 18px;display: table;font-size: 12px;cursor: default;\""; string title = m.MM_Intro.Trim() == "" ? m.MM_Name : m.MM_Intro; temp += "title='" + title + "'"; temp += " nodeId='" + m.MM_Id + "' text=\"" + m.MM_Name + "\""; temp += " tax='" + m.MM_Tax + "' patId=\"" + m.MM_PatId + "\" "; temp += " type='text'>"; //菜单节点的自定义样式 string style = "font-size: 13px; "; if (m.MM_Color != String.Empty && m.MM_Color != null) { style += "color: " + m.MM_Color + ";"; } if (m.MM_IsBold) { style += "font-weight: bold;"; } if (m.MM_IsItalic) { style += "font-style: italic;"; } if (m.MM_Font != String.Empty && m.MM_Font != null) { style += "font-family: '" + m.MM_Font + "';"; } string name = "<span style=\"" + style + "\">" + m.MM_Name + "</span>"; temp += name; //如果当前节点显示状态为false if (!m.MM_IsShow) { temp += " <span style=\"color:red\" title=\"该节点项在使用中将不显示\">[隐]</span>"; } if (!m.MM_IsUse) { temp += " <span style=\"color:red\" title=\"菜单项被禁用; 具体作用: 在使用中将不响应鼠标事件\">[禁]</span>"; } temp += "</div>"; } catch (Exception ex) { Message.ExceptionShow(ex); } return(temp); }
/// <summary> /// 生成节点文件项 /// </summary> /// <param name="m"></param> /// <returns></returns> private string _BuildNode(Song.Entities.ManageMenu m) { string temp = ""; try { //temp = "<div style=\"width:auto;line-height: 18px;display: table; cursor: default;\""; //temp += " title='" + (m.MM_Intro == "" ? m.MM_Name : m.MM_Intro) + "'"; //temp += " nodeId='" + m.MM_Id + "' text=\"" + m.MM_Name + "\""; ////temp+=" path=\""+node.Path+"\""; //temp += " tax='" + m.MM_Tax + "' patId=\"" + m.MM_PatId + "\" >"; //菜单节点的自定义样式 string style = "font-size: 13px; "; if (m.MM_Color != String.Empty && m.MM_Color != null) { style += "color: " + m.MM_Color + ";"; } if (m.MM_IsBold) { style += "font-weight: bold;"; } if (m.MM_IsItalic) { style += "font-style: italic;"; } if (m.MM_Font != String.Empty && m.MM_Font != null) { style += "font-family: '" + m.MM_Font + "';"; } // string name = "<span style=\"" + style + "\">" + m.MM_Name + "</span>"; if (m.MM_Link != "") { temp += "<a href=\"" + m.MM_Link + "\" target=\"_blank\">" + name + "</a>"; } else { temp += name; } } catch (Exception ex) { Message.ExceptionShow(ex); } //temp += "</div>"; return(temp); }
/// <summary> /// 修改是否显示的状态 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void sbShow_Click(object sender, EventArgs e) { try { StateButton ub = (StateButton)sender; int index = ((GridViewRow)(ub.Parent.Parent)).RowIndex; int id = int.Parse(this.GridView1.DataKeys[index].Value.ToString()); // Song.Entities.ManageMenu entity = Business.Do <IManageMenu>().GetSingle(id); entity.MM_IsShow = !entity.MM_IsShow; Business.Do <IManageMenu>().Save(entity); BindData(null, null); } catch (Exception ex) { Message.ExceptionShow(ex); } }
//生成下拉菜单,子菜单面板 private string _BuildMenuItem(Song.Entities.ManageMenu m, int level, string path) { Extend.MenuNode node = new Song.Extend.MenuNode(m, _allMM); //如果没有子节点,则直接返回 if (!node.IsChilds) { return(""); } // string tmp = ""; try { if (level == 0) { tmp = "<div style=\"z-index: " + (_sysZIndex++) + ";\""; } else { tmp = "<div style=\"position: absolute; z-index: " + (_sysZIndex++) + ";\""; } tmp += " patId='" + node.Item.MM_Id + "' "; tmp += " class='menuPanel' type='menuPanel' level=\"" + (level++) + "\">"; for (int i = 0; i < node.Childs.Length; i++) { //生成菜单点 Song.Entities.ManageMenu n = node.Childs[i]; tmp += this._SysBuildNode(n, "MenuNode", path + "," + n.MM_Name); //tmp+="<div>"+n.Name+"</div>"; } tmp += "</div>"; //递归生成子菜单 for (int i = 0; i < node.Childs.Length; i++) { Song.Entities.ManageMenu n = node.Childs[i]; tmp += this._BuildMenuItem(n, level, path + "," + n.MM_Name); } } catch (Exception ex) { Message.ExceptionShow(ex); } return(tmp); }
/// <summary> /// 修改排序 /// </summary> /// <param name="xml"></param> public void SaveOrder(string xml) { XmlDocument resXml = new XmlDocument(); resXml.XmlResolver = null; using (DbTrans tran = Gateway.Default.BeginTrans()) try { resXml.LoadXml(xml, false); XmlNodeList nodeList = resXml.SelectSingleNode("nodes").ChildNodes; //取rootid XmlNode nodes = resXml.SelectSingleNode("nodes"); XmlElement xenodes = (XmlElement)nodes; //遍历所有子节点 foreach (XmlNode xn in nodeList) { XmlElement xe = (XmlElement)xn; int id = Convert.ToInt32(xe.Attributes["id"].Value); int pid = Convert.ToInt32(xe.Attributes["pid"].Value); int tax = Convert.ToInt32(xe.Attributes["tax"].Value); bool state = Convert.ToBoolean(xe.Attributes["state"].Value); Song.Entities.ManageMenu mm = this.GetSingle(id); if (mm != null) { mm.MM_PatId = pid; mm.MM_Tax = tax; mm.MM_State = state; tran.Save <ManageMenu>(mm); } } tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } }
//获取单个栏目信息 public string ManageMenuJson(int id) { Song.Entities.ManageMenu nc = Business.Do <IManageMenu>().GetSingle(id); return(nc == null ? "" : nc.ToJson()); }
/// <summary> /// 更改菜单项的信息 /// </summary> /// <param name="nodexml"></param> private void _updateTreeNode(string nodexml) { if (nodexml == "" || nodexml == null) { return; } XmlDocument resXml = new XmlDocument(); resXml.LoadXml(nodexml, false); XmlNode node = resXml.SelectSingleNode("node"); string type = ((XmlElement)node).Attributes["type"].Value; int id = Convert.ToInt32(((XmlElement)node).Attributes["id"].Value); int rootid = Convert.ToInt32(((XmlElement)node).Attributes["rootid"].Value); //当前对象 Song.Entities.ManageMenu mm = null; if (type == "edit" || type == "root") { mm = Business.Do <IManageMenu>().GetSingle(id); } if (type == "add") { mm = new Song.Entities.ManageMenu(); } //不管是新增还是修改(根节点、子节点),都需要用到的赋值 mm.MM_Name = getNodeText(node, "name", "").ToString(); mm.MM_WinWidth = Convert.ToInt32(getNodeText(node, "winwidth", 400)); mm.MM_WinHeight = Convert.ToInt32(getNodeText(node, "winheight", 300)); mm.MM_Func = getNodeText(node, "func", "").ToString(); mm.MM_IsBold = Convert.ToBoolean(getNodeText(node, "isbold", false)); mm.MM_IsItalic = Convert.ToBoolean(getNodeText(node, "isitalic", false)); mm.MM_IsShow = Convert.ToBoolean(getNodeText(node, "isshow", true)); mm.MM_IsUse = Convert.ToBoolean(getNodeText(node, "isuse", true)); mm.MM_Intro = getNodeText(node, "intro", "").ToString(); mm.MM_IcoX = (int)Convert.ToDouble(getNodeText(node, "icox", "0")); mm.MM_IcoY = (int)Convert.ToDouble(getNodeText(node, "icoy", "0")); //修改与新增才用到的赋值 if (type == "edit" || type == "add") { mm.MM_Type = getNodeText(node, "type", "").ToString(); mm.MM_Link = getNodeText(node, "link", "").ToString(); // mm.MM_Marker = getNodeText(node, "marker", "").ToString(); mm.MM_Marker = mm.MM_Marker.Replace("|", ","); mm.MM_Marker = mm.MM_Marker.Replace(" ", ","); string marker = ""; if (mm.MM_Marker != "" && mm.MM_Marker != null) { foreach (string t in mm.MM_Marker.Split(',')) { if (t.Trim() != "") { marker += t + ","; } } if (marker.Substring(marker.Length - 1) == ",") { marker = marker.Substring(0, marker.Length - 1); } } mm.MM_Marker = marker; mm.MM_Func = getNodeText(node, "func", "").ToString(); } //修改根节点 if (type == "root") { Business.Do <IManageMenu>().Save(mm); } if (type == "add") { mm.MM_Root = rootid; mm.MM_PatId = getNodeText(node, "patid", 0).ToString(); Business.Do <IManageMenu>().Add(mm); } if (type == "edit") { if (mm.MM_Func == "sys") { Business.Do <IManageMenu>().Save(mm); } else { //移动到 int mrootid = Convert.ToInt32(getNodeText(node, "moveto", 0)); //复制到 int crootid = Convert.ToInt32(getNodeText(node, "copyto", 0)); //如果既不移动与不复制 if (rootid == mrootid && rootid == crootid) { Business.Do <IManageMenu>().Save(mm); } //如果移动 if (rootid != 0 && rootid != mrootid) { Business.Do <IManageMenu>().Move(mm, mrootid); } //如果拷贝 if (crootid != 0 && rootid != crootid) { Business.Do <IManageMenu>().Copy(mm, crootid); } } } }