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

📄 register.aspx.cs

📁 一个手机电子商务网站 包含物品展示
💻 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.OleDb;
using System.Configuration;
using System.Web.Security;

namespace MobileShop
{
	/// <summary>
	/// Register 的摘要说明。
	/// </summary>
	public class Register : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.TextBox txtAccount;
		protected System.Web.UI.WebControls.TextBox txtPassword;
		protected System.Web.UI.WebControls.TextBox txtEmail;
		protected System.Web.UI.WebControls.TextBox txtPasswordEnsure;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.RequiredFieldValidator valAccount;
		protected System.Web.UI.WebControls.RequiredFieldValidator valPassword;
		protected System.Web.UI.WebControls.CompareValidator cvalPassword;
		protected System.Web.UI.WebControls.RegularExpressionValidator rvalAccount;
		protected System.Web.UI.WebControls.RegularExpressionValidator rvalPassword;
		protected System.Web.UI.WebControls.RegularExpressionValidator rvalEmail;
		protected System.Web.UI.WebControls.RequiredFieldValidator valEmail;
		protected System.Web.UI.WebControls.Button btnSubmit;
		protected System.Web.UI.WebControls.Button btnReset;
		protected System.Web.UI.WebControls.RequiredFieldValidator valFirstName;
		protected System.Web.UI.WebControls.TextBox txtFirstName;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.RequiredFieldValidator valLastName;
		protected System.Web.UI.WebControls.TextBox txtLastName;
		protected System.Web.UI.WebControls.Label Label8;
		protected System.Web.UI.WebControls.Label Label11;
		protected System.Web.UI.WebControls.RequiredFieldValidator valAddress1;
		protected System.Web.UI.WebControls.TextBox txtAddress2;
		protected System.Web.UI.WebControls.TextBox txtAddress1;
		protected System.Web.UI.WebControls.Label Label9;
		protected System.Web.UI.WebControls.RequiredFieldValidator valPostalCode;
		protected System.Web.UI.WebControls.TextBox txtPostalCode;
		protected System.Web.UI.WebControls.Label Label10;
		protected System.Web.UI.WebControls.Label Label12;
		protected System.Web.UI.WebControls.Label Label13;
		protected System.Web.UI.WebControls.TextBox txtTelephoneNumber;
		protected System.Web.UI.WebControls.Label Label14;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.RegularExpressionValidator rvalTelephoneNunber;
		protected System.Web.UI.HtmlControls.HtmlGenericControl FONT1;
		protected System.Web.UI.WebControls.RegularExpressionValidator rvalPostalCode;
		protected System.Web.UI.WebControls.DropDownList dlistState;
		protected System.Web.UI.WebControls.DropDownList dlistCountry;
		protected System.Web.UI.WebControls.RequiredFieldValidator valCity;
		protected System.Web.UI.WebControls.TextBox txtCity;
		protected System.Web.UI.WebControls.Label Label15;
		protected System.Web.UI.WebControls.Label Label5;
		private System.Exception duplicateAccount = new Exception("用户名已存在,请更换换后重试");
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!IsPostBack)
			{
				DropDownListBind();
			}

		}

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

		}
		#endregion

		private void btnReset_Click(object sender, System.EventArgs e)
		{
			ClearTextBox();
		}
		private void ClearTextBox()
		{
			txtAccount.Text="";
			txtAddress1.Text = "";
			txtAddress2.Text = "";
			txtEmail.Text = "";
			txtFirstName.Text = "";
			txtLastName.Text = "";
			txtPostalCode.Text = "";
			txtTelephoneNumber.Text = "";
		}

		private void btnSubmit_Click(object sender, System.EventArgs e)
		{	
			string ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
			ConnectionString += Server.MapPath("MobileShop.mdb");
			OleDbConnection conn = new OleDbConnection(ConnectionString);

			OleDbCommand cmd;
			try
			{
				cmd = new OleDbCommand("select Account From UserInfo", conn);
				conn.Open();

				OleDbDataReader dr = cmd.ExecuteReader();
				while(dr.Read())
				{
					if(dr.GetString(0) == txtAccount.Text)
					{
						dr.Close();
						throw duplicateAccount;
					}
				}
				dr.Close();
						
				string InsertSqlString = "Insert into UserInfo (FirstName,LastName,Account,Pwd,Addr1,Addr2,Email,City,PostalCode,State,TelephoneNumber,IsAdmin) values ('"
					+ txtFirstName.Text +  "','" 
					+ txtLastName.Text + "','" 
					+ txtAccount.Text + "','" 
					+ txtPassword.Text + "','"
					+ txtAddress1.Text + "','"
					+ txtAddress2.Text + "','"
					+ txtEmail.Text + "','"
					+ txtCity.Text + "','"
					+ txtPostalCode.Text + "','"
					+ dlistState.SelectedItem.Text + "','"
					//+ dlistCountry.SelectedItem.Text +"','"
					+ txtTelephoneNumber.Text;
				if(Request.QueryString["IsAdmin"] != null)
				{
					InsertSqlString += "'," + Request.QueryString["IsAdmin"] + ")";
				}
				else
				{
					InsertSqlString += "'," + false + ")";
				}

				cmd = new OleDbCommand(InsertSqlString, conn);
					

				cmd.ExecuteNonQuery();

				//HttpCookie customerCookie = new HttpCookie("CustomerID", txtAccount.Text);
				
				//Response.Cookies.Add(customerCookie);
				if(Request.QueryString["IsAdmin"] != null)
				{
					Response.Redirect("Administrators.aspx", false);
				}
				else
				{
					Session.Add("CustomerID", txtAccount.Text);
					Session.Timeout=30;
					Response.Redirect("RegisterSuccessed.aspx?ID=" + txtAccount.Text, false);
				}
				
				
			}
			catch(Exception err)
			{
				MessageBox(err.Message);
			}
			finally
			{
				conn.Close();
				
			}
		}
			public   void   MessageBox(string   strMessage)   
			{   
				Response.Write("<"+"SCRIPT   language=javascript>");   
				Response.Write("alert(\""+strMessage+"\");");   
				Response.Write("<"+"/SCRIPT>\n");   
			}
		public void DropDownListBind()
		{
			string ConnectionString = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=";
			ConnectionString += Server.MapPath("MobileShop.mdb");
			OleDbConnection conn = new OleDbConnection(ConnectionString);

			OleDbCommand cmd = new OleDbCommand("Select name from Province", conn);

			conn.Open();

			try
			{
				OleDbDataReader dr = cmd.ExecuteReader();

				while(dr.Read())
				{
					ListItem ls = new ListItem(dr.GetString(0), dr.GetString(0));
					this.dlistState.Items.Add(ls);
				}
				dr.Close();
			}
			catch(Exception err)
			{
				Response.Write(err.Message);
			}
			finally
			{
				conn.Close();
			}
		}
	}
}

⌨️ 快捷键说明

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