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

📄 controladdress.ascx.cs

📁 PetShop实现的是一个网上购物的系统功能
💻 CS
字号:
namespace PetShop.Web.Inc {
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using System.Collections;
	using System.Diagnostics;
	using System.Data.SqlClient;
	using PetShop.Components;
	
	/// <summary>
	///	Displays editable address information for current user. 
	///	Props:
	///	 UserDefaultValues - If fields should be initialized with values from database.
	/// </summary>
	public partial  class ControlAddress : System.Web.UI.UserControl {

		// public props
		public bool UseDefaultValues=true;
		
		/// <summary>
		public ControlAddress() {
			this.Init += new System.EventHandler(Page_Init);
		}

		protected void Page_Load(object sender, System.EventArgs e) {
			if (!IsPostBack) {
				// init dropdowns
				listState.Items.Add(new ListItem("California"));
				listState.Items.Add(new ListItem("New York"));
				listState.Items.Add(new ListItem("Texas"));

				listCountry.Items.Add(new ListItem("USA"));
				listCountry.Items.Add(new ListItem("Canada"));
				listCountry.Items.Add(new ListItem("Japan"));
				
				// initialize the values if using default values
				if (UseDefaultValues) {
					// determine who is logged in
					Debug.Assert(Request.Cookies["CustomerID"] != null);
					string userID = (string)Request.Cookies["CustomerID"].Value;

					// get user info
					Customer cust = new Customer();
					//SqlDataReader data = cust.GetAddress(userID);

					Customer.CustomerAddress customerAddress = cust.GetAddress(userID);

					//data.Read();
					
					// init values					
					txtFirstName.Text = customerAddress.firstname;
					txtLastName.Text = customerAddress.lastname;
					txtAddress1.Text = customerAddress.addr1;
					txtAddress2.Text = customerAddress.addr2;
					txtCity.Text = customerAddress.city;
					txtPostalCode.Text = customerAddress.zip;
					txtTelephoneNumber.Text = customerAddress.phone;
					SelectListItem(listState, customerAddress.state);
					SelectListItem(listCountry, customerAddress.country);

					/*					 
						txtFirstName.Text = (string)data["firstname"];
						txtLastName.Text = (string)data["lastname"];
						txtAddress1.Text = (string)data["addr1"];
						txtAddress2.Text = (string)data["addr2"];
						txtCity.Text = (string)data["city"];
						txtPostalCode.Text = (string)data["zip"];
						txtTelephoneNumber.Text = (string)data["phone"];
						SelectListItem(listState, (string)data["state"]);
						SelectListItem(listCountry, (string)data["country"]);
						
						// done with datareader
						//data.Close();
					*/
				}
			}
		}

		protected void Page_Init(object sender, EventArgs e) {
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
		}

		/// <summary>
		/// Saves or updates address information for current
		///	user (session).
		/// </summary>
		/// <param name="adr">Hashtable to save info into.</param>
		/// <param name="prefix">Prefix of key that is used when saving info.</param>
		public void SaveInfo(Hashtable adr, string prefix) {
			adr[prefix + "_FirstName"] = txtFirstName.Text.Trim();
			adr[prefix + "_LastName"] = txtLastName.Text.Trim();
			adr[prefix + "_Address1"] = txtAddress1.Text.Trim();
			adr[prefix + "_Address2"] = txtAddress2.Text.Trim();
			adr[prefix + "_City"] = txtCity.Text.Trim();
			adr[prefix + "_State"] = listState.SelectedItem.Text.Trim();
			adr[prefix + "_PostalCode"] = txtPostalCode.Text.Trim();
			adr[prefix + "_Country"] =  listCountry.SelectedItem.Text.Trim();
			adr[prefix + "_Number"] = txtTelephoneNumber.Text.Trim();
		}

		// select specified item in dropdown list		
		private void SelectListItem(DropDownList list, string text) {
			try {
				list.Items.FindByText(text).Selected = true;
			}
			catch {
			}
		}

		public string GetFirstName
		{
			get
			{
				return txtFirstName.Text.Trim();
			}
			set
			{
				txtFirstName.Text=value;
			}
		}
		public string GetLastName
		{
			get
			{
				return txtLastName.Text.Trim();
			}
			set
			{
				txtLastName.Text=value;
			}
		}
		public string GetAddr1
		{
			get
			{
				return txtAddress1.Text.Trim();
			}
			set
			{
				txtAddress1.Text=value;
			}
		}
		public string GetAddr2
		{
			get
			{
				return txtAddress2.Text.Trim();
			}
			set
			{
				txtAddress2.Text=value;
			}
		}
		public string GetCity
		{
			get
			{
				return this.txtCity.Text.Trim();
			}
			set
			{
				this.txtCity.Text=value;
			}
		}
		public string  GetState
		{
			get
			{
				return this.listState.SelectedItem.Text;
			}
			set
			{
				this.listState.SelectedItem.Text=value;
			}
		}
		public string GetZip
		{
			get 
			{
				return this.txtPostalCode.Text;
			}
			set
			{
				value=this.txtPostalCode.Text;
			}
		}
		public string GetCountry
		{
			get
			{
				return this.listCountry.SelectedItem.Text;
			}
			set
			{
				value=this.listCountry.SelectedItem.Text;
			}
		}

		#region Web Form Designer generated code
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {

		}
		#endregion
	}
}

⌨️ 快捷键说明

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