using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace free.bbs
{
	/// <summary>
	/// Summary description for banji_huitie.
	/// </summary>
	public class banji_huitie : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox TextBox2;
		protected System.Web.UI.WebControls.Button Button1;
		protected System.Data.SqlClient.SqlConnection myconn;
		protected System.Data.SqlClient.SqlCommand mycomm;
		SqlDataReader myread;

		void databind()
		{
			myconn=new SqlConnection(Session["str_connection"].ToString());
			myconn.Open();
			try
			{
				mycomm=new SqlCommand("select neirong from huifu where (huifu_id="+Request.Params["huifu_id"]+" and yonghuming='"+Request.Cookies["free_huiyuan"].Value.ToString()+"')",myconn);
				myread=mycomm.ExecuteReader();
				try
				{
					myread.Read();
					TextBox2.Text=htmldecode(myread["neirong"].ToString());
					myread.Close();
				
				}
				catch
				{
					myread.Close();
					Response.Write("<script>alert('你无权编辑该主题')</script>");
					Response.Write("<script>window.close()</script>");
					
				}
			}
			catch
			{
				Response.Write("<script>alert('你无权编辑该主题')</script>");

				
			}
			
			myconn.Close();
		}
		private void Page_Load(object sender, System.EventArgs e)
		{
			
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Button1.Click += new System.EventHandler(this.Button1_Click);
			//this.Load += new System.EventHandler(this.Page_Load);
			databind();

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			DateTime shijian=DateTime.Now;
			string sqlstr="update huifu set  neirong=@neirong, uptime='"+shijian+"',isup='1' where huifu_id="+Request.Params["huifu_id"]+"";
			mycomm=new SqlCommand(sqlstr,myconn);
			mycomm.Parameters.Add(new SqlParameter("@neirong", SqlDbType.NText));
			mycomm.Parameters["@neirong"].Value =htmlencode(TextBox2.Text);
			mycomm.Connection.Open();		
			try 
			{
				mycomm.ExecuteNonQuery();
				Response.Write("<script>alert('编辑成功')</script>");
				Response.Write("<script>window.close()</script>");
			}
			catch
			{
				Response.Write("<script>alert('编辑失败')</script>");}
			mycomm.Connection.Close();
		
		}
		private string htmlencode(string str)
		{
			str=Server.HtmlEncode(str);
			str=str.Replace("\r\n","<br>");
			char ch;
			ch=(char)32;
			str=str.Replace(ch.ToString(),"");
			return str;
		}
		private string htmldecode(string str)
		{
			str=Server.HtmlDecode(str);
			str=str.Replace("<br>","\r\n");
			return str;
		}
	}
}
