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

📄 default.aspx.cs

📁 This is not a very mean things
💻 CS
字号:
//-----------------------------------------------------------------------
//
// WebExpert.NET 1.0 
//
// (c) 2003, www.AspCool.com. All rights reserved.
// ASP酷技术网 版权所有
//
// 该源码下载自:http://www.51aspx.com
// 邮箱:tim@aspcool.com
//
// 版权声明:本程序仅供学习使用,你也可以修改后在网站上使用,但使用时必
// 须保留ASP酷技术网(www.AspCool.com)的版权信息和链接。本程序随《ASP.NET
// 网站建设专家》一书赠送,未经作者同意,不得随意修改、传播。
//
// 描述:
//   此文件包含下面的类:
//       _default
//
// 作者:     王保健
// 时间:     2005-01-15
//
//------------------------------------------------------------------------
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;
namespace AspCool.WebExpert.Newsletter
{
	/// <summary>
	/// Summary description for _default.
	/// </summary>
	public class _default : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btnSubscribe;
		protected System.Web.UI.WebControls.TextBox txtEmail;
		protected System.Web.UI.WebControls.Button btnUnsubscribe;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
//			btnUnsubscribe.Attributes.Add("OnClick","javascript:Return Confirm('您确信要退定吗?');");
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnSubscribe.Click += new System.EventHandler(this.btnSubscribe_Click);
			this.btnUnsubscribe.Click += new System.EventHandler(this.btnUnsubscribe_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSubscribe_Click(object sender, System.EventArgs e)
		{
			//创建数据库连接
			SqlConnection myConnection = new SqlConnection( ConfigurationSettings.AppSettings ["ConnectionString"]);
			myConnection.Open(); //打开数据库连接

			//获取电子邮件地址,并去掉单引号,空格
			string sEmail=txtEmail.Text.Replace("'","").Trim();

			//从newsletters表中查看此邮件是否已经订阅
			string strCount="select Email from newsletters where Email='"+sEmail +"'";
			//创建SQL命令。
			SqlCommand myComm= new SqlCommand(strCount,myConnection);
			//执行strCount语句,获得SqlDataReader。
			SqlDataReader dr=myComm.ExecuteReader();
			if (dr.Read())
			{
				//关闭SqlDataReader
				dr.Close();
				//关闭数据库连接
				myConnection.Close();
				Response.Write("您已经订阅过ASP酷电子杂志!<br>");
				Response.End();
			}
			dr.Close();

            //向数据库中增加订阅电子杂志的电子邮件的SQL语句
			string strSQL="insert into newsletters(Email) values('"+sEmail+"')";
			SqlCommand myComm2=new SqlCommand(strSQL,myConnection);
			try
			{
				myComm2.ExecuteNonQuery();
				Response.Write("恭喜您,您已经成功订阅了ASP酷电子杂志。");
			}
			catch
			{
				Response.Write("订阅电子邮件失败,请稍后再试,如果反复失败,请与aspcool8-web@yahoo.com.cn联系。");
			}
			finally
			{
				//关闭数据库连接
				myConnection.Close();
			}
			Response.End();
		}

		private void btnUnsubscribe_Click(object sender, System.EventArgs e)
		{
			//创建数据库连接
			SqlConnection myConnection = new SqlConnection( ConfigurationSettings.AppSettings ["ConnectionString"]);
			myConnection.Open(); //打开数据库连接

			//获取电子邮件地址,并去掉单引号,空格
			string sEmail=txtEmail.Text.Replace("'","").Trim();

			//从newsletters表中查看此邮件是否已经订阅
			string strCount="select Email from newsletters where Email='"+sEmail +"'";
			//创建SQL命令。
			SqlCommand myComm= new SqlCommand(strCount,myConnection);
			//执行strCount语句,获得SqlDataReader。
			SqlDataReader dr=myComm.ExecuteReader();
			if (!dr.Read())
			{
				//关闭SqlDataReader
				dr.Close();
				//关闭数据库连接
				myConnection.Close();
				Response.Write("您还未订阅ASP酷电子杂志!<br>");
				Response.End();
			}
			dr.Close();

			//从数据库中删除退订电子杂志的电子邮件的SQL语句
			string strSQL="delete from newsletters where Email='"+sEmail+"'";
			SqlCommand myComm2=new SqlCommand(strSQL,myConnection);
			try
			{
				myComm2.ExecuteNonQuery();
				Response.Write("您已经退订了ASP酷电子杂志。");				
			}
			catch
			{
				Response.Write("退订电子邮件失败,请稍后再试,如果反复失败,请与aspcool8-web@yahoo.com.cn联系。");
			}
			finally
			{		
				//关闭数据库连接
				myConnection.Close();
			}
			Response.End();
		}
	}
}

⌨️ 快捷键说明

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