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.Ajax
{
    public partial class CommentIndex : JuSNS.UI.Page.UserPage
    {
        JuSNS.Home.Comment Commd = new JuSNS.Home.Comment();
        protected void Page_Load(object sender, EventArgs e)
        {
            string GType = Request.QueryString["type"];
            string GID = Request.QueryString["id"];
            string Cid = Request.QueryString["cid"];
            string Action = Request.QueryString["action"];
            string ListStr = string.Empty;
            if (Action != string.Empty && Action != null)
            {
                if (Action == "del")
                {
                    Commd.DelComment(UserID, Convert.ToInt32(GID), GType);
                }
                else if (Action == "add")
                {
                    int mUserID = UserID;
                    int InfoID = Convert.ToInt32(GID);
                    string mContent = JuSNS.Common.Input.ForTXT(Request.QueryString["content"].ToString());
                    int CommentID = Convert.ToInt32(Request.QueryString["commentid"].ToString());
                    if (Commd.AddComment(mUserID, GType, InfoID, mContent, CommentID) > 0)
                    {
                        Response.Write("Success");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("Error");
                        Response.End();
                    }
                }
            }
            else
            {
                if (GType == "mini")
                {
                    ListStr += showMiniList(Convert.ToInt32(GID), GType, Cid);
                    ListStr += "<input type=\"text\" name=\"submitMiniBlogSend_" + GID + "\"  class=\"f-text\"maxlength=\"100\"   size=\"35\"   id=\"submitMiniBlogSend_" + GID + "\"  /> <input onclick=\"saveDataComment('" + UserID + "','mini','" + GID + "','submitMiniBlogSend_" + GID + "','0','1','mini_" + Cid + "')\" type=\"button\"  class=\"f-button\" name=\"rebutton\" id=\"rebutton\" value=\"»Ø¸´\" />";
                }
                Response.Write(ListStr);
                Response.End();
            }
        }

        public string showMiniList(int Id, string GType, string Cid)
        {
            string ListStr = string.Empty;
            IDataReader dr = Commd.GetCommentList(Id, GType);
            while (dr.Read())
            {
                JuSNS.Home.User user = new JuSNS.Home.User();
                JuSNS.Model.UserInfo userinfo = new JuSNS.Model.UserInfo();
                userinfo = user.GetUserInfo(Convert.ToInt32(dr["Commentator"].ToString()));
                string getUsername = userinfo.Username;
                string DelStr = string.Empty;
                if (dr["Commentator"].ToString() == UserID.ToString())
                {
                    DelStr = "<span class=\"delete\"><a href=\"javascript:void(0);\" class=\"m-del\" title=\"É¾³ý\" onclick=\"deleteComment('" + dr["Commentator"].ToString() + "','mini','" + dr["ID"].ToString() + "','mini_" + Cid + "','" + dr["MiniBlogID"].ToString() + "','" + Cid + "');\">x</a>";
                }
                ListStr += " <img src=\"/images/comments.gif\" /> <a href=\"/user/?r=" + dr["Commentator"].ToString() + "\">" + getUsername + "</a> <span style=\"color:#666666;\">" + dr["Content"].ToString() + " " + DelStr + " &nbsp; " + JuSNS.Common.Public.getTimeSpan(Convert.ToDateTime(dr["PostTime"].ToString())) + "</span><br />";
            }
            dr.Close();
            return ListStr;
        }
    }
}
