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;

namespace JuSNS.Web.system.movie
{
    public partial class add : JuSNS.UI.Page.ManagePage
    {
        protected string sort = "movie";
        JuSNS.Home.Movie movie = new JuSNS.Home.Movie();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                getInfo();
        }

        /// <summary>
        /// 加载页面初始信息
        /// </summary>
        protected void getInfo()
        {
            for (int i = DateTime.Now.Year; i >= 1950; i--)
            {
                ListItem itm = new ListItem();
                itm.Value = i.ToString();
                itm.Text = i.ToString();
                YearOnShow.Items.Add(itm);
            }


            DataTable dt = movie.getDictMovieSortList();

            if (dt != null && dt.Rows.Count > 0)
            {
                this.MovieSort.DataSource = dt;
                this.MovieSort.DataTextField = "SortName";
                this.MovieSort.DataValueField = "ID";
                this.MovieSort.DataBind();
                this.MovieSort.SelectedIndex = 0;
                //getSelect(TxtClassID, xClassID.ToString());
            }
            dt.Clear(); dt.Dispose();
        }

        /// <summary>
        /// 执行添加电影过程
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Button1_Click(object sender, EventArgs e)
        {
            JuSNS.Model.MovieInfo movieinfo = new JuSNS.Model.MovieInfo();

            string s_moveSort = Request.Form["MovieSort"];
            if (string.IsNullOrEmpty(s_moveSort))
            {
                PageError("请选择电影类型!", "add.aspx");
            }
            string[] arr_moveSort = s_moveSort.Split(',');

            string s_savepath = "uploads/Movie";
            string Picture = string.Empty;
            string filename = string.Empty;
            if (this.supfile.HasFile)
            {
                JuSNS.Common.Input.UploadFile(this.supfile.PostedFile, s_savepath, out filename);
                Picture = filename;
            }

            movieinfo.MovieID = 0;
            movieinfo.Title = Title.Text;
            movieinfo.Director = Director.Text;
            movieinfo.Billing = Billing.Text;
            movieinfo.YearOnShow = Convert.ToInt32(Request.Form["YearOnShow"]);
            movieinfo.Gut = this.Gut.Value;
            movieinfo.Comments = 0;
            movieinfo.Seen = 0;
            movieinfo.Wanna = 0;
            movieinfo.Wonna = 0;
            movieinfo.Score = 0;
            if (!string.IsNullOrEmpty(Picture))
            {
                movieinfo.PosterFile = s_savepath + "/" + Picture;
            }
            else
            {
                movieinfo.PosterFile = s_savepath + "/default.jpg";
            }
            movieinfo.zt_dy = zt_dy.Value;
            movieinfo.zt_dy1 = zt_dy1.Value;
            movieinfo.zt_url = zt_url.Text;
            movieinfo.zt_url1 = zt_url1.Text;
            movieinfo.SortID = Convert.ToInt32(this.MovieSort.SelectedValue);
            movieinfo.UserID = 0;
            movieinfo.hits = 0;
            movieinfo.CreatTime = DateTime.Now;

            int movieid = movie.AddMovie(movieinfo);
            if (movieid > 0)
            {
                Response.Redirect("index.aspx");
            }
            else
            {
                PageError("添加电影失败", "add.aspx");
            }
        }
    }
}
