using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using Spaces;
public partial class Admin_dllayoutsettings : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        UserLayout ul = new UserLayout();
        UserConfig uc = Cacher.GetUserConfig(Account);
        Theme theme = Globals.GetThemes().FindTheme(uc.Theme);
        string layout = Request.Form["homePageLayout"];
        XmlDocument doc = new XmlDocument();
       // Response.Write(layout);
      //  Response.Write("<br><br>" + Request.Form);
        //Response.End();
        doc.LoadXml(layout);
        //检查是否为null，兼容msn的皮肤
        if (uc.Theme == "msn")
        {
            /* if (uc.Layout.Style == null||uc.Layout.Style==string.Empty)
                 ul.Style = "Fusion";
             else
                 ul.Style = uc.Layout.Style;
             * */


            if (uc.Layout == null || uc.Layout.Theme == null )
                ul.Theme = "Fusion";
            else
                ul.Theme = uc.Layout.Theme;
            if (uc.Layout == null || uc.Layout.Layout == null || uc.Layout.Layout == string.Empty)
                ul.Layout = "backwardstwocol";
            else
                ul.Layout = uc.Layout.Layout;
        }

        // Response.Write("UC" + uc.Theme);
        // Response.Write("UL"+ul.Theme);
        // Response.End();
        XmlNode ts = doc.SelectSingleNode("L");
     // Response.Write(string.Format("t={0}",ts.Attributes["T"].Value));
        ul.Layout = ts.Attributes["T"].Value;//设置空间的布局
     // Response.End();
        ul.Rows.Clear();
        foreach (XmlNode n in ts["Rs"])
        {
            //Response.Write("行"+n.Attributes["T"].Value+"<br>");
            ThemeRow tr = new ThemeRow();

            // tr.EnableDynamic=Globals.GetThemes().FindTheme(tr.)

            foreach (XmlNode c in n["Ps"])
            {
                ThemeCell tc = new ThemeCell();
                tc.ModuleName = c.Attributes["T"].Value;
                tc.Parameter = string.Empty;
                 Response.Write("列" + c.Attributes["T"].Value + "<br>");
                tr.Add(tc);
            }
            ul.Rows.Add(tr);
        }
        uc.Layout = ul;
        Users.UpdateUserConfig(uc);
       // Response.Write("行数" + uc.Layout.Layout);
        //发送提示信息
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script type='text/javascript' language='javascript'>");
        sb.AppendFormat("parent._win_confirm_msg_show('您已成功更改了页面布局，是否现在查看？','window.open(\"{0}\")','','120','80')", Globals.GetSiteUrls().Default(uc.Account));
        sb.Append("</script>");
        Message.Text = sb.ToString();

    }
    string Account
    {
        get { return SpacesContext.Current.Context.User.Identity.Name; }
    }
}
