⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guestbook.aspx.cs

📁 这是一个ASP.NET和数据库的程序
💻 CS
字号:
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;
using System.Configuration;
using System.IO;
namespace baogelyb
{
	/// <summary>
	/// guestbook 的摘要说明。
	/// </summary>
	public class guestbook : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.TextBox zuti;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.TextBox name;
		protected System.Web.UI.WebControls.TextBox lianxidizhi;
		protected System.Web.UI.WebControls.TextBox dianhua;
		protected System.Web.UI.WebControls.TextBox qq;
		protected System.Web.UI.WebControls.TextBox mail;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
		protected System.Web.UI.WebControls.TextBox www;
		protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.TextBox content;
		protected System.Web.UI.WebControls.ImageButton ImageButton1;
		protected System.Web.UI.WebControls.ImageButton ImageButton2;
	    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.Sql.4.0;Data Source="+Server.MapPath(dbPath);
				//创建数据库连接对像
				SqlConnection ACconn=db.createconnection();

				try
				{
					//打开数据库
					ACconn.Open();

				
					//				//				int SSID=Convert.ToInt32(SID.SelectedValue);
					//				//判断添加新闻是否已存在
					//				string ACsqlII="select * from lyb where zuti!='"+this.zuti.Text+"'";
					////				string ACsqlII="select * from lyb";
					//				SqlCommand ACcommII=new SqlCommand(ACsqlII,ACconn);
					//				SqlDataReader 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+"')";
						
					SqlCommand ACcommI=new SqlCommand(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+"')";
					//
					//						SqlCommand ACcommI=new SqlCommand(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="";
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -