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.Inc
{
    public partial class MovieAjax : JuSNS.UI.Page.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";
            if (this.GetUserID() == 0)
            {
                Response.Write("请登录后操作！");
                Response.End();
            }
            else
            {
                Operate();
            }
        }

        /// <summary>
        /// 执行相关操作
        /// </summary>
        protected void Operate()
        {
            string s_Act = Request.QueryString["Action"];
            string s_Content = Request.QueryString["Content"];
            string s_MiD = Request.QueryString["movieid"];
            string s_Score = Request.QueryString["Score"];
            string s_Return = "";
            string s_Return2 = "False";
            JuSNS.Home.Movie movie = new JuSNS.Home.Movie();
            JuSNS.Model.MovieInfo movieinfo = new JuSNS.Model.MovieInfo();
            int movieid = Convert.ToInt32(s_MiD);
            int istar = 0;
            switch (s_Act)
            {
                case "Save":
                    movie.SaveComment(GetUserID(), movieid, s_Content);
                    s_Return = "<div id=\"movie-review\">" +
                               "<div class=\"content\" runat=\"server\" id=\"div_review\">" + JuSNS.Common.Input.HtmlEncode(s_Content) + "" +
                               "</div><br />(<a href=\"javascript:void(0);\" onclick=\"EditComm(" +
                               "document.form1.HidMovieID.value);\" class=\"edit\">修改评论</a>)<span id=\"span_err\"></span></div>";
                    break;
                case "Edit":
                    s_Return = movie.getComment(GetUserID(), movieid);
                    s_Return = "<p><textarea id=\"review\" rows=\"3\" maxlength=\"500\" " +
                               "style=\"width: 250px\">" + JuSNS.Common.Input.HtmlEncode(s_Return) + "</textarea>" +
                               "</p><p class=\"pstr\"><input type=\"button\" class=\"f-button\" value=\"发表评论\" " +
                               "onclick=\"javascript:SaveComm(document.form1.review.value,document.form1.HidMovieID.value);\" />" +
                               "<span id=\"span_err\"></span></p>";
                    break;
                case "Think":
                    if (Session["ThinkMovie" + movieid] != null && Session["ThinkMovie" + movieid].ToString() == "True")
                    {
                        movie.UpdateWanna(movieid, GetUserID(), false);
                        Session["ThinkMovie" + movieid] = "";
                    }
                    else
                    {
                        movie.UpdateWanna(movieid, GetUserID(), true);
                        Session["ThinkMovie" + movieid] = "True";
                        s_Return2 = "True";
                    }
                    movieinfo = movie.GetMovieInfo(movieid);
                    istar = Convert.ToInt32(movieinfo.Score / 5);

                    s_Return = "<span class=\"rate-star rate-star" + istar + "\">" + istar + "</span> " + movieinfo.Score + "/10 " +
                                 "(<span class=\"reshow\">" + movieinfo.Seen + "</span> 人) &nbsp; " +
                                 "<span class=\"reshow\">" + movieinfo.Wanna + "</span> 人想看，<span class=\"reshow\">" + movieinfo.Wonna + "</span> 人不想看";
                    break;
                case "NoThink":
                    if (Session["NoThinkMovie" + movieid] != null && Session["NoThinkMovie" + movieid].ToString() == "True")
                    {
                        movie.UpdateWonna(movieid, GetUserID(), false);
                        Session["NoThinkMovie" + movieid] = "";
                    }
                    else
                    {
                        movie.UpdateWonna(movieid, GetUserID(), true);
                        Session["NoThinkMovie" + movieid] = "True";
                        s_Return2 = "True";
                    }
                    movieinfo = movie.GetMovieInfo(movieid);
                    istar = Convert.ToInt32(movieinfo.Score / 5);
                    s_Return = "<span class=\"rate-star rate-star" + istar + "\">" + istar + "</span> " + movieinfo.Score + "/10 " +
                                 "(<span class=\"reshow\">" + movieinfo.Seen + "</span> 人) &nbsp; " +
                                 "<span class=\"reshow\">" + movieinfo.Wanna + "</span> 人想看，<span class=\"reshow\">" + movieinfo.Wonna + "</span> 人不想看";
                    break;
                case "Open":
                    movieinfo = movie.GetMovieInfo(movieid);
                    s_Return = movieinfo.Gut + "<a href=\"javascript:void(0);\" " +
                              "onclick=\"javascript:MoreGut(" + movieid + ",'Close');\">收起...</a>";
                    break;
                case "Close":
                    movieinfo = movie.GetMovieInfo(movieid);
                    if (movieinfo.Gut.Length > 200)
                        s_Return = JuSNS.Common.Input.GetSubString(movieinfo.Gut, 200) + "... " +
                                   "<a href=\"javascript:void(0);\" onclick=\"javascript:MoreGut(" + movieid + ",'Open');\">更多...</a>";
                    else
                        s_Return = movieinfo.Gut;
                    break;
                case "SaveScore":
                    int Score = Convert.ToInt32(s_Score);
                    movie.SaveScore(GetUserID(), movieid, Score);
                    movieinfo = movie.GetMovieInfo(movieid);
                    istar = Convert.ToInt32(movieinfo.Score);
                    s_Return = "<span class=\"rate-star rate-star" + istar + "\">" + istar + "</span> " + movieinfo.Score * 2 + "/10 " +
                                 "(<span class=\"reshow\">" + movieinfo.Seen + "</span> 人) &nbsp; " +
                                 "<span class=\"reshow\">" + movieinfo.Wanna + "</span> 人想看，<span class=\"reshow\">" + movieinfo.Wonna + "</span> 人不想看";
                    break;
            }
            Response.Write(s_Return);
            Response.End();
        }
    }
}
