product_display.aspx.cs
来自「b to b 模式 电子商务系统」· CS 代码 · 共 181 行
CS
181 行
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.Configuration;
using System.Data.SqlClient;
namespace B2Bsite
{
/// <summary>
/// 商品详细信息显示
/// </summary>
public class product_display : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
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.Label Label5;
protected System.Web.UI.WebControls.Label Label6;
protected System.Web.UI.HtmlControls.HtmlImage IMG1;
public string ProductID;
public string ProductName;//产品名称
public string ProductPicture;//图片
public string ProductPrice;//当前价格
public string ProductQuantity;//产品数量
public string ProudctBegin;//上架时间
public string ProductEnd;//结束时间
TimeSpan ProductSpare;//所剩时间
public string ProductAddress;//所在地
public string ProductPost;//运费支付
public string ProductFax;
public string productfax;
public string ProductDetail;//商品详情
public string apper;//显示日期
DateTime dt1;
DateTime dt2;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label8;
DateTime dt;
public string strUserName="";
protected System.Web.UI.WebControls.Label daohang;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
public string shopID="";
public String strDaohang =""; //导航条
public string strTypeID=""; //类别ID
private void Page_Load(object sender, System.EventArgs e)
{
if( !IsPostBack)
{
ProductID = Request.QueryString["id"].ToString();
dt=DateTime.Now.Date;
SqlConnection connection=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
string sql="select * from Products where ProductState=0 and ProductId="+ProductID; //数据库连接字符串
SqlCommand command=new SqlCommand(sql,connection);//构件执行数据命令
connection.Open();
SqlDataReader dr=command.ExecuteReader();//保存从数据库里面返回的一条记录
if(dr.Read())
{
IMG1.Src = "showProductPicture.aspx?id=" + dr["ProductId"].ToString();
strTypeID = dr["ProductType"].ToString();
ProductName=dr["ProductName"].ToString();
ProductPicture=dr["ProductPicture"].ToString();
ProductPrice=dr["ProductPrice"].ToString();
ProductQuantity=dr["ProductQuantity"].ToString();
ProudctBegin=dr["ProductStart"].ToString();
ProductEnd=dr["ProductLeft"].ToString();
//dt1=ProudctBegin;
dt1=Convert.ToDateTime(ProudctBegin);
ProudctBegin=dt1.ToLongTimeString();
dt2=dt1.AddDays(14);
System.DateTime s=DateTime.Now;
ProductSpare=dt2-s;
apper=ProductSpare.Days.ToString()+"天"+ProductSpare.Hours.ToString()+"小时"+ProductSpare.Minutes.ToString()+"分"+ProductSpare.Seconds.ToString()+"秒";
ProductAddress=dr["ProductAddress"].ToString();
ProductPost=dr["ProductPost"].ToString();
ProductFax=dr["ProductFax"].ToString();
ProductDetail=dr["ProductDetail"].ToString();
strUserName = dr["UserName"].ToString ();
Label1.Text=ProductPrice;
Label2.Text=ProductQuantity;
Label3.Text=apper;
Label4.Text=ProductAddress;
Label5.Text="平邮:"+ProductPost+"元 "+"快递:"+ ProductFax+"元";
Label6.Text=ProductName;
Label8.Text = strUserName;
}
//
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
string sql2="select * from DianPuDetail where DianPuUser='"+strUserName+"'";
SqlCommand command2=new SqlCommand(sql2,conn);
conn.Open();
SqlDataReader dr2=command2.ExecuteReader();
if( dr2.Read() )
{
shopID = dr2["DianPuId"].ToString();
}
dr2.Close();
conn.Close();
//导航条
InitDaohang(strDaohang,strTypeID);
daohang.Text =strDaohang;
}
}
private void InitDaohang(string strTmp,string parentId)//初始化导航条
{
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);
String sql="SELECT * FROM PType where category_ID=" + parentId;
SqlCommand command=new SqlCommand(sql,conn);
conn.Open();
SqlDataReader dr=command.ExecuteReader();
if(dr.Read())
{
InitDaohang(strTmp,dr["parentId"].ToString());
strTmp += " >> ";
strTmp += "<a href ='productList.aspx?categoryid=";
strTmp += dr["category_ID"].ToString();
strTmp += "'>";
strTmp += dr["category_name"].ToString();
strTmp += "</a>";
strDaohang += strTmp;
}
dr.Close();
conn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?