购物车代码求一个asp.net 购物车代码?

购物车代码  时间:2021-06-17  阅读:()

购物车的Java代码

import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator;

public class ShoppingCartManager { HashMap<String, String> hm=new HashMap<String, String>(); float totlePrice=0;

//添加book到购物车 public void addBook(String bookId,String bookQuantity){ if(hm.containsKey(bookId)){ int value=Integer.parseInt(hm.get(bookId)); value+=Integer.parseInt(bookQuantity); hm.put(bookId, value+""); }else{ hm.put(bookId, bookQuantity); } } //修改数量 public void updateQuantity(String bookId,String bookQuantity){ hm.put(bookId, bookQuantity); } //获取购物车的所有信息 并计算总价 public ArrayList<BookBean> getShoppingCart(){ ArrayList<BookBean> al=new ArrayList<BookBean>(); Iterator<String> i=hm.keySet().iterator(); String ids=""; BookTableManager btm=new BookTableManager(); while(i.hasNext()){ ids=ids+","+i.next(); } al= btm.selectByBookIds(ids); totlePrice=0; //清空总价,防止无限累计 for(int j=0;j<al.size();j++){ BookBean bb=al.get(j); totlePrice+=bb.getPrice()*Integer.parseInt(getQuantityById(bb.getBookId()+"")); } return al; } //获取总价 public float getTotlePrice(){ return totlePrice; } //根据ID获取数量 public String getQuantityById(String id){ String quantity=hm.get(id); return quantity; } //清空购物车 public void clear(){ hm.clear(); } //删除购物车中的一本书 public void deleteById(String id){ hm.remove(id); }

}

购物车页面布局原代码

public?class?MyShopCar?extends?HttpServlet?{?public?void?service(HttpServletRequest?request,?HttpServletResponse?response) throws?ServletException,?IOException?{ int?id=Integer.parseInt(request.getParameter("proID")); HttpSession?session=request.getSession(); HashMap?cars=(HashMap)session.getAttribute("cars");?类二:public?class?ShowCarServlet?extends?HttpServlet?{?public?void?service(HttpServletRequest?request,?HttpServletResponse?response) throws?ServletException,?IOException?{ List?list=new?ArrayList(); ProductDao?proDao=new?ProductDao(); HttpSession?session=request.getSession(); HashMap?map=(HashMap)session.getAttribute("cars"); Iterator?ator=map.keySet().iterator(); int?sums=0; while(ator.hasNext()) { Integer?id=(Integer)ator.next(); Integer?count=(Integer)map.get(id); Product?pro=proDao.getAllById(id); pro.setCount(count); sums+=pro.getSum(); list.add(pro); } request.setAttribute("list",?list); request.setAttribute("sums",?sums+""); request.getRequestDispatcher("myShopCar.jsp").forward(request,?response);?}} if(cars==null) { cars=new?HashMap(); } Integer?count?=?(Integer)cars.get(id); if(count==null) { cars.put(id,?1); }else { cars.put(id,?count+1); } session.setAttribute("cars",?cars); response.sendRedirect("ShowCarServlet"); }}

