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
{
	/// <summary>
	/// guestbook 的摘要说明。
	/// </summary>
	public class guestbook : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.ImageButton ImageButton2;
		protected System.Web.UI.WebControls.ImageButton ImageButton1;
		protected System.Web.UI.WebControls.TextBox content;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.TextBox www;
		protected System.Web.UI.WebControls.TextBox mail;
		protected System.Web.UI.WebControls.TextBox qq;
		protected System.Web.UI.WebControls.TextBox dianhua;
		protected System.Web.UI.WebControls.TextBox lianxidizhi;
		protected System.Web.UI.WebControls.TextBox name;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.TextBox zuti;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.HtmlControls.HtmlForm Form1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
	    public string Addtime;
		
		
		private void Page_Load(object sender, System.EventArgs e)
		{
			
		}




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

		}
		#endregion

		private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			if(this.IsValid)
			{
				Addtime=System.DateTime.Now.ToString();
				//			Addtime=System.DateTime.Now.ToLongTimeString();
				int face=Convert.ToInt32(Request.Form["face"].ToString());
			
			

				//取得数据库路径
				string dbPath=System.Configuration.ConfigurationSettings.AppSettings["lyb"];
				//定义数据库连接字符串
				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 * from lyb where zuti!='"+this.zuti.Text+"'";
					////				string ACsqlII="select * from lyb";
					//				OleDbCommand ACcommII=new OleDbCommand(ACsqlII,ACconn);
					//				OleDbDataReader ACdrII=ACcommII.ExecuteReader();
					//				//				string y="";
					//				if(ACdrII.Read())
					//				{
					//					
					//					
					//					if(this.zuti.Text==ACdrII["zuti"].ToString())
					//					{
					//						//					Response.Write("<script>alert('此信息已添加过');</script>");
					//						//					Response.Write("<script>history.go(-2);</script>");
					//						Response.Redirect("Error/404b.htm");
					//					}
					//				}
					//				//				else
					//				//				{
					//				    
					//				//					this.TextBox1.Text=y;
					//				ACdrII.Close();



				
					
					//					if (Convert.ToInt32(SID.SelectedValue)==0)
					//					{
					string ACsqlI="insert into lyb(zuti,name,lianxidizhi,dianhua,qq,mail,www,face,content,Addtime) values ('"+this.zuti.Text+"','"+this.name.Text+"','"+this.lianxidizhi.Text+"','"+this.dianhua.Text+"','"+this.qq.Text+"','"+this.mail.Text+"','"+this.www.Text+"',"+face+",'"+this.content.Text.ToString().Replace("\r\n","<br>")+"','"+Addtime+"')";
						
					OleDbCommand ACcommI=new OleDbCommand(ACsqlI,ACconn);
					ACcommI.ExecuteNonQuery();
					Response.Write("<script>alert('留言成功添加');</script>");

					//					}
					//					else
					//					{
					//						string ACsqlI="insert into Article(ClassID,ChannelID,Title,LinkUrl,Content,Intro,Author,MY_Email,CopyFrom,MY_Site,Inputer,MY_QQ,UpdateTime) values ('"+SID.SelectedValue+"','"+ChannelID.SelectedValue+"','"+Title.Text+"','"+LinkUrl.Text+"','"+Content.Text+"','"+Intro.Text+"','"+Author.Text+"','"+MY_Email.Text+"','"+CopyFrom.Text+"','"+MY_Site.Text+"','"+Inputer.Text+"','"+MY_QQ.Text+"','"+Addtime+"')";
					//
					//						OleDbCommand ACcommI=new OleDbCommand(ACsqlI,ACconn);
					//						ACcommI.ExecuteNonQuery();
					//						Response.Write("<script>alert('信息成功添加');</script>");	
					//
					//					}
					
 
					
					
																													
				
				}
				catch(Exception ex)
				{
					Response.Write(ex.ToString());
				}
				finally
				{
					ACconn.Close();
				}
			}
		}

		private void ImageButton2_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			this.zuti.Text="";
			this.name.Text="";
			this.lianxidizhi.Text="";
			this.qq.Text="";
			this.mail.Text="";
			this.www.Text="";
			this.content.Text="";
		}

		private void btushow_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("showguestbook.aspx");
		}
	}
}
