using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using EKETEAM.Data;
using EKETEAM.FrameWork;

namespace eFrameWork.Application
{
    public partial class Menu : System.Web.UI.UserControl
    {
        private eUser user;
        public string AppItem = eParameters.Request("AppItem");
        ApplicationMenu appmenu;
        protected void Page_Load(object sender, EventArgs e)
        {

            user = new eUser("Application");
            appmenu = new ApplicationMenu(user);        
            litMenu.Text = getMenus("");
            
        }
        private string getMenus(string ParentID)
        {
            StringBuilder sb = new StringBuilder();
            if (ParentID.Length == 0)
            {
                sb.Append("<ul class=\"emenu\">\r\n");
            }
            else
            {
                sb.Append("<ul" + (appmenu.curMenuIDS.IndexOf(ParentID) == -1 ? " style=\"display:none;\"" : "") + ">\r\n");
            }
            DataRow[] rows = appmenu.AppItems.Select(ParentID.Length == 0 ? "ParentID is Null and Show=1" : "ParentID='" + ParentID + "' and Show=1", "PX,addTime");
            for (int i = 0; i < rows.Length; i++)
            {
                if (!appmenu.allMenuIDS.Contains(rows[i]["ApplicationItemID"].ToString()) && rows[i]["Finsh"].ToString() == "True") continue;
                string curids = rows[i]["ApplicationItemID"].ToString();                
                if (rows[i]["PackID"].ToString().Length > 0) curids = rows[i]["PackID"].ToString();
                sb.Append("<li" + (appmenu.curMenuIDS.IndexOf(curids) > -1 ? " class=\"cur\"" : "") + ">");
                if (rows[i]["ModelID"].ToString().Length == 0)
                {
                    sb.Append("<a href=\"javascript:;\" onclick=\"showmenu(this);\"");
                    sb.Append(appmenu.curMenuIDS.IndexOf(rows[i]["ApplicationItemID"].ToString()) > -1 ? " class=\"open\"" : " class=\"close\"");
                }
                else
                {
                    sb.Append("<a href=\"" + appmenu.gethref(rows[i]) + "\"");
                }

                sb.Append(rows[i]["Finsh"].ToString() == "False" ? " style=\"color:#666;\"" : "");
                sb.Append(" onfocus=\"this.blur();\">");
                if (rows[i]["icon"].ToString().Length > 0) sb.Append("<img" + (rows[i]["Finsh"].ToString() == "False" ? " class=\"gray\"" : "") + " src=\"../" + rows[i]["icon"].ToString() + "\"align=\"absmiddle\" border=\"0\" >");
                sb.Append(rows[i]["mc"].ToString());
                sb.Append("</a>");
               
                if (rows[i]["ModelID"].ToString().Length == 0)
                {
                    sb.Append(getMenus(rows[i]["ApplicationItemID"].ToString()));
                }
                sb.Append("</li>\r\n");
            }
            sb.Append("</ul>\r\n");
            return sb.ToString();
        }
    }
}