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;
using System.Configuration;
using System.IO;
namespace baoge.Admin
{
	/// <summary>
	/// Admin_Addlink 的摘要说明。
	/// </summary>
	public class Admin_Addlink : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox sitename;
		protected System.Web.UI.WebControls.TextBox dizhi;
		protected System.Web.UI.WebControls.TextBox logo;
		protected System.Web.UI.WebControls.TextBox jianjie;
		protected System.Web.UI.WebControls.Button Button1;
	    public int CID;
		protected System.Web.UI.WebControls.DropDownList ChannelID;
		public int i;
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["AdminName"]==null)
			{
				Response.Redirect("Admin_Login.aspx");
			}
			if(!IsPostBack)
			{
				ChannelDataBind();

			}
		}


		private void ChannelDataBind()
		{
	

			//取得数据库路径
			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 ACsql="select id,name from linklei";
			OleDbDataAdapter ACda=new OleDbDataAdapter(ACsql,ACconn);
			DataTable ACdt=new DataTable();
			ACda.Fill(ACdt);

			//频道的数据绑定
			ChannelID.DataSource=ACdt;
			ChannelID.DataTextField="name";
			ChannelID.DataValueField="id";
			ChannelID.DataBind();
		
			ACda.Dispose();
//			if(this.ChannelID.Items.Count==0)
//			{
//			   this.ChannelID.Items[0].Value="其它";
//			}
			ACconn.Close();

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

		}
		#endregion

		private void Button1_Click(object sender, System.EventArgs e)
		{
			string i=this.jianjie.Text;
			string j=i.Replace("\n","<BR>");
			j=i.Replace("\t","   "); 
            j=i.Replace(" ","&nbsp;"); 
//            content = content.Replace("\n","<BR>");
//			content=content.Replace("\t","   "); 
//			content=content.Replace(" ","&nbsp;"); 
			int CID=Convert.ToInt32(ChannelID.SelectedValue);

			

			//取得数据库路径
			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();

				
				//				int SSID=Convert.ToInt32(SID.SelectedValue);
				//判断添加新闻是否已存在
//				string ACsqlII="select linkid from link where sitename='"+sitename.Text+"'";
				string ACsqlII="select * from link";
				OleDbCommand ACcommII=new OleDbCommand(ACsqlII,ACconn);
				OleDbDataReader ACdrII=ACcommII.ExecuteReader();
				//				string y="";
				while(ACdrII.Read())
				{
//					if(this.sitename.Text==(string)ACdrII["sitename"]&&this.ChannelID.SelectedItem.ToString()==(string)ACdrII["name"])
//					{
//					
//						Response.Write("<script>alert('此信息已添加过');</script>");
//						Response.Write("<script>history.go(-1);</script>");
//					}
   
				}
				
					

              ACdrII.Close();							

			    
//				if(this.sitename.Text!=(string)ACdrII["sitename"]&&this.ChannelID.SelectedItem.ToString()!=(string)ACdrII["name"])
//				{
						
					string ACsqlI="insert into link(id,sitename,name,dizhi,logo,jianjie) values ('"+ChannelID.SelectedValue+"','"+this.sitename.Text+"','"+ChannelID.SelectedItem+"','"+this.dizhi.Text+"','"+this.logo.Text+"','"+j.Trim()+"')";
						
					OleDbCommand ACcommI=new OleDbCommand(ACsqlI,ACconn);
					ACcommI.ExecuteNonQuery();
					Response.Write("<script>alert('信息成功添加');</script>");
			
				
//				}
					
					 
																						
				
			}
			catch(Exception ex)
			{
				Response.Write(ex.ToString());
			}
			finally
			{
				
				ACconn.Close();
			}

		}
	}
}
