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.home.movie
{
    public partial class pic : JuSNS.UI.Page.UserPage
    {
        JuSNS.Home.Movie movie = new JuSNS.Home.Movie();
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";
            string movieid = Request.QueryString["ID"];
            if (!JuSNS.Common.Input.IsInteger(movieid))
            {
                PageError("参数传递错误!", "index.aspx");
            }
            HidMID.Value = movieid;
            if (Request.QueryString["succ"] == "1")
            {
                this.succDiv.Visible = true;
            }
            LoadList();
        }

        /// <summary>
        /// 加载分页
        /// </summary>
        /// <param name="PageIndex">当前页数</param>
        protected void LoadList()
        {
            int r, p, PageIndex = 0;
            PageIndex = Convert.ToInt32(Request.QueryString["Page"]);

            MovieInfo movieinfo = movie.GetMovieInfo(Convert.ToInt32(Request.QueryString["ID"]));
            Lit_MovieName.Text = movieinfo.Title+"的海报";

            SqlConditionInfo st = new SqlConditionInfo("@MovieID", Convert.ToInt32(HidMID.Value), TypeCode.Int32);

            DataTable dt = JuSNS.Home.UtilPage.GetPage("moviepiclist_u_aspx", PageIndex, 32, out r, out p, st);
            if (dt != null)
            {
                Rpt_MoviePicList.DataSource = dt;
                Rpt_MoviePicList.DataBind();
            }
            //判断是否调用分页
            if (r > 32)
            {
                DivPage.InnerHtml = PageNavigator.Pagination(PageIndex, p, "pic.aspx?ID=" + HidMID.Value);
            }
            if (r == 0)
                DivPage.InnerHtml = "暂无电影海报";
        }

        protected string GetUserNames(object userid)
        {
            if (userid.ToString() == "0")
            {
                return "管理员";
            }
            UserInfo mdl = new UserInfo();
            JuSNS.Home.User us = new JuSNS.Home.User();
            mdl = us.GetUserInfo(Convert.ToInt32(userid.ToString()));
            return mdl.Username;

        }



        protected void Button1_Click(object sender, EventArgs e)
        {
            GetIsNotEmail();
            if (Page.IsValid)
            {
                string Picture = string.Empty;
                string filename = string.Empty;
                string s_savepath = "uploads/movie";
                if (this.supfile.HasFile)
                {
                    JuSNS.Common.Input.UploadFile(this.supfile.PostedFile, s_savepath, out filename);
                    Picture = filename;
                }
                else
                {
                    PageError("请选择海报", "pic.aspx?id=" + HidMID.Value);
                }
                MoviePosterInfo mp = new MoviePosterInfo();
                mp.MovieID = Convert.ToInt32(this.HidMID.Value);
                mp.PostIP = JuSNS.Common.Public.GetClientIP();
                mp.PostTime = DateTime.Now;
                mp.UserID =this.UserID;
                mp.IsLock = 1;
                mp.FileName = s_savepath + "/" + filename;
                if (movie.AddMoviePoster(mp) > 0)
                {
                    Response.Redirect("pic.aspx?succ=1&id=" + HidMID.Value);
                }
            }
        }
    }
}
