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.mood
{
    public partial class edit : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string a = Request.QueryString["a"];
            if (a != "edit")
            {
                if (a == "get")
                {
                    JuSNS.Home.JUser us = new JuSNS.Home.JUser();
                    string mInfo = string.Empty;
                    string resultStr = string.Empty;
                    IDataReader dr = us.GetMoodInfo(UserID);
                    if (dr.Read())
                    {
                        mInfo = dr["Content"].ToString() + "<span class=\"time\">" + JuSNS.Common.Public.getTimeEXSpan(DateTime.Parse(dr["PostTime"].ToString())) + "</span> <a href=\"mood/?mid=" + dr["ID"].ToString() + "#re_" + dr["ID"].ToString() + "\">回复(" + dr["ReplayNum"].ToString() + ")</a> ";
                    }
                    if (mInfo != string.Empty)
                    {
                        resultStr = JuSNS.Common.Public.CheckSma(mInfo);
                    }
                    else
                    {
                        resultStr = "你可以更新状态，让朋友们知道你在做什么... ";
                    }
                    dr.Close();
                    resultStr = "<span id=\"myNewMoodTopDiv\">" + resultStr + " <a href=\"javascript:void(0);\" onclick=\"changemood('" + UserID + "')\">编辑</a></span>";
                    Response.Write(resultStr);
                    Response.End();
                }
                else
                {
                    string uID = Request.QueryString["uid"];
                    if (uID != this.UserID.ToString())
                    {
                        Response.Write("错误的参数");
                        Response.End();
                    }
                    else
                    {
                        string listStr = string.Empty;
                        listStr += "<a href=\"javascript:void(0);\"  id=\"face\" onclick=\"showface(this.id,'editMood_index',1);\"><img src=\"../template/images/face/c.gif\" title=\"选择表情\"  align=\"absmiddle\" /></a> <input value=\"\" id=\"editMood_index\" maxlength=\"100\" name=\"editMood_index\" class=\"f-text s50\" type=\"text\" />";
                        listStr += " <input type=\"button\" value=\"发布\" onclick=\"editMoodNewPost();\" class=\"f-button\" /> <input type=\"button\" value=\"取消\"  onclick=\"editreset();\"  class=\"f-reset\" />";
                        Response.Write(listStr);
                        Response.End();
                    }
                }
            }
            else
            {
                string cont = Request.QueryString["content"];
                if (cont == "这里输入您的心情日记" || string.IsNullOrEmpty(cont))
                {
                    Response.Write("请输入心情日记内容！");
                    Response.End();
                }
                JuSNS.Home.Mood mini = new JuSNS.Home.Mood();
                if (mini.SaveMini(this.UserID, JuSNS.Common.Input.ToHtml(cont), "") > 0)
                {
                    JuSNS.Home.JUser us = new JuSNS.Home.JUser();
                    string mInfo = string.Empty;
                    string resultStr = string.Empty;
                    IDataReader dr = us.GetMoodInfo(UserID);
                    if (dr.Read())
                    {
                        mInfo = dr["Content"].ToString() + " <span class=\"time\">" + JuSNS.Common.Public.getTimeEXSpan(DateTime.Parse(dr["PostTime"].ToString())) + "</span> <a href=\"mood/?mid=" + dr["ID"].ToString() + "#re_" + dr["ID"].ToString() + "\">回复(" + dr["ReplayNum"].ToString() + ")</a> ";
                    }
                    if (mInfo != string.Empty)
                    {
                        resultStr = JuSNS.Common.Public.CheckSma(mInfo);
                    }
                    else
                    {
                        resultStr = "你可以更新状态，让朋友们知道你在做什么... ";
                    }
                    dr.Close();
                    resultStr = "<span id=\"myNewMoodTopDiv\">" + resultStr + " <a href=\"javascript:void(0);\" onclick=\"changemood('" + UserID + "')\">编辑</a></span>";
                    Response.Write(resultStr);
                    Response.End();
                }
            }
        }
    }
}
