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 Spaces;

public partial class Admin_BlogSettings : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            BindPage();
        }
    }

    private void BindPage()
    {
        UserConfig uc = Cacher.GetUserConfig(Account);
        dropPostCount.Items.Clear();
        for (int i = 0; i < 50; i++)
        {
            ListItem li = new ListItem(i+"条",i.ToString());
            if (li.Value == uc.ShowPostCount.ToString())
                li.Selected = true;
            dropPostCount.Items.Add(li);
        }
        dropCommentCount.Items.Clear();
        for (int i = 0; i < 50; i++)
        {
            ListItem li = new ListItem(i + "条", i.ToString());
            if (li.Value == uc.ShowCommentCount.ToString())
                li.Selected = true;
            dropCommentCount.Items.Add(li);
        }
        chkDisabledComment.Checked = uc.DisabledComment;
        foreach (ListItem li in dropPostShowMode.Items)
        {
            li.Selected = false;
            if (li.Value == string.Format("{0}", (int)uc.PostShowMode))
            {
                li.Selected = true;
            }
        }
    }
    protected void btnSet_Click(object sender, EventArgs e)
    {
        //UserConfig uc = Cacher.GetUserConfig(Account);
        string sql = "UPDATE Blog_Config SET ShowPostCount=" + Utils.SqlInput(dropPostCount.SelectedValue) + ", ShowCommentCount=" + Utils.SqlInput(dropCommentCount.SelectedValue) + ", DisabledComment=" + (chkDisabledComment.Checked ? 1 : 0) + ",PostShowMode="+Utils.SqlInput(dropPostShowMode.SelectedValue)+"  WHERE Account='" + Account + "'";
        SpacesDataProvider.Instance().ExecuteNonQuery(sql);
        Cacher.ClearUserConfigCache(Account);
      //  this.BindPage();

        Message.Text = Msg.GetMsg("您已成功更改了博客设置！");
    }
    string Account
    {
        get { return SpacesContext.Current.Context.User.Identity.Name; }
    }
}
