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.OleDb;

namespace baoge
{
	/// <summary>
	/// NewsView 的摘要说明。
	/// </summary>
	public class NewsView : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		public int CID;
		public string ATitle;
		public string Atitle,CopyFrom,Author,Inputer,Hits,Addtime,Content;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.Label Label2;
	    public string WebName,WebUrl,WebLogo,WebEmail,CAddress,CTel,CQQ,Webcopyright;
		protected System.Web.UI.WebControls.Label lblremary;
		protected System.Web.UI.WebControls.Label Label8;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面

			if(!IsPostBack)
			{
				NewsBodyA();
				SystemBaseDataBind();
//				Naviget();
				CopyRightA();

			}


		}

		private void NewsBodyA()
		{
			
			int CID=Convert.ToInt32(Request.QueryString["ID"]);
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对像
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);


			ACconn.Open();

			//定义SQL语句
			string ACsql="select * from Article where ArticleID="+CID;

			//创建Command对像
			OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
			//通过执行Command实例化DataReader类
			OleDbDataReader ACdr=ACcomm.ExecuteReader();
		
			
			if(ACdr.Read ())
			{
                Label2.Text=ACdr["Title"].ToString();
                Label3.Text=ACdr["CopyFrom"].ToString();
				Label4.Text=ACdr["Author"].ToString();
				Label5.Text=ACdr["Inputer"].ToString();
				Label6.Text=ACdr["Updatetime"].ToString().Substring(0,8);
                Label7.Text=ACdr["Content"].ToString();
				this.Label8.Text=ACdr["Hits"].ToString();
				this.lblremary.Text="<a href='remark.aspx?id="+ACdr["ArticleID"]+"&title="+ACdr["Title"]+"'>评论</a>";
                ATitle=Label2.Text.ToString();
			}
			ACdr.Close ();//切记一定要关闭阅读器

			ACcomm.CommandText="update Article set Hits=Hits+1 where ArticleID="+CID;
//			OleDbDataReader ACdrr=ACcomm.ExecuteReader();
//			if(ACdrr.Read ())
//			{
//				ATitle=Label2.Text.ToString();
//				this.Label8.Text=ACdr["Hits"].ToString();
//			}
//			ACdrr.Close ();//切
			ACcomm.ExecuteNonQuery();
			ACconn.Close();

		}

        

		private void SystemBaseDataBind()
		{
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对像
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
			//数据库操作
			try
			{
				ACconn.Open();
				//取得所需操作的记录ID

				//定义SQL语句
				string ACsql="select ID,WebName,WebUrl,WebLogo,WebEmail,CAddress,CTel,CQQ,Webcopyright from Config where ID=1";
				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				//通过执行Command实例化DataReader类
				OleDbDataReader ACdr=ACcomm.ExecuteReader();
				if(ACdr.Read())
				{
					WebName=ACdr["WebName"].ToString();
					WebUrl=ACdr["WebUrl"].ToString();
					WebLogo=ACdr["WebLogo"].ToString();
					WebEmail=ACdr["WebEmail"].ToString();
					CAddress=ACdr["CAddress"].ToString();
					CTel=ACdr["CTel"].ToString();
					CQQ=ACdr["CQQ"].ToString();
					Webcopyright=ACdr["Webcopyright"].ToString();

					ACdr.Close();

				}
				else
				{
					Response.Write("对不起，请先填加网站信息");
				}
			
			}
			catch(Exception ex)
			{
				Response.Write(ex.ToString());
			}
			finally
			{
				ACconn.Close();

			}
		}




	
//		public string Naviget()
//		{
//			//取得数据库路径
//			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
//			//定义连接字符串
//			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
//			//创建数据库对像
//			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
//
//
//			ACconn.Open();
//
//			string Naviget=null;//新闻主体
//			//定义SQL语句
//			string ACsql="select * from Channel";
//
//			//创建Command对像
//			OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
//			//通过执行Command实例化DataReader类
//			OleDbDataReader ACdr=ACcomm.ExecuteReader();
//		
//			
//			while(ACdr.Read ())//循环读取
//			{
//
//				Naviget+=" "+" "+"|"+" "+" ";
//				Naviget+="<a class=Na href='ListChannel.aspx?id="+ACdr["ChannelID"]+"' target=_blank>"+ACdr["ChannelName"]+"</a>";
//			}
//			ACdr.Close ();//切记一定要关闭阅读器
//			ACconn.Close();
//			return Naviget;
//			
//
//		}



		private void CopyRightA()
		{
			//取得数据库路径
			string dbPath=System.Configuration.ConfigurationSettings.AppSettings["dbPath"];
			//定义连接字符串
			string ACconnStr="Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(dbPath);
			//创建数据库对像
			OleDbConnection ACconn=new OleDbConnection(ACconnStr);
			//数据库操作
			try
			{
				ACconn.Open();
				//取得所需操作的记录ID

				//定义SQL语句
				string ACsql="select ID,WebName,WebUrl,WebLogo,WebEmail,CAddress,CTel,CQQ,Webcopyright from Config where ID=1";
				//创建Command对像
				OleDbCommand ACcomm=new OleDbCommand(ACsql,ACconn);
				//通过执行Command实例化DataReader类
				OleDbDataReader ACdr=ACcomm.ExecuteReader();
				if(ACdr.Read())
				{
					WebName=ACdr["WebName"].ToString();
					WebUrl=ACdr["WebUrl"].ToString();
					WebLogo=ACdr["WebLogo"].ToString();
					WebEmail=ACdr["WebEmail"].ToString();
					CAddress=ACdr["CAddress"].ToString();
					CTel=ACdr["CTel"].ToString();
					CQQ=ACdr["CQQ"].ToString();
					Webcopyright=ACdr["Webcopyright"].ToString();
					ACdr.Close();

				}
				else
				{
					Response.Write("对不起，请先填加网站信息");
				}
			
			}
			catch(Exception ex)
			{
				Response.Write(ex.ToString());
			}
			finally
			{
				ACconn.Close();

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

		}
		#endregion
	}
}
