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 norke.admin
{
	/// <summary>
	/// messageDetail 的摘要说明。
	/// </summary>
	public partial class messageDetail : System.Web.UI.Page
	{
    
		protected void Page_Load(object sender, System.EventArgs e)
		{
            //权限检查
            HttpCookie cookie = Request.Cookies["norkeyangjian"];
            if (cookie == null)
            {
                Response.Redirect("~/login.aspx");
                return;
            }

            if( !IsPostBack )
            {

                if( Request.QueryString["id"] == null || Request.QueryString["id"].ToString() == String.Empty )
                {
                    Response.Write("错误!! 参数出了问题..");
                    Response.End();
                }
                
                string strID = Request.QueryString["id"].ToString();  
                //ViewState["ID"]

                alterState( strID ); //改变信息 状态
                getData( strID ); //获取信息 内容
            }
		}

        private void alterState( string strID ) //改变信息 状态
        {
            string mySql = "update message set MState=1 where MState<>1 and MID=" + strID;
            DBConn myDB = new DBConn(); 
            myDB.Update( mySql );
            myDB.Close();
        }

        private void getData( string strID ) //获取信息 内容
        {
            string mySql = "select * from message where MID=" + strID;
            DBConn myDB = new DBConn(); 
            SqlDataReader mydr  = myDB.getDataReader( mySql );
            if( mydr.Read() )
            {
                lblUName.Text = mydr["UName"].ToString();
                lblUPhone.Text = mydr["UPhone"].ToString();
                string strUEmail = mydr["UEmail"].ToString();
                lblUEmail.Text = "<a href='mailto:" + strUEmail + "'>" + strUEmail + "</a>";
                lblMTitle.Text = mydr["MTitle"].ToString();
                txtMContent.Text = CleanString.htmlOutputText( mydr["MContent"].ToString() ); 
                lblDate.Text = mydr["Pubdate"].ToString();
            }
            else
            {
                Response.Write("没有这条信息");
                mydr.Close();
                myDB.Close();
                Response.End();
            }
            mydr.Close();
            myDB.Close();
        }

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    

        }
		#endregion
	}
}
