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

namespace JuSNS.Web.system.album
{
    public partial class index : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "album";
        protected void Page_Load(object sender, EventArgs e)
        {
            bindData();
            string DivErr = Request.QueryString["DivErr"];
            if (!string.IsNullOrEmpty(DivErr))
            {
                this.DivErr.InnerHtml = DivErr;
            }
        }

        protected void bindData()
        {
            int ReCount, PgCount;
            int PageIndex = 1;
            string order = Request.QueryString["order"];
            string key = Request.QueryString["key"];
            if (string.IsNullOrEmpty(order))
            {
                order = "AlbumID";
            }

            string listpage = "manageAlbumList_aspx";
            SqlConditionInfo[] sqlcondition = new SqlConditionInfo[1];
            sqlcondition[0] = new SqlConditionInfo("@order", order, TypeCode.Int32);

            if (Request.QueryString["Page"] != null)
                PageIndex = Convert.ToInt32(Request.QueryString["Page"]);

            if (!string.IsNullOrEmpty(key))
            {
                key = JuSNS.Common.Input.Filter(key.Trim());
                Array.Resize<SqlConditionInfo>(ref sqlcondition, sqlcondition.Length + 1);
                sqlcondition[1] = new SqlConditionInfo("@key", key, TypeCode.String);
                sqlcondition[1].Blur = 3;
                listpage = "manageAlbumlist_key_aspx";
            }
            DataTable dt = UtilPage.GetPage(listpage, PageIndex, PAGESZ, out ReCount, out PgCount, sqlcondition);
            string PageUrl = "index.aspx";
            this.RptData.DataSource = dt;
            this.RptData.DataBind();
            PageUrl += "?";
            if (!string.IsNullOrEmpty(order))
            {
                PageUrl += "&order=" + order;
            }
            if (!string.IsNullOrEmpty(key))
            {
                PageUrl += "&key=" + Server.UrlEncode(key);
            }
            PageUrl.Replace("??", "?");
            PageUrl.Replace("?&", "?");
            if (ReCount > PAGESZ)
            {
                this.DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, PgCount, PageUrl);
            }
            else
            {
                this.DivPage.Visible = false;
            }
        }

        /// <summary>
        /// 删除相册
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void delAlbum_Click(object sender, EventArgs e)
        {
            string ids = Request.Form["albumchkedid"];
            if (string.IsNullOrEmpty(ids))
            {
                Response.Redirect("index.aspx?" + Request.QueryString + "&DivErr=请选择一个项目。");
            }
            string[] id = ids.Split(',');
            for (int i = 0; i < id.Length; i++)
            {
                delAlbumfuc(Convert.ToInt32(id[i]));
            }
            Response.Redirect(Request.RawUrl);
        }


        private int delAlbumfuc(int AlbumID)
        {
            Home.Album ab = new Home.Album();
            return ab.Del(AlbumID);
        }
    }
}