求一个asp.net 购物车代码?

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.Collections; public partial class AddCar : System.Web.UI.Page { ess db = new ess(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string id = Request.QueryString["id"].ToString();

if (Session["car"] != null) { Hashtable hash = Session["car"] as Hashtable; if (!hash.ContainsKey(id)) { hash.Add(id, 1); } else { hash[id] = int.Parse(hash[id].ToString()) + 1; } Session["car"] = hash; } else { Hashtable hash = new Hashtable(); hash.Add(id, 1); Session["car"] = hash; } Hashtable k = Session["car"] as Hashtable;

DataColumn dc0 = new DataColumn("id", typeof(string)); DataColumn dc1 = new DataColumn("商品名", typeof(string)); DataColumn dc2 = new DataColumn("价格", typeof(float)); DataColumn dc3 = new DataColumn("数量", typeof(int)); DataColumn dc4 = new DataColumn("总价格", typeof(float)); DataTable dt = new DataTable(); dt.Columns.Add(dc0); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); foreach (DictionaryEntry i in k) { //Response.Write(i.Key+" "+i.Value+"<br>"); DataRow dr = dt.NewRow(); DataSet ds = db.QueryDataSet("select * from product where p_id=" + i.Key); dr["id"] = ds.Tables[0].Rows[0]["p_id"].ToString(); dr["商品名"] = ds.Tables[0].Rows[0]["p_name"].ToString(); dr["价格"] = ds.Tables[0].Rows[0]["p_price"].ToString(); dr["数量"] = int.Parse(k[i.Key].ToString()); dr["总价格"] = int.Parse(k[i.Key].ToString()) * double.Parse(ds.Tables[0].Rows[0]["p_price"].ToString()); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind(); } }

protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("default2.aspx"); } protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) { string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); Hashtable k = Session["car"] as Hashtable; Session["car"] = k; k.Remove(id); DataColumn dc0 = new DataColumn("id", typeof(string)); DataColumn dc1 = new DataColumn("商品名", typeof(string)); DataColumn dc2 = new DataColumn("价格", typeof(float)); DataColumn dc3 = new DataColumn("数量", typeof(int)); DataColumn dc4 = new DataColumn("总价格", typeof(float)); DataTable dt = new DataTable(); dt.Columns.Add(dc0); dt.Columns.Add(dc1); dt.Columns.Add(dc2); dt.Columns.Add(dc3); dt.Columns.Add(dc4); foreach (DictionaryEntry i in k) { //Response.Write(i.Key+" "+i.Value+"<br>"); DataRow dr = dt.NewRow(); DataSet ds = db.QueryDataSet("select * from product where p_id=" + i.Key); dr["id"] = ds.Tables[0].Rows[0]["p_id"].ToString(); dr["商品名"] = ds.Tables[0].Rows[0]["p_name"].ToString(); dr["价格"] = ds.Tables[0].Rows[0]["p_price"].ToString(); dr["数量"] = int.Parse(k[i.Key].ToString()); dr["总价格"] = int.Parse(k[i.Key].ToString()) * double.Parse(ds.Tables[0].Rows[0]["p_price"].ToString()); dt.Rows.Add(dr); } GridView1.DataSource = dt; GridView1.DataBind();

} protected void Button2_Click(object sender, EventArgs e) { Hashtable k = Session["car"] as Hashtable; string code = DateTime.Now.Ticks.ToString() + new Random().Next(); db.ExecuteNonQuery("insert into OrderList values(+code+)"); foreach(DictionaryEntry i in k) { db.ExecuteNonQuery("insert into DetailsList values(+code+,"+Session["u_id"].ToString()+","+i.Key+","+i.Value+")"); } } } 自己慢慢领悟把

pacificrack:超级秒杀,VPS低至$7.2/年,美国洛杉矶VPS,1Gbps带宽

pacificrack又追加了3款特价便宜vps搞促销,而且是直接7折优惠(一次性),低至年付7.2美元。这是本月第3波便宜vps了。熟悉pacificrack的知道机房是QN的洛杉矶,接入1Gbps带宽,KVM虚拟,纯SSD RAID10,自带一个IPv4。官方网站:https://pacificrack.com支持PayPal、支付宝等方式付款7折秒杀优惠码:R3UWUYF01T内存CPUSS...

Sharktech云服务器35折年付33美元起,2G内存/40G硬盘/4TB流量/多机房可选

Sharktech又称SK或者鲨鱼机房,是一家主打高防产品的国外商家,成立于2003年,提供的产品包括独立服务器租用、VPS云服务器等,自营机房在美国洛杉矶、丹佛、芝加哥和荷兰阿姆斯特丹等。之前我们经常分享商家提供的独立服务器产品,近期主机商针对云虚拟服务器(CVS)提供优惠码,优惠后XS套餐年付最低仅33.39美元起,支持使用支付宝、PayPal、信用卡等付款方式。下面以XS套餐为例,分享产品配...

炭云188元/年,上海CN2 VPS/2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP

炭云怎么样?炭云(之前的碳云),国人商家,正规公司(哈尔滨桓林信息技术有限公司),主机之家测评介绍过多次。现在上海CN2共享IP的VPS有一款特价,上海cn2 vps,2核/384MB内存/8GB空间/800GB流量/77Mbps端口/共享IP/Hyper-v,188元/年,特别适合电信网络。有需要的可以关注一下。点击进入:炭云官方网站地址炭云vps套餐:套餐cpu内存硬盘流量/带宽ip价格购买上...

购物车代码为你推荐
小明发布首页永久网站2015小明发布看看永久域在哪里能找到免费的短信营销方案家装短信营销如何进行才有效?淘码除了爱码,现在哪个验证码平台还能用在线沟通什么是在线状态?particular教程有没有制作花瓣飘落的AE教程particular教程particular的用法pass是什么锒行卡上的闪付pass是什么意思?西安娱乐西安那里有好玩的地方,夜生活不去邮政网关如何注销中国邮政支付网关网上账号ps5教程怎样使用PS5的程序
已备案域名 上海vps 域名服务器是什么 美国独立服务器 新加坡服务器 国外idc 香港机房托管 名片模板psd 主机屋免费空间 admit的用法 卡巴斯基试用版 四核服务器 路由跟踪 东莞主机托管 iki 免费网络空间 网络速度 阿里云个人邮箱 服务器防御 建站技术 更多