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.FrameWork;
using EKETEAM.Data;

namespace eFrameWork.Applicationhui
{
    public partial class Default : System.Web.UI.Page
    {
        public eUser user;
        public ApplicationMenu appmenu;
        public string appNames = "";
        public string toptab = "";
        public string topframe = "";
        public string Skin
        {
            get 
            {
                if (Session["huiskin"] == null)
                {
                    string tmp = eOleDB.getValue("select parValue from a_eke_sysUserCustoms Where ApplicationID is null and ModelID is null and UserID='" + user.ID + "' and parName='huiskin'");
                    if (tmp.Length == 0) tmp = "default";
                    Session["huiskin"] = tmp;
                    return tmp;
                }
                else
                {
                    return Session["huiskin"].ToString();
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            user = new eUser("ApplicationHUI");
            user.Check();
            #region 设置皮肤
            string act = eParameters.QueryString("act");
            if (act == "sethuiskin")
            {
                string sql = "if exists (select * from a_eke_sysUserCustoms Where ApplicationID is null and ModelID is null and UserID='" + user.ID + "' and parName='huiskin')";
                sql += "update a_eke_sysUserCustoms set parValue='" + eParameters.QueryString("value") + "' where ApplicationID is null and ModelID is null and UserID='" + user.ID + "' and parName='huiskin'";
                sql += " else ";
                sql += "insert into a_eke_sysUserCustoms (ApplicationItemID,ModelID,UserID,parName,MC,parValue) ";
                sql += " values (NULL,NULL,'" + user.ID + "','huiskin','HUI样式','" + eParameters.QueryString("value") + "')";
                eOleDB.Execute(sql);
                Session["huiskin"] = eParameters.QueryString("value");
                Response.End();
            }
            #endregion
            appmenu = new ApplicationMenu(user);
            if (appmenu.ApplicationItemID.Length > 0)
            {
                string topappitemid = appmenu.getTopAppItemID(appmenu.ApplicationID,"");
                //DataRow[] rows = appmenu.AppItems.Select("ApplicationItemID='" + appmenu.ApplicationItemID + "'", "px,addTime");        
                DataRow[] rows = appmenu.AppItems.Select("ApplicationItemID='" + topappitemid + "'", "px,addTime");     
                if (rows.Length > 0)
                {
                    var url = appmenu.gethref(rows[0]);
                    //toptab = "<li class=\"active\"><span title=\"" + rows[0]["mc"].ToString() + "\" data-href=\"" + url + "\">" + rows[0]["mc"].ToString() + "</span><i></i><em></em></li>\r\n";
                    toptab = "<li class=\"active\"><span title=\"" + rows[0]["mc"].ToString() + "\" data-href=\"" + url + "\">" + rows[0]["mc"].ToString() + "</span><em></em></li>\r\n";

                    topframe += "<div class=\"show_iframe\">\r\n";
                    topframe += "<div style=\"display:none\" class=\"loading\"></div>\r\n";
                    topframe += "<iframe scrolling=\"yes\" frameborder=\"0\" src=\"" + url + "\"></iframe>\r\n";
                    topframe += "</div>\r\n";
                }
            }
            appmenu.UserApps.DefaultView.Sort = "appSort";
            DataTable tb = appmenu.UserApps.DefaultView.ToTable(true, "ApplicationID", "MC", "Pic");
            if (tb.Rows.Count == 0)
            {
                Response.Write("没有权限!");
                Response.End();
            }
            StringBuilder sb = new StringBuilder();
            foreach (DataRow dr in tb.Rows)
            {
                sb.Append("<li class=\"navbar-levelone" + (appmenu.ApplicationID == dr["ApplicationID"].ToString() ? " current" : "") + "\"><a href=\"" + (appmenu.ApplicationID == dr["ApplicationID"].ToString() ? "javascript:;" : "Default.aspx?AppID=" + dr["ApplicationID"].ToString()) + "\">" + dr["mc"].ToString() + "</a></li>\r\n");
            }
            appNames = sb.ToString();

            //eBase.PrintDataTable(tb);
            //eBase.End();

        }
    }
}