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.index
{
    public partial class gbook : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            JuSNS.Home.GBook lw = new JuSNS.Home.GBook();
            string pid = Request.QueryString["pid"];
            string sendid = Request.QueryString["sendid"];
            string a = Request.QueryString["a"];
            string recid = Request.QueryString["recid"];
            if (a == "save")
            {
                string content = Request.QueryString["content"];
                if (sendid == recid)
                {
                    Response.Write("<span class=\"reshow\">自己不能给自己发送留言！</span>");
                    Response.End();
                }
                else
                {
                    if (lw.Edit(0, Convert.ToInt32(sendid), Convert.ToInt32(recid), content, Convert.ToInt32(pid), 1) > 0)
                    {
                        Response.Write("succ");
                        Response.End();
                    }
                    else
                    {
                        Response.Write("error");
                        Response.End();
                    }
                }
            }
            if (a == "del")
            {
                string id = Request.QueryString["id"];
                if (lw.Delete(this.UserID, Convert.ToInt32(id)) > 0)
                {
                    Response.Write("succ");
                    Response.End();
                }
                else
                {
                    Response.Write("error");
                    Response.End();
                }
            }
            else
            {
                if (!JuSNS.Common.Input.IsInteger(pid,false) || !JuSNS.Common.Input.IsInteger(sendid,false))
                {
                    Response.Write("错误的参数");
                    Response.End();
                }
                else
                {
                    string list = string.Empty;
                    IDataReader dr = lw.GetRepayBook(this.UserID, Convert.ToInt32(pid));
                    while (dr.Read())
                    {
                        string SendIDSTR = string.Empty;
                        if (dr["SendID"].ToString() == "-1")
                        {
                            SendIDSTR = "<span class=\"reshow\">管理员</span>";
                        }
                        else
                        {
                            SendIDSTR = "<a href=\"../user/" + JuSNS.Common.Public.URLWrite("", "r", dr["SendID"].ToString()) + "\">" + dr["UserName"].ToString() + "</a>";
                        }
                        list += "<div>" + SendIDSTR + " <span class=\"time\">(" + JuSNS.Common.Public.getTimeSpan(DateTime.Parse(dr["PostTime"].ToString())) + ")</span> 回复说：</div>";
                        list += "<div class=\"contentb\">" + dr["Content"].ToString() + " <a href=\"javascript:void(0);\" onclick=\"replaybook('" + dr["ID"].ToString() + "','" + dr["SendID"].ToString() + "','" + dr["RecID"].ToString() + "')\">回复(" + dr["ReplayCount"].ToString() + ")</a></div>";
                        list += "<div class=\"repbook\" id=\"repay_book_" + dr["ID"].ToString() + "\" style=\"display:none;\"></div>";
                    }
                    string formStr = "<div id=\"bookform_"+pid+"\"><form id=\"form1\" name=\"form1\" method=\"post\" action=\"\"><textarea name=\"repcontent_" + pid + "\" id=\"repcontent_" + pid + "\" cols=\"50\" maxlength=\"200\" class=\"f-text\" rows=\"4\"></textarea> <div><input type=\"button\" name=\"buttonbook\" id=\"buttonbook\" class=\"f-button\" onclick=\"sendreplybook('" + recid + "','"+sendid+"','" + pid + "')\" value=\"提交回复\" /> <span style=\"display: none;\" id=\"sendstate_" + pid + "\" class=\"showSumbitflow\">正在发送，请稍候……</span></div></form></div>";
                    dr.Close();
                    Response.Write("<div class=\"line-none\"></div><div style=\"padding-left:18px;\">" + list + formStr + "</div>");
                    Response.End();
                }
            }
        }
    }
}
