using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class GoodsShow : System.Web.UI.Page { string GoodsId; public DataTable GoodsInfo; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString.ToString()); protected void Page_Load(object sender, EventArgs e) { try { GoodsId = Request.QueryString["GoodsId"].ToString(); } catch { Response.Redirect("List.aspx"); } if (!IsPostBack) { GetGoodsinfo(); BindPic(); string sqlstr1 = "select pid from v3_merchandises where id = " + GoodsId; new common().count(Convert.ToInt32((int)new common().ExcuteReader(sqlstr1).Tables[0].Rows[0][0])); } } private void GetGoodsinfo() { string sqlstr = "select shangpin.pid as ID ,pic.FileName as FileName,shangpin.See_count as [count],shangpin.market_price_rmb as jiage1, shangpin.vip_price_rmb as jiage2," + " shangpin.trade_name_cn as name , shangpin.Buy_count as Buy,shangpin.MULU as Mulu, shangpin.Chubanshe" + " as chubanshe, shangpin.Chubanshijian as chubanshijian,shangpin.ISBN as isbn,shangpin.description_cn as description from v3_merchandises as shangpin left join " + " v3_Pic_path as pic on shangpin.pid = pic.pid where pic.Show=1 and shangpin.id =" + GoodsId; GoodsInfo = new common().ExcuteReader(sqlstr).Tables[0]; } public void BindPic() { string sqlstr = " select * from v3_Pic_path where pid = (select pid from v3_merchandises where id =" + GoodsId + ") and v3_Pic_path.Show !=1"; SqlDataAdapter sda = new SqlDataAdapter(sqlstr, con); DataSet ds = new DataSet(); sda.Fill(ds); this.Repeater1.DataSource = ds; this.Repeater1.DataBind(); } protected string GetGoodsPid() { string sqlstr = " select pid from v3_merchandises where id = " + GoodsId; return new common().ExcuteReader(sqlstr).Tables[0].Rows[0][0].ToString(); } protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string UserID = null; if (Session["member"] != null) { DataTable dt = (DataTable)Session["member"]; foreach (System.Data.DataRow row in dt.Rows) { UserID = row[0].ToString(); } string sqlExecuteScalar = "select * from v3_shoppingcar where Pid='" + GetGoodsPid() + "' and cid = '" + UserID + "'"; if (new common().ExecuteScalar(sqlExecuteScalar, null)) { string Update = " update v3_shoppingcar set amount = amount+" + Convert.ToInt32(buy_num.Text) + " where pid =" + GetGoodsPid() + " and cid = '" + UserID + "'"; if (new common().ExcuteNoneQuery(Update, null)) { Response.Redirect("shoppingcart.aspx?p=" + UserID); } } else { string sqlstr = " INSERT INTO v3_shoppingcar(CID,amount,adddate,Pid)VALUES('" + UserID + "','" + Convert.ToInt32(this.buy_num.Text) + "','" + DateTime.Now.ToLongTimeString() + "','" + GetGoodsPid() + "')"; if (new common().ExcuteNoneQuery(sqlstr, null)) { Response.Redirect("shoppingcart.aspx?p=" + UserID); } } } else { Response.Redirect("Login.aspx?ReturnUrl=" + Request.Url.ToString()); } } /// /// 加入购物车 /// /// /// protected void ImageButton2_Click(object sender, ImageClickEventArgs e) { string UserID = null; if (Session["member"] != null) { DataTable dt = (DataTable)Session["member"]; foreach (System.Data.DataRow row in dt.Rows) { UserID = row[0].ToString(); } string sqlExecuteScalar = "select * from v3_shoppingcar where Pid='" + GetGoodsPid() + "' and cid = '" + UserID + "'"; if (new common().ExecuteScalar(sqlExecuteScalar, null)) { string Update = " update v3_shoppingcar set amount = amount+" + Convert.ToInt32(buy_num.Text) + " where pid =" + GetGoodsPid() + " and cid = '" + UserID + "'"; if (new common().ExcuteNoneQuery(Update, null)) { PublicClass.AlertClass.Alert(this, "添加商品到购物车成功!"); GetGoodsinfo(); } } else { string sqlstr = " INSERT INTO v3_shoppingcar(CID,amount,adddate,Pid)VALUES('" + UserID + "','" + Convert.ToInt32(this.buy_num.Text) + "','" + DateTime.Now.ToLongTimeString() + "','" + GetGoodsPid() + "')"; if (new common().ExcuteNoneQuery(sqlstr, null)) { PublicClass.AlertClass.Alert(this, "添加商品到购物车成功!"); GetGoodsinfo(); } } } else { Response.Redirect("Login.aspx?ReturnUrl=" + Request.Url.ToString()); } } }