private void bulidMenu()
{
int id = 0;
int code;
if (!checkUser.checkAdmin())
{
DataTable tblInf = (DataTable)HttpContext.Current.Session["user_inf"]; DataRow row = tblInf.Rows[0];
code = Convert.ToInt32(row["Code"]);
}
else
{
code = 1;
}
XmlDocument xmlMenu = new XmlDocument();
string xmlMenuFile;
if (Session["admin"] != null && Session["admin"].ToString() == "OK")
{
xmlMenuFile = Server.MapPath("menuItem2.config");
}
else
xmlMenuFile = Server.MapPath("menuItem.config");
xmlMenu.Load(xmlMenuFile);
XmlNode root = xmlMenu.SelectSingleNode("/menu");
//循环一级产生主菜单
foreach (XmlNode rootNode in root.ChildNodes)
{
if (rootNode.NodeType != XmlNodeType.Element)
{
continue;
}
//try
//{
if (rootNode.Attributes["code"].Value.Length >= code && rootNode.Attributes["code"].Value.Substring(code - 1, 1) == "1")
{
menu += "<ul class=\"t\">\r\n";
id++;
string imgid = "img" + id;
string menuid = "menu" + id;
//menu += "<li><span class=\"out\" style=\"cursor:hand; vertical-align:top;\" onclick=\"titleClick('" + imgid + "','" + menuid + "')\" onmousemove=\"this.className='over'\" onmouseout=\"this.className='out'\"><img src=\"images/ico_s.gif\" id=\"" + imgid + "\" /> ";
//menu += "<li><span class=\"out\" style=\"cursor:hand; vertical-align:top;\" onclick=\"titleClick('" + imgid + "','" + menuid + "')\" ><img src=\"images/ico_s.gif\" id=\"" + imgid + "\" /> ";
menu += "<li><span class=\"out\" style=\"cursor:hand; vertical-align:top;\" onclick=\"titleClick('" + imgid + "','" + menuid + "')\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\"><img src=\"images/ico_s.gif\" id=\"" + imgid + "\" /><img src=\"images/disk.gif\" width=\"18\" height=\"14\" /> ";
menu += "<strong>" + rootNode.Attributes["text"].Value + "</strong>";
menu += "</span>\r\n";
menu += "<ul id=\"" + menuid + "\" style=\"display:none\">";
//循环二级产生一级菜单
foreach (XmlNode menuNode in rootNode.ChildNodes)
{
if (menuNode.NodeType != XmlNodeType.Element)
{
continue;
}
if (menuNode.Attributes["code"].Value.Length >= code && menuNode.Attributes["code"].Value.Substring(code - 1, 1) == "1")
{
id++;
string text = menuNode.Attributes["text"].Value;
if (!menuNode.HasChildNodes && menuNode.Attributes["url"].Value != "")
{
string url = "../" + menuNode.Attributes["url"].Value;
//menu += "<li><img src=\"images/count.gif\" /> <a href=\"" + url + "\" target=\"main_frame\" class=\"out\" onmousemove=\"this.className='over'\" onmouseout=\"this.className='out'\">" + menuNode.Attributes["text"].Value + "</a>";
if (text.Length >= 11)
{
string shortText = text.Substring(0, 9) + "...";
menu += "<li><img src=\"images/count.gif\" /> <a href=\"" + url + "\" target=\"main_frame\" title=\"" + text + "\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + shortText + "</a>";
}
else
menu += "<li><img src=\"images/count.gif\" /> <a href=\"" + url + "\" target=\"main_frame\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + text + "</a>";
}
else if (menuNode.HasChildNodes)
{
id++;
string img2id = "img2i" + id;
string menu2id = "menu2i" + id;
menu += "<li><span style=\"cursor:hand; vertical-align:middle;\" onclick=\"titleClick('" + img2id + "','" + menu2id + "')\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\"><img src=\"images/ico_s.gif\" id=\"" + img2id + "\" /><img src=\"images/dir_close.gif\" width=\"18\" height=\"14\" id=\"" + img2id + "_dir\" /> " + text + "</span>\r\n";
menu += "<ul id=\"" + menu2id + "\" style=\"display:none\">\r\n";
//循环三级产生二级菜单
foreach (XmlNode subMenuNode in menuNode.ChildNodes)
{
if (subMenuNode.NodeType != XmlNodeType.Element)
{
continue;
}
if (subMenuNode.Attributes["code"].Value.Length >= code && subMenuNode.Attributes["code"].Value.Substring(code - 1, 1) == "1" && subMenuNode.Attributes["url"].Value != "")
{
id++;
string text2 = subMenuNode.Attributes["text"].Value;
string url2 = "../" + subMenuNode.Attributes["url"].Value;
if (text2.Length >= 10)
{
string shortText2 = text2.Substring(0, 8) + "...";
menu += "<li><img src=\"images/count.gif\" width=\"11\" height=\"11\" /> <a href=\"" + url2 + "\" title=\"" + text2 + "\" target=\"main_frame\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + shortText2 + "</a>\r\n";
}
else
menu += "<li><img src=\"images/count.gif\" width=\"11\" height=\"11\" /> <a href=\"" + url2 + "\" target=\"main_frame\" class=\"out\" onmousemove=\"onover(this)\" onmouseout=\"onout(this)\">" + text2 + "</a>\r\n";
}
}
menu += "</ul>";
}
}
}
menu += "</ul></ul>";
}
//}
//catch { }
}
}