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.movie
{
    public partial class index : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "movie";
        protected void Page_Load(object sender, EventArgs e)
        {
            Operate();
            LoadList();
        }

        /// <summary>
        /// 加载分页
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        protected void LoadList()
        {
            int r, p, PageIndex = 0;
            PageIndex = Convert.ToInt32(Request.QueryString["Page"]);
            DataTable dt = null;
            string c = Request.QueryString["c"];
            if (JuSNS.Common.Input.IsInteger(c))
            {
                SqlConditionInfo st = new SqlConditionInfo("@C", Convert.ToInt32(c), TypeCode.Int32);
                dt = JuSNS.Home.UtilPage.GetPage("MovieList_C_aspx", PageIndex, PAGESZ, out r, out p, st);
            }
            else
            {
                if (Key.Text.Trim() != string.Empty)
                {
                    SqlConditionInfo st = new SqlConditionInfo("@Key", Key.Text, TypeCode.String);
                    st.Blur = 3;
                    dt = JuSNS.Home.UtilPage.GetPage("MovieList_Key_aspx", PageIndex, PAGESZ, out r, out p, st);
                }
                else
                {
                    dt = JuSNS.Home.UtilPage.GetPage("movieList_aspx", PageIndex, PAGESZ, out r, out p, null);
                }
            }
            if (dt != null)
            {
                Rpt_MovieList.DataSource = dt;
                Rpt_MovieList.DataBind();
            }
            //判断是否调用分页
            if (r > PAGESZ)
            {
                DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, p, "index.aspx");
            }
        }

        /// <summary>
        /// 操作
        /// </summary>
        protected void Operate()
        {
            string listSTR = "<li><a href=\"index.aspx\">所有影片</a></li>";
            JuSNS.Home.Movie mv = new JuSNS.Home.Movie();
            DataTable dt =mv.getDictMovieSortList();
            if(dt!=null&&dt.Rows.Count>0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    listSTR += "<li><a href=\"index.aspx?c=" + dt.Rows[i]["id"].ToString() + "\">" + dt.Rows[i]["SortName"].ToString() + "(" + dt.Rows[i]["Scount"].ToString() + ")</a></li>";
                }
            }
            dt.Clear(); dt.Dispose();
            this.SortList.InnerHtml = listSTR;
            string s_Act = Request.QueryString["action"];
            if (s_Act == "del")
            {
                string s_ID = Request.QueryString["id"];
                if (s_ID == null || s_ID == "")
                {
                    PageError("参数传递错误!", "index.aspx");
                }
                JuSNS.Home.Movie movie = new JuSNS.Home.Movie();
                if (movie.DelMovie(Convert.ToInt32(s_ID)) == 1)
                    Response.Redirect("index.aspx");
                else
                    PageError("删除电影失败!", "index.aspx");
            }
        }

        /// <summary>
        /// 执行搜索过程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
                LoadList();
        }
    }
}
