首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

小弟我又一段购物车的代码,可是商品如何都添加不进去,也没有报错,麻烦帮小弟我看看,小弟我贴上代码

2012-04-21 
我又一段购物车的代码,可是商品怎么都添加不进去,也没有报错,麻烦帮我看看,我贴上代码using Systemusing

我又一段购物车的代码,可是商品怎么都添加不进去,也没有报错,麻烦帮我看看,我贴上代码
using System;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Security;
using System.Web.UI.HtmlControls;


public partial class fufei_money_1 : System.Web.UI.Page
{
  int AddProID;
  protected void Page_Load(object sender, EventArgs e)
  {
  int AddProID = Convert.ToInt32(Request.QueryString["id"].ToString());
  if (!IsPostBack)
  {
  //if (Request.QueryString["mode"] == "view")
  //{
  // ViewShoppingCart();
  // Caculator();
  //}
  //if (Request.QueryString["id"] != null || Request.QueryString["id"] != "")
  //{
   
  UpdateShoppingCart();
  Caculator();
  //}
  }
  }
   
  //创建购物车
  public void CreateCartTable()
  {
  int AddProID = Convert.ToInt32(Request.QueryString["id"].ToString());
  DataSet ds = new DataSet();
  DataTable newDT = new DataTable("CartTable");
  ds.Tables.Add(newDT);
  DataColumn newdc;
  newdc = new DataColumn("Goods_number", System.Type.GetType("System.String"));
  ds.Tables["CartTable"].Columns.Add(newdc);
  newdc = new DataColumn("ImgUrl", System.Type.GetType("System.String"));
  ds.Tables["CartTable"].Columns.Add(newdc);
  newdc = new DataColumn("original_price", System.Type.GetType("System.String"));
  ds.Tables["CartTable"].Columns.Add(newdc);
  newdc = new DataColumn("Present_price", System.Type.GetType("System.String"));
  ds.Tables["CartTable"].Columns.Add(newdc);
  newdc = new DataColumn("Total_Goods", System.Type.GetType("System.String"));
  newdc.DefaultValue = 1;
  ds.Tables["CartTable"].Columns.Add(newdc);
  newdc = new DataColumn("Total_Price", System.Type.GetType("System.Double"));
  ds.Tables["CartTable"].Columns.Add(newdc);
  Session["myCartTable"] = newDT;
  GridView1. DataSource = ds.Tables["CartTable"].DefaultView;
  GridView1. DataBind();
  }

  public void UpdateShoppingCart()
  {
  if (Session["myCartTable"] == null)
  {
  CreateCartTable();
  WriteShoppingCart();
  }
  else
  {
  WriteShoppingCart();
  }
  }
  //查看购物车
  public void ViewShoppingCart()
  {
  if (Session["myCartTable"] != null)
  {
  DataTable viewTable = new DataTable("nowCartTable");
  viewTable = (DataTable)Session["myCartTable"];
  GridView1.DataBind();
  Caculator();
  }
  }

  public void WriteShoppingCart()


  {
  if (Request.QueryString ["mode"]!= "view")
  {
  DataTable nowTable = new DataTable("nowCartTable");
  nowTable = (DataTable)Session["myCartTable"];
  int pn = nowTable.Rows.Count;
  int i = 0;
  bool hasone = false;
  int nowProdId;
  while (i<pn && !hasone )
  {nowProdId =Int32.Parse (nowTable .Rows [i][0].ToString ());
  if (nowProdId ==AddProID)
  {
  hasone =true ;
  }
  else 
  {
  i++;
  }
  if (hasone )
  {
  DataRow oldDR;
  oldDR = nowTable .Rows [i];
  oldDR ["Total_Goods"]=Int32.Parse (oldDR ["Total_Goods"].ToString ())+1;
  oldDR ["Total_Price"] =Int32.Parse(oldDR ["Total_Goods"].ToString ())*Double.Parse (oldDR ["Present_price"].ToString ());

  }
  else 
  {
  DataRow newDR;
  double unitp;
  Based newbd = new Based ();
  SqlConnection con = newbd.createCon();
  con.Open();
  string sql_str="select * from goods where Goods_number="+AddProID;
  SqlDataAdapter myAdapter = new SqlDataAdapter (sql_str ,con);
  DataSet ds = new DataSet();
  myAdapter .Fill (ds,"AddP");
  newDR=nowTable.NewRow ();
  newDR[0]=AddProID ;
  newDR[1]=ds.Tables ["AddP"].Rows [0]["imgurl"].ToString ();
  newDR[2]=Double.Parse (ds.Tables ["AddP"].Rows [0]["original_price"].ToString ());
  unitp = Double.Parse (ds.Tables ["AddP"].Rows [0]["Present_price"].ToString ());
  newDR[3] =unitp ;
  newDR [4]="1";
  newDR[5] = unitp;
  nowTable .Rows .Add (newDR );
  con.Close ();

  }
  GridView1.DataSource = nowTable.DefaultView;
  GridView1.DataBind();
  Session ["myCartTable"]=nowTable ;
  }

  }
  }
  public void Caculator()
  {
  if (Session["myCarTable"] != null)
  {
  int h;
  Double TotalPri;
  TotalPri = 0;
  DataTable nowTable3 = new DataTable("nowCartTable3");
  nowTable3 = (DataTable)Session["myCartTable"];
  if (nowTable3.Rows.Count > 0)
  {
  for (h = 0; h <= nowTable3.Rows.Count - 1; h++)
  {
  TotalPri = TotalPri + Int32.Parse(nowTable3.Rows[h][5].ToString());

  }
  label.Text = "总金额:" + TotalPri.ToString() + "元";
  }
  }
  }


 <asp:DataList ID="DataList1" runat="server" DataKeyField="id" Width="948px">


  <ItemTemplate>
  <div class="fufei_mo">
  <table align="center" cellspacing="0" class="style1">
  <tr>
  <td align="center" valign="middle" class="style3">
  <asp:Image ID="Image3" runat="server" Width="55px" Height="55px" 
  ImageUrl='<%# Eval("Imgurl") %>' /></td>
  <td align="center" valign="middle" class="style4">
  <asp:Label ID="Label1" runat="server" Text='<%# Eval("Goods_name") %>'></asp:Label></td>
  <td align="center" valign="middle" class="style5">
  ¥<asp:Label ID="Label2" runat="server" Text='<%# Eval("original_price") %>'></asp:Label></td>
  <td align="center" class="style8" valign="middle">
  ¥<asp:Label ID="Label3" runat="server" Text='<%# Eval("Present_price") %>'></asp:Label></td>
  <td align="center" valign="middle" class="style7">
  <asp:TextBox ID="TextBox1" runat="server" Width="50px" Text='<%# Eval("Total_Goods") %>'></asp:TextBox></td>
  <td align="center" valign="middle" class="style9">
  ¥<asp:Label ID="Label4" runat="server" Text='<%# Eval("Total_Price") %>'></asp:Label></td>
  <td align="center" valign="middle">
  添加到收藏夹
  <br />
  <br />
  <asp:Button ID="Button1" runat="server" Text="删除" BorderColor="#FF6699" 
  BorderWidth="1px" /> </td>
  </tr>
  </table>
  </div>
  </ItemTemplate>
  </asp:DataList>
   
  <asp:Label ID="label" runat="server" Text="Label"></asp:Label>

[解决办法]
好长,设置断点跟踪一下吧。

热点排行