using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KstCmsBase.Collection;
using KstCmsBase.Entities;
using KstCmsBase.DAL;

namespace KstCMS.KstCMS_Manager.Ipanel
{
    public partial class Menu_Outlook : KstCmsBase.WebPage.BasePage
    {
        protected string MenuId = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            MenuId = Request.QueryString.Get("MenuId");
            if (string.IsNullOrEmpty(MenuId)) MenuId = "03";
            ShowMenu(MenuId);
        }

        private void ShowMenu(string ID)
        {
            string html = null;
            string htmltd = null;
            string html1 = "<table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\r\n<tbody>\r\n<tr>\r\n";


            SysMenuCollection MasterItems = SysMenu.Get_ModelMenu(ID, User.Identity.Name);
            int row = 0;
            string OpenFirstMenu = string.Empty;
            foreach (SysMenuEntity item in MasterItems)
            {
                SysMenuCollection SubItems = SysMenu.Get_SubMenu(item.MENU_ID, User.Identity.Name);
                if (SubItems.Count == 0)
                {
                    html1 += "<td>\r\n";
                    html = "<td class=\"left_menu_title1\" OnClick=\"OpenUrl('" + item.MENU_CODE + "');\"><img src=\"" + SysRootUrl + "/KstCMS_Manager/images/menu/" + item.MENU_IMAGE + ".gif\" align=\"absmiddle\" /> " + item.MENU_NAME + "</td>\r\n";
                    htmltd = "<td align=\"center\">\r\n";
                }
                else
                {
                    string menuid = item.MENU_ID;
                    if (row == 0)
                        OpenFirstMenu = "toggle('submenu" + menuid + "','" + menuid + "',false);";
                    html1 += "<td  onClick=\"toggle('submenu" + menuid + "','" + menuid + "',false);\" >\r\n";
                    html = "<td class=\"left_menu_title2\" id=\"" + menuid + "\"><img src=\"" + SysRootUrl + "/KstCMS_Manager/images/menu/" + item.MENU_IMAGE + ".gif\" align=\"absmiddle\" /> " + item.MENU_NAME + "</td>\r\n";

                    htmltd = "<td align=\"center\" id=\"submenu" + menuid + "\" style=\"display:none\">\r\n";

                }
                html1 += "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\r\n<tr>\r\n";
                html1 += html + "</tr>\r\n</table>\r\n</td>\r\n</tr><tr>" + htmltd;
                string subHtmltable = " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\r\n";

                foreach (SysMenuEntity SubItem in SubItems)
                {
                    subHtmltable += "<tr><td id=\"Dt" + SubItem.MENU_ID + "\" class=\"left_submenu\" OnClick=\"OpenUrl('" + SubItem.MENU_CODE + "');onSelect('Dt" + SubItem.MENU_ID + "');\" onmouseover=\"onMouseover(this.id);\" onmouseout=\"onMouseout(this.id);\">";
                    subHtmltable += "<img src=\"" + SysRootUrl + "/KstCMS_Manager/images/menu/" + SubItem.MENU_IMAGE + ".gif\" align=\"absmiddle\" /> " + SubItem.MENU_NAME + "</td>";
                    subHtmltable += "</tr>\r\n";
                }
                subHtmltable += "</table>";
                html1 += subHtmltable + "</td><tr>";
                row++;
            }

            html1 += "</tr></tbody></table>";

            LitMenu.Text = html1;

            if (!string.IsNullOrEmpty(OpenFirstMenu))
            {
                Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "", OpenFirstMenu, true);
            }

        }
    }
}