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.Text;
using Spaces;
public partial class TweakUISet : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.Identity.Name == string.Empty)
        {
            Response.Write("请登陆后再更改页面设置！");
            Response.End();
        }
        StringBuilder sb = new StringBuilder();
        string InnerBodyBGColor = Request.Form["InnerBodyBGColor"];
        string OuterBodyBGColor = Request.Form["OuterBodyBGColor"];
        if (InnerBodyBGColor.Trim()!=string.Empty)
        sb.Append(".mainbody{background-color:#" + InnerBodyBGColor + "}\n");

        string BGImagePosition = Request.Form["BGImagePosition"];
        if (BGImagePosition.Trim() != string.Empty && BGImagePosition!="0")
        {
            sb.Append(".mainbody{background-position:"+GetPosition(int.Parse(BGImagePosition))+"}\n");
        }
        string BGImageRepeat = Request.Form["BGImageRepeat"];
        if (BGImageRepeat != string.Empty && BGImageRepeat!="0")
        {
            sb.Append (".mainbody{background-repeat:" + GetRepeat(int.Parse(BGImageRepeat)) + "}\n");
        }
        string BGImageDisplay = Request.Form["BGImageDisplay"];
        if (BGImageDisplay != string.Empty && BGImageDisplay!="0")
        {
            sb.Append(".mainbody{display:" + (BGImageDisplay == "0" ? "default" : "hide") + "}\n");
        }


        string PartsBorderWidth = Request.Form["PartsBorderWidth"];
        if (PartsBorderWidth.Trim() != "")
        {
            sb.Append(".OpaquePartMain, .PicTab, .BottomPanel, .partsmb{border-width:" + PartsBorderWidth + "px;}\n");
        }
        string PartsBorderStyle = Request.Form["PartsBorderStyle"];
        if (PartsBorderStyle.Trim() != string.Empty && PartsBorderStyle!="0")
        {
            sb.Append(".OpaquePartMain, .PicTab, .BottomPanel, .partsmb{border-style:" + GetBorderStyle(int.Parse(PartsBorderStyle)) + ";}\n");
        }

        string PartsBorderColor = Request.Form["PartsBorderColor"];
        if (PartsBorderColor.Trim() != string.Empty)
        {
            sb.Append(".OpaquePartMain, .PicTab, .BottomPanel, .partsmb{border-color:#" + PartsBorderColor + ";}\n");
        }

        string PartBGColor = Request.Form["PartBGColor"];
        if (PartBGColor.Trim() != string.Empty)
        {
            sb.Append(".OpaquePartMain, .PicTab, .BottomPanel, .partsmb{background-color:#" + PartBGColor + ";}\n");
        }

        string BGImageTrans = Request.Form["BGImageTrans"];
        if (BGImageTrans.Trim() != string.Empty)
        {
            sb.Append(".OpaquePartMain, .PicTab, .BottomPanel, .partsmb{FILTER: progid:DXImageTransform.Microsoft.Alpha(opacity=" + BGImageTrans + ");}\n");
        }
        UserConfig uc = Cacher.GetUserConfig(User.Identity.Name);
        uc.Layout.Style = sb.ToString();
        Users.UpdateUserConfig(uc);
        Response.Redirect(Globals.GetSiteUrls().Default(uc.Account));
    }
    string GetBorderStyle(int index)
    {
        string s = string.Empty;
        switch (index)
        { 
            
            case 1:
                s = "none";
                break;
            case 2:
                s = "dotted";
                break;
            case 3:
                s = "dashed";
                break;
 
            case 4:
                s = "solid";
                break;
            case 5:
                s = "double";
                break;
            case 6:
                s = "groove";
                break;
            case 7:
                s = "ridge";
                break;
            case 8:
                s = "inset";
                break;
            case 9:
                s = "window-inset";
                break;
            case 10:
                s = "outset";
                break;
        
        }
        return s;
    }
    string GetRepeat(int index)
    {

        string rep = string.Empty;
        switch (index)
        { 
            case 0:
                rep = "default";
                break;
            case 1:
                rep = "repeat";
                break;
            case 2:
                rep = "no-repeat";
                break;
            case 3:
                rep = "repeat-y";
                break; 
                case 4:
                    rep = "repeat-x";
                break;
        }
        return rep;
    }
    string GetPosition(int index)
    {
        string pos = string.Empty;
        switch (index)
        { 
            case 0:
                pos = "default";
                break;
            case 1:
                pos = "top left";
                break;
            case 2:
                pos = "top center";
                break;
            case 3:
                pos = "top right";
                break;
            case 4:
                pos = "center left";
                break;
            case 5:
                pos = "center center";
                break;
            case 6:
                pos = "center right";
                break;
            case 7:
                pos = "bottom left";
                break;
            case 8:
                pos = "bottom center";
                break;
            case 9:
                pos = "bottom right";
                break;
        }
        return pos;
    }
}
