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

namespace eFrameWork.AppMobile
{
    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("AppMobile");
            user.Check();
            appmenu = new ApplicationMenu(user);        


            StringBuilder sb = new StringBuilder();
            DataRow[] rows,rs;
            #region 已分组
            rows = appmenu.AppItems.Select("ModelID is Null and Show=1", "PX,addTime");
            for (int i = 0; i < rows.Length; i++)
            {
                if (!appmenu.allMenuIDS.Contains(rows[i]["ApplicationItemID"].ToString())) continue;
                sb.Append("<dl class=\"eFunGroup\">\r\n");
                sb.Append("<dt>" + rows[i]["MC"].ToString() + "</dt>\r\n");
                sb.Append("<dd>\r\n");
                rs = appmenu.AppItems.Select("ParentID='" + rows[i]["ApplicationItemID"].ToString() + "' and ModelID is not Null and Show=1", "PX,addTime");
                for (int j = 0; j < rs.Length; j++)
                {
                    if (!appmenu.allMenuIDS.Contains(rs[j]["ApplicationItemID"].ToString())) continue;

                    sb.Append("<a href=\"" + appmenu.gethref(rs[j]) + "\"><img" + (rs[j]["Finsh"].ToString() == "False" ? " class=\"gray\"" : "") + " src=\"../" + rs[j]["icon"].ToString() + "\"  /><p" + (rs[j]["Finsh"].ToString() == "False" ? " style=\"color:#ccc;\"" : "") + ">" + rs[j]["MC"].ToString() + "</p></a>\r\n");
                }
                sb.Append("</dd>\r\n");
                sb.Append("</dl>\r\n");
                sb.Append("<div class=\"clear\"></div>\r\n");
            }
            #endregion
            #region 未分组
            rs = appmenu.AppItems.Select("ModelID is not Null and ParentID is null and Show=1", "PX,addTime");
            if (rs.Length > 0)
            {
                sb.Append("<dl class=\"eFunGroup\">\r\n");
                sb.Append("<dt>未分组</dt>\r\n");
                sb.Append("<dd>\r\n");
                for (int j = 0; j < rs.Length; j++)
                {
                    if (!appmenu.allMenuIDS.Contains(rs[j]["ApplicationItemID"].ToString())) continue;
                    sb.Append("<a href=\"" + appmenu.gethref(rs[j]) + "\"><img" + (rs[j]["Finsh"].ToString() == "False" ? " class=\"gray\"" : "") + " src=\"../" + rs[j]["icon"].ToString() + "\"  /><p" + (rs[j]["Finsh"].ToString() == "False" ? " style=\"color:#ccc;\"" : "") + ">" + rs[j]["MC"].ToString() + "</p></a>\r\n");
                }
                sb.Append("</dd>\r\n");
                sb.Append("</dl>\r\n");
                sb.Append("<div class=\"clear\"></div>\r\n");
            }
            #endregion
            LitMenu.Text = sb.ToString();
        }
    }
}