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

RAKsmart秒杀服务器$30/月,洛杉矶/圣何塞/香港/日本站群特价

RAKsmart发布了9月份优惠促销活动,从9月1日~9月30日期间,爆款美国服务器每日限量抢购最低$30.62-$46/月起,洛杉矶/圣何塞/香港/日本站群大量补货特价销售,美国1-10Gbps大带宽不限流量服务器低价热卖等。RAKsmart是一家华人运营的国外主机商,提供的产品包括独立服务器租用和VPS等,可选数据中心包括美国加州圣何塞、洛杉矶、中国香港、韩国、日本、荷兰等国家和地区数据中心(...

Megalayer(月599元)限时8月香港和美国大带宽服务器

第一、香港服务器机房这里我们可以看到有提供四个大带宽方案,是全向带宽和国际带宽,前者适合除了中国大陆地区的全网地区用户可以用,后者国际带宽适合欧美地区业务。如果我们是需要大陆地区速度CN2优化的,那就需要选择常规的优化带宽方案,参考这里。CPU内存硬盘带宽流量价格选择E3-12308GB240GB SSD50M全向带宽不限999元/月方案选择E3-12308GB240GB SSD100M国际带宽不...

易探云香港vps主机价格多少钱?香港云服务器主机租用价格

易探云香港vps主机价格多少钱?香港vps主机租用费用大体上是由配置决定的,我们选择香港vps主机租用最大的优势是免备案vps。但是,每家服务商的机房、配置、定价也不同。我们以最基础配置为标准,综合比对各大香港vps主机供应商的价格,即可选到高性能、价格适中的香港vps主机。通常1核CPU、1G内存、2Mbps独享带宽,价格在30元-120元/月。不过,易探云香港vps主机推出四个机房的优惠活动,...

购物车代码为你推荐
excel大写金额怎么用Excel将小写金额转换成人民币的大写金额无处不在的意思,幸福无处不在,最适合才是最好是什么意思gas是什么意思GC什么意思全局钩子delphi 键盘全局钩子云办公平台Gleasy云办公平台解决了哪些问题?腾讯合作伙伴大会腾讯位置服务是什么?ocr软件下载如何安装汉王ocr文字识别软件gbk内码高考姓名gbk内码查询在线沟通网络沟通的问题有哪些idataparameterunsigned char idata是什么意思
最好看的qq空间 免费网站申请 双拼域名 腾讯实名认证中心 中国电信宽带测速器 双线asp空间 789 监控服务器 工信部网站备案查询 贵阳电信 服务器论坛 免费个人主页 网站加速 789电视剧网 国外免费网盘 ncp是什么 asp介绍 web服务器有哪些 连连支付 游戏服务器 更多