日期:2014-05-17 浏览次数:20511 次
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text; using System.Data.SqlClient; public partial class ShoppingCart : System.Web.UI.Page { public int goods_id = 0; public int ProdCount = 0; public int sum = 0; DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { HttpCookie cookie = Request.Cookies["UserInfo"]; if (null == cookie) { Response.Write("<script>location.href='login.aspx'</script>"); Response.End(); } if (Request.QueryString["goods_id"] != null || Request.QueryString["goods_id"] != "") { goods_id = Convert.ToInt32(Request.QueryString["goods_id"]); } if (Request.QueryString["ProdCount"] != null || Request.QueryString["ProdCount"] != "") { ProdCount = Convert.ToInt32(Request.QueryString["ProdCount"]); } DataTable newDT = new DataTable("CartTable"); ds.Tables.Add(newDT); DataColumn newDC; newDC = new DataColumn("ProdID", System.Type.GetType("System.Int32")); ds.Tables["CartTable"].Columns.Add(newDC); newDC = new DataColumn("ProdCount", System.Type.GetType("System.Int32")); newDC.DefaultValue = 2; ds.Tables["CartTable"].Columns.Add(newDC); newDC = new DataColumn("ProName", System.Type.GetType("System.String")); ds.Tables["CartTable"].Columns.Add(newDC); newDC = new DataColumn("SalePrice", System.Type.GetType("System.Double")); ds.Tables["CartTable"].Columns.Add(newDC); newDC = new DataColumn("MarketPrice", System.Type.GetType("System.Double")); ds.Tables["CartTable"].Columns.Add(newDC); Session["myCartTable"] = ds; StringBuilder strSqlString = new StringBuilder(); strSqlString.Append("select "); strSqlString.Append("pro_name, "); strSqlString.Append("pro_sale_price, "); strSqlString.Append("pro_market_price "); strSqlString.Append("from "); strSqlString.Append("tb_products "); strSqlString.Append("where "); strSqlString.Append("pro_id = " + goods_id); DataSet dss = SqlHelper.GetDataSet(SqlHelper.ConnectionString, CommandType.Text, strSqlString.ToString(), null); if (goods_id > 0) { if (dss.Tables[0].Rows.Count > 0) { DataRow dr = newDT.NewRow(); dr["ProdID"] = goods_id; dr["ProdCount"] = ProdCount; dr["ProName"] = dss.Tables[0].Rows[0]["pro_name"]; dr["SalePrice"] = dss.Tables[0].Rows[0]["pro_sale_price"]; dr["MarketPrice"] = Convert.ToDouble(dss.Tables[0].Rows[0]["pro_sale_price"]) * ProdCount; newDT.Rows.Add(dr); } } if (ds.Tables[0].Rows.Count > 0) { for (i