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

📄 shopping.aspx.cs

📁 网络营销软件的源代码
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace WebApplication8.firstPage
{
	/// <summary>
	/// shopping 的摘要说明。
	/// </summary>
	public class shopping : System.Web.UI.Page
	{
		protected System.Web.UI.HtmlControls.HtmlTableCell shop;
		SqlConnection connection;
		SqlCommand command = new SqlCommand();
		SqlDataAdapter adapter = new SqlDataAdapter();
		protected System.Web.UI.HtmlControls.HtmlTableCell totalProduct;
		protected System.Web.UI.HtmlControls.HtmlTableCell totalMoney;
		DataTable table;
		DataSet dataset;
		DataSet searchSet;
		protected System.Web.UI.WebControls.Button show;
		protected System.Web.UI.HtmlControls.HtmlInputText keyword;
		protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
		protected System.Web.UI.WebControls.DataGrid product;
		protected System.Web.UI.HtmlControls.HtmlTableCell list;
		protected System.Web.UI.WebControls.Label count;
		protected System.Web.UI.HtmlControls.HtmlTableCell ads;


		private void Page_Load(object sender, System.EventArgs e)
		{
			
	
			// 在此处放置用户代码以初始化页面
			if(Session["userName"]==null)
				Response.Redirect("../login.aspx");

			if(Session["type"].Equals("个人"))
				shop.InnerHtml = "<div align='center'><A href='shopping.aspx'><IMG height='29' src='images/shopping.gif' width='157' border='0'></A></div>";
			else if(Session["type"].Equals("企业"))
				shop.InnerHtml = "<div align='center'><A href='enterprise.aspx'><IMG height='29' src='images/shopping.gif' width='157' border='0'></A></div>";

			if(Session["type"].ToString().Equals("个人"))
				ads.Visible = false;

			count.Text = Application["count"].ToString();

			if(Session["cart"] == null)
			{
				ShoppingCart cart = new ShoppingCart();
				Session["cart"] = cart;
			}
			
			totalProduct.InnerHtml = "当前商品件数: <font color=#cc0000>"+((ShoppingCart)Session["cart"]).getItemCount()+"</font>";
			totalMoney.InnerHtml = "当前消费: <font color=#cc0000>"+((ShoppingCart)Session["cart"]).getTotalPrice()+"</font>";
			
			connection = new SqlConnection(Application["market"].ToString());
			command.Connection = connection;
			connection.Open();
			adapter.SelectCommand = command;
			dataset = new DataSet();
			
			if(keyword.Value.Length != 0)
				command.CommandText = "select * from Product where productName like '%"+keyword.Value+"%' or description like '%"+keyword.Value+"%'";
			else

				command.CommandText = "select productid,productName,price,description,studentNO from Product";
			adapter.Fill(dataset);

			table = dataset.Tables[0];
				
			product.DataSource = new DataView(table);
			product.DataBind();		

			Connection connection_ = new Connection(Application["market"].ToString());
			SqlDataReader reader = connection_.execute("select top 3 productName from AccountRecord order by id desc");
			string html="";
			while(reader.Read())
			{
				html += "> "+reader["productName"].ToString()+"</br>";
			}
			reader.Close();
			list.InnerHtml = html;
			
		}
		

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.show.Click += new System.EventHandler(this.show_Click);
			this.product.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.doCart);
			this.product.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.pageChange);
			this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		public void pageChange(object sender, DataGridPageChangedEventArgs e)
		{
			if(e==null)
				product.CurrentPageIndex = 0;
			else
				product.CurrentPageIndex = e.NewPageIndex;
			product.DataSource = new DataView(table);
			product.DataBind();
		}

		public void doCart(Object sender,DataGridCommandEventArgs e)
		{
			try{
				string id = e.Item.Cells[0].Text;
				string productName = e.Item.Cells[1].Text;
				string price = e.Item.Cells[2].Text;
				string description = e.Item.Cells[3].Text;
				string studentNO="";
				
				
				
				DataView record = (DataView)(product.DataSource);
				record.RowFilter = "productid='"+id+"'";	
				if(record.Count > 0)
				studentNO = record[0]["studentNO"].ToString();
				((ShoppingCart)Session["cart"]).insert(id,productName,price,description,studentNO);

				totalProduct.InnerHtml = "当前商品件数: <font color=#cc0000>"+((ShoppingCart)Session["cart"]).getItemCount()+"</font>";
				totalMoney.InnerHtml = "当前消费: <font color=#cc0000>"+((ShoppingCart)Session["cart"]).getTotalPrice()+"</font>";
			}
			catch(Exception o)
			{
			;	
			}
		}


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


		private void Submit1_ServerClick(object sender, System.EventArgs e)
		{
			searchSet = new DataSet();
			command.CommandText = "select * from Product where productName like '%"+keyword.Value+"%' or description like '%"+keyword.Value+"%'";
			adapter.Fill(searchSet);
			product.CurrentPageIndex = 0;
			product.DataSource = new DataView(searchSet.Tables[0]);
			product.DataBind();
		}


	}
}

⌨️ 快捷键说明

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