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 JuSNS.Model;
using JuSNS.UI.Control;

namespace JuSNS.Web.system.blog
{
    public partial class index :JuSNS.UI.Page.ManagePage
    {
        protected string sort = "blog";
        protected void Page_Load(object sender, EventArgs e)
        {
            //Operate();
            if (!Page.IsPostBack)
            {
                int con = 2;
                if (Request.QueryString["Condtion"] != null)
                    con = int.Parse(Request.QueryString["Condtion"]);
                int ord = 1;
                if (Request.QueryString["Order"] != null)
                    ord = int.Parse(Request.QueryString["Order"]);
                string keyw = string.Empty;
                if (Request.QueryString["Key"] != null)
                {
                    keyw = Common.Input.URLDecode(Request.QueryString["Key"]);
                }
                int pg = 1;
                if (Request.QueryString["Page"] != null)
                    pg = int.Parse(Request.QueryString["Page"]);
                LoadList(pg, con, ord, keyw);
            }
        }

        /// <summary>
        /// 加载分页
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        protected void LoadList(int pageIndex, int con, int ord, string key)
        {
            int r, p;
            string Url = "index.aspx";
            this.Condtion.SelectedValue = con.ToString();
            Url += "?Condtion=" + con;
            this.Order.SelectedValue = ord.ToString();
            Url += "&Order=" + ord;
            if (key != null && key.Trim() != string.Empty)
            {
                Url += "&Key=" + Common.Input.URLEncode(key);
                this.Key.Text = key;
            }
            JuSNS.Manage.Blog bl = new JuSNS.Manage.Blog();
            DataTable dt = bl.Search(con, key, ord, pageIndex, PAGESZ, out r, out p);
            this.RptData.DataSource = dt;
            this.RptData.DataBind();
            //判断是否调用分页
            if (r > PAGESZ)
            {
                DivPage.InnerHtml = PageNavigator.Pagination(pageIndex, p, Url);
            }
            else
            {
                this.DivPage.Visible = false;
            }
            DataBind();
        }

        /// <summary>
        /// 搜索
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            int con = 1;
            if (Request.Form["Condtion"] != null)
                con = int.Parse(Request.Form["Condtion"]);
            int ord = 1;
            if (Request.Form["Order"] != null)
                ord = int.Parse(Request.Form["Order"]);
            string keyw = string.Empty;
            if (Request.Form["Key"] != null)
            {
                keyw = Request.Form["Key"];
            }
            LoadList(1, con, ord, keyw);
        }
        /// <summary>
        /// 显示锁定按钮
        /// </summary>
        /// <param name="islock"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        protected string ShowLock(object islock, object id)
        {
            if (islock != null && islock != DBNull.Value && (bool)islock == true)
            {
                return "<a href=\"javascript:UnLockIt('" + id + "');\">解锁</a>";
            }
            else
            {
                return "<a href=\"javascript:LockIt('" + id + "');\">锁定</a>";
            }
        }
        /// <summary>
        /// 显示状态
        /// </summary>
        /// <param name="islock"></param>
        /// <returns></returns>
        protected string ShowLock(object islock)
        {
            if (islock != null && islock != DBNull.Value && (bool)islock == true)
            {
                return "<font color=\"red\">锁定</font>";
            }
            else
            {
                return "正常";
            }
        }

        protected string ShowRec(object isRec, object id)
        {
            if (isRec.ToString() == "1")
            {
                return "<a href=\"javascript:void(0);\" onclick=\"Rec('0','" + id.ToString() + "')\"><font color=\"red\">已推荐</font></a>";
            }
            else
            {
                return "<a href=\"javascript:void(0);\" onclick=\"Rec('1','" + id.ToString() + "')\">未推荐</a>";
            }
        }
    }
}
