购物车代码求一个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+")"); } } } 自己慢慢领悟把

星梦云:四川100G高防4H4G10M月付仅60元

星梦云怎么样?星梦云资质齐全,IDC/ISP均有,从星梦云这边租的服务器均可以备案,属于一手资源,高防机柜、大带宽、高防IP业务,一手整C IP段,四川电信,星梦云专注四川高防服务器,成都服务器,雅安服务器。星梦云目前夏日云服务器促销,四川100G高防4H4G10M月付仅60元;西南高防月付特价活动,续费同价,买到就是赚到!点击进入:星梦云官方网站地址1、成都电信年中活动机(成都电信优化线路,封锁...

BuyVM($5/月)不限流量流媒体优化VPS主机 1GB内存

BuyVM商家属于比较老牌的服务商,早年有提供低价年付便宜VPS主机还记得曾经半夜的时候抢购的。但是由于这个商家风控非常严格,即便是有些是正常的操作也会导致被封账户,所以后来陆续无人去理睬,估计被我们风控的抢购低价VPS主机已经手足无措。这两年商家重新调整,而且风控也比较规范,比如才入手他们新上线的流媒体优化VPS主机也没有不适的提示。目前,BuyVM商家有提供新泽西、迈阿密等四个机房的VPS主机...

Spinservers:美国独立服务器(圣何塞),$111/月

spinservers是Majestic Hosting Solutions,LLC旗下站点,主营美国独立服务器租用和Hybrid Dedicated等,spinservers这次提供的大硬盘、大内存服务器很多人很喜欢。TheServerStore自1994年以来,它是一家成熟的企业 IT 设备供应商,专门从事二手服务器和工作站业务,在德克萨斯州拥有40,000 平方英尺的仓库,库存中始终有数千台...

购物车代码为你推荐
ae序列号安装AE,序列号是什么意思?youtube创始人鬼步舞创作者是谁网络视频下载器那些视频下载器比较全而且好用?flash实例FLASH中实例是个什么概念,真心期待着!!!期待好心人,感恩!希望大家多讨论netbios协议机子上启动了netbios协议,为什么还是运行不了netbios命令cursorlocation在ENVI中双击遥感图像出来个CURSOR LOCATION/value对话框。下面有个LL : 31?6'21.84"N, 117?9'11.78"E网站客服代码在线客服系统的代码添加到网站中,要怎么做?backupexec怎样在vmware vcenter上安装backup exec agent for windows微盟价格微盟怎么收费?微盟价格做微盟平台的销售怎么样,有前景吗
紧急升级请记住新域名 网址域名注册 免费申请域名和空间 ddos 荷兰服务器 bluevm stablehost unsplash tk域名 长沙服务器 有益网络 jsp空间 135邮箱 网站卫士 美国网站服务器 华为云盘 国内域名 双线空间 789电视剧网 国外免费网盘 更多