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

📄 productshow.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 web.Code;

namespace web.Index
{
	/// <summary>
	/// ProdectShow 的摘要说明。
	/// </summary>
	public partial class ProdectShow : System.Web.UI.Page
	{

		protected GoodsDAO goodsDAO = new GoodsDAO();
		protected int pagesize = 8, pageindex;
		protected string category = null, subcategory = null;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			Trace.Warn("Page_LoadBegin","Timer1:Begin");
			if(!Page.IsPostBack)
			{
				if( Request.Params["CategoryId"]!=null&&Request.Params["SubCategoryId"]!=null )
				{
					category = Request.Params["CategoryId"].ToString();
					subcategory = Request.Params["SubCategoryId"].ToString();	
				}
				else if( Request.Params["CategoryId"]!=null )
				{
					category = Request.Params["CategoryId"].ToString();
				}
				else if( Request.Params["SubCategoryId"]!=null )
				{
					subcategory = Request.Params["SubCategoryId"].ToString();
				}
				if( subcategory!= null )
				{
					PageNavigate1.RecordsCount = goodsDAO.getGoodsNumberBySubCategory( subcategory );
				}
				else if( category!= null )
				{
					PageNavigate1.RecordsCount = goodsDAO.getGoodsNumberByCategory( category );
				}
				else
				{
					PageNavigate1.RecordsCount = goodsDAO.getGoodsNumber();
				}
				if( Request.Params["PageIndex"] == null || Request.Params["PageIndex"] == "" )
				{
					pageindex = 0;
				}
				else
				{
					pageindex = Convert.ToInt32( Request.Params["PageIndex"].ToString() );
				}
				PageNavigate1.PageSize = pagesize;
				PageNavigate1.PageIndex = pageindex;
				
				BindData();
				Trace.Warn("Page_LoadEnd","Timer4:End");
			}
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{   
			this.DataGrid2.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid2_ItemCommand);
			this.DataGrid2.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid2_ItemDataBound);
			this.PageNavigate1.PageNumberDataBound += new Thinksea.WebControls.PageNavigate.PageNavigate.PageNumberEventHandler(this.PageNavigate1_PageNumberDataBound);

		}
		#endregion

		private void BindData()
		{
			Trace.Warn("DataBindBegin","Timer2:Begin");
			DataSet tmpDataSet = new DataSet();
			if( Request.Params["SubCategoryId"]!=null )
			{
				int id = Convert.ToInt32( Request.Params["SubCategoryId"].ToString() );
				tmpDataSet = goodsDAO.getGoodsBySubCategory(pagesize,pageindex+1,id);
			}
			else if( Request.Params["CategoryId"]!=null )
			{
				int id = Convert.ToInt32( Request.Params["CategoryId"].ToString() );
				tmpDataSet = goodsDAO.getGoods(pagesize,pageindex+1,id);
			}
			else
			{
				tmpDataSet = goodsDAO.getGoods(pagesize,pageindex+1);
			}
			DataGrid2.DataSource = tmpDataSet.Tables[0];
			DataGrid2.DataBind();
			Trace.Warn("DataBindEnd","Timer3:End");
		}

		private void DataGrid2_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			Trace.Warn("DataBindBegin","Timer:Begin");
			if(e.CommandName == "buy")
			{
				if( Session["LoginName"] == null)
				{
					Response.Redirect("../Login.aspx?Return=" + Request.Url.ToString());
				}
				else
				{
					CustomerDAO customerDAO = new CustomerDAO();
					int userId = customerDAO.getUserId( Session["LoginName"].ToString() );
					if(e.Item.ItemType   ==   ListItemType.AlternatingItem  ||   e.Item.ItemType   ==   ListItemType.Item)   
					{   
						Label ItemId = (Label)e.Item.FindControl("idRecord");
						int goodsId = Convert.ToInt32( ItemId.Text.ToString() );
						goodsDAO.inputCar(goodsId,userId);
						Response.Redirect("../Customer/Car.aspx?Return="+Request.Url.ToString());
					}
				}
			}
			Trace.Warn("DataBindEnd","Timer:End");
		}

		private void PageNavigate1_PageNumberDataBound(object source, Thinksea.WebControls.PageNavigate.PageNumberEventArgs e)
		{
			if( category!=null && subcategory!= null )
			{
				e.PageNumberControl.NavigateUrl = "ProductShow.aspx?CategoryId=" + category + "&SubCategoryId=" + subcategory +"&PageIndex=" + e.PageNumber.ToString();
			}
			else if( category!=null )
			{
				e.PageNumberControl.NavigateUrl = "ProductShow.aspx?CategoryId=" + category + "&PageIndex=" + e.PageNumber.ToString();
			}
			else if( subcategory!=null )
			{
				e.PageNumberControl.NavigateUrl = "ProductShow.aspx?SubCategoryId=" + subcategory +"&PageIndex=" + e.PageNumber.ToString();
			}
			else
			{
				e.PageNumberControl.NavigateUrl = "ProductShow.aspx?PageIndex=" + e.PageNumber.ToString();
			}
		}

		private void DataGrid2_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if (e.Item.ItemType == ListItemType.Item ||e.Item.ItemType == ListItemType.AlternatingItem)
			{
				e.Item.Attributes.Add("onmouseover","this.style.backgroundColor='#cccccc';this.style.color='buttontext';this.style.cursor='default';");
				e.Item.Attributes.Add("onmouseout","this.style.backgroundColor='';this.style.color='';");
			}
		}

	}
}

⌨️ 快捷键说明

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