📄 productdisplay.aspx.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;
namespace SCard
{
/// <summary>
/// productDisplay 的摘要说明。
/// </summary>
public class productDisplay : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblDaohang;
protected System.Web.UI.WebControls.Repeater CRepeater;
protected System.Web.UI.WebControls.Repeater HotRepeater;
protected System.Web.UI.WebControls.Label lblPName;
protected System.Web.UI.WebControls.Label lblPFPrice;
protected System.Web.UI.WebControls.Label lblPNPrice;
public string strPID="-1";
public string strPName=string.Empty;
public string strPBewrite = "";//商品简介
public string strPUseMode = "";//使用说明
public string strPValidity = "";
protected System.Web.UI.WebControls.DropDownList ddlClass;
protected System.Web.UI.WebControls.TextBox txtSelect;
protected System.Web.UI.WebControls.Button btnSelect;//有效期
public string strBuy = "";//打印在线购买 或 没有存货
private void Page_Load(object sender, System.EventArgs e)
{
if( !IsPostBack )
{
if(Request.QueryString["id"]!=null)
{
string strID = Request.QueryString["id"].ToString();
strID = CleanString.htmlInputText( strID );
DBConn myDB = new DBConn();
string sql = "select * from products where PID=" + strID;
OleDbDataReader dr;
try
{
dr = myDB.getDataReader( sql );
}
catch
{
Response.Write("<script>");
Response.Write("alert('没有这个商品!!!');");
Response.Write("</script>");
Response.Redirect("index.aspx");
return;
}
if( dr.Read() )
{
ViewState["CID"] = dr["CID"].ToString();
}
else
{
Response.Write("<script>");
Response.Write("alert('没有这个商品!!!');");
Response.Write("</script>");
dr.Close();
myDB.Close();
Response.Redirect("index.aspx");
return;
}
dr.Close();
myDB.Close();
ViewState["ID"] = strID;
}
CData();
HData();
DHData();
PData();
setSelectClass();//绑定 类别选框
}
}
private void setSelectClass()//绑定 类别选框
{
DBConn myDB = new DBConn();
string mySql = "select CID,CName from Category order by CID desc";
ddlClass.DataSource = myDB.getDataReader( mySql );
ddlClass.DataTextField = "CName";
ddlClass.DataValueField = "CID";
ddlClass.DataBind();
myDB.Close();
ddlClass.Items.Insert(0,new ListItem("所有分类","-1"));
}
private void PData()//显示相应商品信息
{
string strID = ViewState["ID"].ToString();
DBConn myDB = new DBConn();
string sql = "select * from Products where PID=" + strID;
OleDbDataReader dr = myDB.getDataReader( sql );
if( dr.Read() )
{
strPID = dr["PID"].ToString();
lblPName.Text = dr["PName"].ToString();
strPName = lblPName.Text;//
lblPFPrice.Text = double.Parse(dr["PFPrice"].ToString()).ToString("f2");
lblPNPrice.Text = double.Parse(dr["PNPrice"].ToString()).ToString("f2");
strPBewrite = dr["PBewrite"].ToString();
strPUseMode = dr["PUseMode"].ToString();
strPValidity = dr["PValidity"].ToString();
string strPStock = dr["PStock"].ToString();
if( Int32.Parse(strPStock) > 0 )
{
strBuy = "<img src='images/car.gif'> [ <A target=_blank href='makeOrder.aspx?id=" + strPID + "'>在线购买</A> ]";
}
else
{
strBuy = "[ 没有存货 ]";
}
}
dr.Close();
myDB.Close();
}
private void CData()//分类列表绑定
{
DBConn myDB = new DBConn();
string sql = "select * from Category";
CRepeater.DataSource = myDB.getDataReader( sql );
CRepeater.DataBind();
myDB.Close();
}
private void DHData()//导航条设置
{
string strCID = ViewState["CID"].ToString();
if( ViewState["CID"] == null || ViewState["CID"].ToString() == String.Empty )
{
lblDaohang.Text = "所有商品";
}
else
{
DBConn myDB = new DBConn();
string sql = "select * from Category where CID=" + strCID;
OleDbDataReader dr = myDB.getDataReader( sql );
if( dr.Read() )
{
lblDaohang.Text = dr["CName"].ToString();
}
dr.Close();
myDB.Close();
}
//lblDaohang.Text += ;
}
private void HData()//分类对应的热销商品列表绑定
{
if( ViewState["CID"] == null || ViewState["CID"].ToString() == String.Empty )
{
DBConn myDB = new DBConn();
string sql = "SELECT TOP 10 * FROM Products WHERE PSellNum>0 ORDER BY PSellNum DESC,PID";
HotRepeater.DataSource = myDB.getDataReader( sql );
HotRepeater.DataBind();
myDB.Close();
}
else
{
string strCID = ViewState["CID"].ToString();
DBConn myDB = new DBConn();
string sql = "select top 10 * from Products where PSellNum>0 and CID=" + strCID + " order by PSellNum desc,PID";
HotRepeater.DataSource = myDB.getDataReader( sql );
HotRepeater.DataBind();
myDB.Close();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.btnSelect.Click += new System.EventHandler(this.btnSelect_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void btnSelect_Click(object sender, System.EventArgs e)
{
string strClass = ddlClass.SelectedValue;
string strText = Server.UrlEncode( txtSelect.Text );
Response.Redirect("Select.aspx?class=" + strClass + "&text=" + strText);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -