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;namespace KJXY
{
/// <summary>
/// Shopping_Car 的摘要说明。
/// </summary>
public class Shopping_Car : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Button Button2;

private void Page_Load(object sender, System.EventArgs e)
{

} #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{    
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
this.Init += new System.EventHandler(this.Shopping_Car_Init); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
Response.Write("<Script language='JavaScript'>history.go(-2);</"+"Script>");
} private void Shopping_Car_Init(object sender, System.EventArgs e)
{
int quantity = 0;  //总数量
int total = 0;     //总价格
if(!IsPostBack)
{

if(Session["shopping"] == null)
{
Response.Write("<TABLE id='Table1' style='Z-INDEX: 103; LEFT: 50px; POSITION: absolute; TOP: 200px' borderColor='inactivecaptiontext'"+
"'cellSpacing='2' borderColorDark='inactivecaptiontext' cellPadding='1' width='456' borderColorLight='inactivecaptiontext' border='2'>");
Response.Write("<TR>");
Response.Write("<TD bgColor='inactivecaptiontext'></td>");
Response.Write("<TD bgColor='inactivecaptiontext'>");
Response.Write("产品名称");
Response.Write("</TD>");
Response.Write("<TD bgColor='inactivecaptiontext'>");
Response.Write("产品价格");
Response.Write("</TD>");
Response.Write("<TD bgColor='inactivecaptiontext'>");
Response.Write("产品数量");
Response.Write("</TD>");
Response.Write("</TR>");
Hashtable ht = new Hashtable();
Session["shopping"] = ht;
string product_name = Request["product_name"];
if(product_name != null && product_name != "")
{
if(!ht.Contains(product_name))
{
HPPcTableLogic hppct = new HPPcTableLogic();
HPPcTable hppc = hppct.ShowProduct_Name(product_name);
hppc.Num = 1;
ht[product_name] = hppc;
Session["shopping"] = ht;
}
if(ht != null)
{
HPPcTableLogic hppct = new HPPcTableLogic();
HPPcTable hppc = (HPPcTable)ht[product_name];
for(int i=0;i<ht.Count;i++)
{
if(hppc.Product_name != null && hppc.Product_name != "")
{
total = hppc.Price;
quantity = hppc.Num;
Response.Write("<TR>");
Response.Write("<TD><input type='checkbox' name='s' value='qwq'></TD>");
Response.Write("<TD>");
Response.Write(hppc.Product_name);
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write(hppc.Price);
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write("<INPUT type='text' value='1' size='3'>");
Response.Write("</TD>");
Response.Write("</TR>");
}
}
}
}
Response.Write("<TR>");
Response.Write("<TD  style='COLOR: #ff0066' colSpan='2'align='center'>");
Response.Write("合计");
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write(total);
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write(quantity);
Response.Write("</TD>");
Response.Write("</TR>");
Response.Write("</table>");
}
else
{
Response.Write("<TABLE id='Table1' style='Z-INDEX: 103; LEFT: 50px; POSITION: absolute; TOP: 200px' borderColor='inactivecaptiontext'"+
"'cellSpacing='2' borderColorDark='inactivecaptiontext' cellPadding='1' width='456' borderColorLight='inactivecaptiontext' border='2'>");
Response.Write("<TR>");
Response.Write("<TD bgColor='inactivecaptiontext'></td>");
Response.Write("<TD bgColor='inactivecaptiontext'>");
Response.Write("产品名称");
Response.Write("</TD>");
Response.Write("<TD bgColor='inactivecaptiontext'>");
Response.Write("产品价格");
Response.Write("</TD>");
Response.Write("<TD bgColor='inactivecaptiontext'>");
Response.Write("产品数量");
Response.Write("</TD>");
Response.Write("</TR>");
Hashtable ht = (Hashtable)Session["shopping"];
string product_name = Request["product_name"];
if(product_name != null && product_name != "")
{
if(!ht.Contains(product_name))
{
HPPcTableLogic hppct = new HPPcTableLogic();
HPPcTable hppc = hppct.ShowProduct_Name(product_name);
hppc.Num = 1;
ht[product_name] = hppc;
}
else
{
if(!IsPostBack)
{
HPPcTableLogic hppct = new HPPcTableLogic();
HPPcTable hppc = (HPPcTable)ht[product_name];
hppc.Num = hppc.Num+1;
ht[product_name] = hppc;
}
}
Session["shopping"] = ht;
if(ht != null)
{
IDictionaryEnumerator ide = ht.GetEnumerator();
while(ide.MoveNext())
{
HPPcTable hppc = (HPPcTable)ide.Value;

if(hppc.Product_name != null && hppc.Product_name != "")
{
total = total+(hppc.Price*hppc.Num);
quantity = quantity+hppc.Num;
Response.Write("<TR>");
Response.Write("<TD><input type='checkbox' name='s' value='qwq'></TD>");
Response.Write("<TD>");
Response.Write(hppc.Product_name);
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write(hppc.Price);
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write("<INPUT type='text' value='"+hppc.Num+"' size='3'>");
Response.Write("</TD>");
Response.Write("</TR>");
}
}
}
}
Response.Write("<TR>");
Response.Write("<TD  style='COLOR: #ff0066' colSpan='2'align='center'>");
Response.Write("合计");
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write(total);
Response.Write("</TD>");
Response.Write("<TD>");
Response.Write(quantity);
Response.Write("</TD>");
Response.Write("</TR>");
Response.Write("</table>");
}
}
}
}
}
每次刷新后,单个数量NUM都会自动+1,我看不出是为什么。请各位高手帮我找找哪里有错误,谢谢了~!