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.home.ask
{
    public partial class edit : JuSNS.UI.Page.UserPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            JuSNS.Home.Ask ask = new JuSNS.Home.Ask();
            JuSNS.Model.AskInfo askinfo = new JuSNS.Model.AskInfo();
            string action = Request.QueryString["action"];
            if (action == "update")
            {
                if (ask.EditInfo(this.UserID, Convert.ToInt32(Request.QueryString["qID"]), Request.QueryString["Content"]) > 0)
                {
                    Response.Write("right");
                    Response.End();
                }
                Response.Write("error");
                Response.End();
            }
            else if (action == "show")
            {
                askinfo = ask.GetAskInfo(Convert.ToInt32(Request.QueryString["qID"]));
                string tags = string.Empty;
                if (!string.IsNullOrEmpty(askinfo.Tag))
                {
                    string[] arr = askinfo.Tag.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                    if (arr != null)
                    {
                        tags += "<div>标签：";
                        for (int i = 0; i < arr.Length; i++)
                        {
                            tags += "<a href=\"" + rooDir + "/home/ask/index.aspx?r=all&key=" + JuSNS.Common.Input.URLEncode(arr[i]) + "\">" + arr[i] + "</a> ";
                        }
                        tags += "</div>";
                    }
                }
                string Pic = string.Empty;
                if (!string.IsNullOrEmpty(askinfo.Pic))
                {
                    Pic = "<a href=\"" + rooDir + "/" + askinfo.Pic + "\" target=\"_blank\"><img src=\"" + rooDir + "/" + askinfo.Pic + "\" align=\"left\" alt=\"点击放大\" style=\"padding:3px;border:1px solid #eeeeee;width:120px;margin:0 10px 5px 0;\" /></a>";
                }
                Response.Write(tags + Pic + askinfo.Content);
                Response.End();
            }
            else
            {
                int qID = Convert.ToInt32(Request.QueryString["qID"]);
                askinfo = ask.GetAskInfo(qID);
                string ContentForm = string.Empty;
                ContentForm += "<form id=\"form2\" action=\"\">";
                ContentForm += "<div><textarea name=\"qContent\" id=\"qContent\" class=\"f-text s90\" rows=\"5\">" + askinfo.Content + "</textarea></div>";
                ContentForm += "<div><input type=\"button\" onclick=\"SaveEdit('" + qID + "');\" name=\"buttonEdit\" class=\"f-button\" id=\"buttonEdit\" value=\"修改\" /> ";
                ContentForm += " <input type=\"button\" onclick=\"ShowEdit('" + qID + "');\" name=\"buttonEdit\" class=\"f-reset\" id=\"buttonEdit\" value=\"取消\" /></div>";
                ContentForm += "</form>";
                Response.Write(ContentForm);
                Response.End();
            }
        }
    }
}
