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;

namespace JuSNS.Web.Inc.Ajax
{
    public partial class MiniComment :JuSNS.UI.Page.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string mID = Request.QueryString["mid"];
            string Action = Request.QueryString["action"];
            if (this.GetUserID() == 0)
            {
                Response.Write("<span class=\"reshow\">请登录后进行操作！</span>");
                Response.End();
            }
            if (string.IsNullOrEmpty(mID))
            {
                Response.Write("参数错误，加载错误");
                Response.End();
            }
            else
            {
                switch (Action)
                {
                    case "show":
                        string ListStr = GetCommentList(Convert.ToInt32(mID));
                        Response.Write("<div class=\"line-none\"></div>\r\n" + ListStr + "\r\n");
                        Response.Write("<div  class=\"c padding10\"><input type=\"text\"  class=\"f-text\" id=\"conent_" + mID + "\"  size=\"30\" maxlength=\"100\" name=\"conent_" + mID + "\" /> <input type=\"button\" name=\"b_" + mID + "\" id=\"b_" + mID + "\" onclick=\"saveMiniContent('" + mID + "','1')\" value=\"回复\" class=\"f-button\" /></div>\r");
                        break;
                    case "Save":
                        string ContentStr = Request.QueryString["content"];
                        JuSNS.Home.Mood MD = new JuSNS.Home.Mood();
                        MD.SaveMiniComment(Convert.ToInt32(mID), ContentStr, GetUserID(), 0);
                        break;
                    case "Del":
                        string uid = Request.QueryString["uid"];
                        if (uid == GetUserID().ToString())
                        {
                            int bid = Convert.ToInt32(Request.QueryString["bid"]);
                            JuSNS.Home.Mood MDd = new JuSNS.Home.Mood();
                            MDd.DelMiniComent(bid);
                        }
                        break;
                }
                Response.End();
            }
        }

        protected string GetCommentList(int mID)
        {
            JuSNS.Home.Mood MD=new JuSNS.Home.Mood();
            string listStr = string.Empty;
            IDataReader rd = MD.GetMiniComment(mID);
            while (rd.Read())
            {
                JuSNS.Home.User user = new JuSNS.Home.User();
                UserInfo userinfo = new UserInfo();
                userinfo = user.GetUserInfo(Convert.ToInt32(rd["Commentator"].ToString()));
                string getUsername = userinfo.Username;
                string DelStr = string.Empty;
                if (GetUserID().ToString() == rd["Commentator"].ToString())
                {
                    DelStr = "<span class=\"delete\"><a href=\"javascript:void(0);\" onclick=\"Confirm(this,'确定删除回复吗？','删除心情日记回复',function(){delMiniComment('" + rd["Commentator"].ToString() + "','" + rd["ID"].ToString() + "','" + mID + "','1');});\">x</a></span>";
                }
                listStr += "<div class=\"c padding10\"><span class=\"nl\"><a href=\""+rooDir+"/user/" + JuSNS.Common.Public.URLWrite("", "r", rd["Commentator"].ToString()) + "\">" + getUsername + "</a> " + rd["Content"].ToString() + " </span>" + DelStr + "</div>\r";
            }
            rd.Close();
            return listStr;
        }
    }
}
