欢迎来到天天文库
浏览记录
ID:44811566
大小:47.50 KB
页数:7页
时间:2019-10-29
《cookies购物车类》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、publicstaticDataTableGetShoppingCart(){ DataTabledt=newDataTable();if(HttpContext.Current.Request.Cookies["ShoppingCart"]!=null&&HttpContext.Current.Request.Cookies["ShoppingCart"].Value.Trim()!=""){HttpCookieoCookie=(HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"];oCookie.Expi
2、res=DateTime.Now.AddYears(3);stringShoppingCartStr=oCookie.Value.ToString();//HttpContext.Current.Response.Write(ShoppingCartStr);string[]arrCookie=ShoppingCartStr.Split(newchar[]{','});//查看cookie中是否有该产品stringnewCookie="";for(inti=0;i3、Trim().Remove(arrCookie[i].IndexOf(':'));}newCookie=newCookie.Substring(1);dt=Product.GetProductByProductIds(newCookie,-1);dt.Columns.Add("Quantity");dt.Columns.Add("Box");foreach(DataRowrowindt.Rows){for(inti=0;i4、row["ProductId"].ToString()){row["Quantity"]=arrCookie[i].Substring(arrCookie[i].IndexOf(":")+1);row["Quantity"]=row["Quantity"].ToString().Remove(row["Quantity"].ToString().IndexOf(":"));stringBox=arrCookie[i].Substring(arrCookie[i].LastIndexOf(":")+1);if(Box=="1")row["Box"]=true;elserow["Box5、"]=false;}}}}else{dt=Database.GetDataTable("selecttop0*fromView_ProductList");dt.Columns.Add("Quantity");}returndt;}}//如果没有该产品if(!bExists){oCookie.Value=oCookie.Value+","+ProductID.ToString()+":"+Quantity.ToString()+":"+Box.ToString();}else{oCookie.Value=newCookie.Substring(1);}HttpContext.Cur6、rent.Response.Cookies.Add(oCookie);HttpContext.Current.Response.Write("ShoppingCart:"+HttpContext.Current.Request.Cookies["ShoppingCart"].Value);}}//////移除购物车子项//////publicstaticvoidRemoveShoppingCart(intProductID){if(HttpContext.Current.Reques7、t.Cookies["ShoppingCart"]!=null){HttpCookieoCookie=(HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"];oCookie.Expires=DateTime.Now.AddYears(3);//CheckifCookiealreadycontainsameitemstringShoppingCartStr=oCookie.Value.ToStrin
3、Trim().Remove(arrCookie[i].IndexOf(':'));}newCookie=newCookie.Substring(1);dt=Product.GetProductByProductIds(newCookie,-1);dt.Columns.Add("Quantity");dt.Columns.Add("Box");foreach(DataRowrowindt.Rows){for(inti=0;i4、row["ProductId"].ToString()){row["Quantity"]=arrCookie[i].Substring(arrCookie[i].IndexOf(":")+1);row["Quantity"]=row["Quantity"].ToString().Remove(row["Quantity"].ToString().IndexOf(":"));stringBox=arrCookie[i].Substring(arrCookie[i].LastIndexOf(":")+1);if(Box=="1")row["Box"]=true;elserow["Box5、"]=false;}}}}else{dt=Database.GetDataTable("selecttop0*fromView_ProductList");dt.Columns.Add("Quantity");}returndt;}}//如果没有该产品if(!bExists){oCookie.Value=oCookie.Value+","+ProductID.ToString()+":"+Quantity.ToString()+":"+Box.ToString();}else{oCookie.Value=newCookie.Substring(1);}HttpContext.Cur6、rent.Response.Cookies.Add(oCookie);HttpContext.Current.Response.Write("ShoppingCart:"+HttpContext.Current.Request.Cookies["ShoppingCart"].Value);}}//////移除购物车子项//////publicstaticvoidRemoveShoppingCart(intProductID){if(HttpContext.Current.Reques7、t.Cookies["ShoppingCart"]!=null){HttpCookieoCookie=(HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"];oCookie.Expires=DateTime.Now.AddYears(3);//CheckifCookiealreadycontainsameitemstringShoppingCartStr=oCookie.Value.ToStrin
4、row["ProductId"].ToString()){row["Quantity"]=arrCookie[i].Substring(arrCookie[i].IndexOf(":")+1);row["Quantity"]=row["Quantity"].ToString().Remove(row["Quantity"].ToString().IndexOf(":"));stringBox=arrCookie[i].Substring(arrCookie[i].LastIndexOf(":")+1);if(Box=="1")row["Box"]=true;elserow["Box
5、"]=false;}}}}else{dt=Database.GetDataTable("selecttop0*fromView_ProductList");dt.Columns.Add("Quantity");}returndt;}}//如果没有该产品if(!bExists){oCookie.Value=oCookie.Value+","+ProductID.ToString()+":"+Quantity.ToString()+":"+Box.ToString();}else{oCookie.Value=newCookie.Substring(1);}HttpContext.Cur
6、rent.Response.Cookies.Add(oCookie);HttpContext.Current.Response.Write("ShoppingCart:"+HttpContext.Current.Request.Cookies["ShoppingCart"].Value);}}//////移除购物车子项//////publicstaticvoidRemoveShoppingCart(intProductID){if(HttpContext.Current.Reques
7、t.Cookies["ShoppingCart"]!=null){HttpCookieoCookie=(HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"];oCookie.Expires=DateTime.Now.AddYears(3);//CheckifCookiealreadycontainsameitemstringShoppingCartStr=oCookie.Value.ToStrin
此文档下载收益归作者所有