cookies购物车类.doc

上传人:豆**** 文档编号:34137354 上传时间:2022-08-14 格式:DOC 页数:8 大小:49.50KB
返回 下载 相关 举报
cookies购物车类.doc_第1页
第1页 / 共8页
cookies购物车类.doc_第2页
第2页 / 共8页
点击查看更多>>
资源描述

《cookies购物车类.doc》由会员分享,可在线阅读,更多相关《cookies购物车类.doc(8页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、如有侵权,请联系网站删除,仅供学习与交流cookies购物车类【精品文档】第 8 页cookies购物车类cookies购物车类public static DataTable GetShoppingCart()DataTable dt = new DataTable();if (HttpContext.Current.Request.CookiesShoppingCart != null & HttpContext.Current.Request.CookiesShoppingCart.Value.Trim() != )HttpCookie oCookie = (HttpCookie)Http

2、Context.Current.Request.CookiesShoppingCart;oCookie.Expires = DateTime.Now.AddYears(3);string ShoppingCartStr = oCookie.Value.ToString();/HttpContext.Current.Response.Write(ShoppingCartStr);string arrCookie = ShoppingCartStr.Split(new char , );/查看cookie中是否有该产品string newCookie = ;for (int i = 0; i ar

3、rCookie.Length; i+)newCookie = newCookie + , + arrCookiei.Trim().Remove(arrCookiei.IndexOf(:);newCookie = newCookie.Substring(1);dt = Product.GetProductByProductIds(newCookie, -1);dt.Columns.Add(Quantity);dt.Columns.Add(Box);foreach (DataRow row in dt.Rows)for (int i = 0; i arrCookie.Length; i+)if (

4、arrCookiei.Trim().Remove(arrCookiei.IndexOf(:) = rowProductId.ToString()rowQuantity = arrCookiei.Substring(arrCookiei.IndexOf(:) + 1);rowQuantity = rowQuantity.ToString().Remove(rowQuantity.ToString().IndexOf(:);string Box = arrCookiei.Substring(arrCookiei.LastIndexOf(:) + 1);if (Box = 1)rowBox = tr

5、ue;elserowBox = false;elsedt = Database.GetDataTable(select top 0 * from View_ProductList);dt.Columns.Add(Quantity);return dt;/如果没有该产品if (!bExists)oCookie.Value = oCookie.Value + , + ProductID.ToString() + : + Quantity.ToString() + : + Box.ToString();elseoCookie.Value = newCookie.Substring(1);HttpCo

6、ntext.Current.Response.Cookies.Add(oCookie);HttpContext.Current.Response.Write(ShoppingCart: + HttpContext.Current.Request.CookiesShoppingCart.Value);/ / 移除购物车子项/ / public static void RemoveShoppingCart(int ProductID)if (HttpContext.Current.Request.CookiesShoppingCart != null)HttpCookie oCookie = (H

7、ttpCookie)HttpContext.Current.Request.CookiesShoppingCart;oCookie.Expires = DateTime.Now.AddYears(3);/Check if Cookie already contain same itemstring ShoppingCartStr = oCookie.Value.ToString();string arrCookie = ShoppingCartStr.Split(new char , );string arrCookie2 = new stringarrCookie.Length - 1;in

8、t j = 0;string NewStr = ;for (int i = 0; i arrCookie.Length; i+)if (arrCookiei.Trim().Remove(arrCookiei.IndexOf(:) != ProductID.ToString()NewStr = NewStr + , + arrCookiei;if (NewStr = )HttpContext.Current.Response.CookiesShoppingCart.Value = ;elseHttpContext.Current.Response.CookiesShoppingCart.Valu

9、e = NewStr.Substring(1);public static void UpdateShoppingCart(int ProductID, int Quantity, bool box)int Box = 1;if (!box)Box = 0;if (HttpContext.Current.Request.CookiesShoppingCart != null)bool bExists = false;HttpCookie oCookie = (HttpCookie)HttpContext.Current.Request.CookiesShoppingCart;oCookie.E

10、xpires = DateTime.Now.AddYears(3);string ShoppingCartStr = oCookie.Value.ToString();string arrCookie = ShoppingCartStr.Split(new char , );/查看cookie中是否有该产品string newCookie = ;for (int i = 0; i arrCookie.Length; i+)if (arrCookiei.Trim().Remove(arrCookiei.IndexOf(:) = ProductID.ToString().Trim()arrCook

11、iei = arrCookiei.Trim().Remove(arrCookiei.IndexOf(:) + : + Quantity.ToString() + : + Box.ToString();newCookie = newCookie + , + arrCookiei;HttpContext.Current.Response.CookiesShoppingCart.Value = newCookie.Substring(1);public static DataTable GetShoppingCart()DataTable dt = new DataTable();if (HttpC

12、ontext.Current.Request.CookiesShoppingCart != null & HttpContext.Current.Request.CookiesShoppingCart.Value.Trim() != )HttpCookie oCookie = (HttpCookie)HttpContext.Current.Request.CookiesShoppingCart;oCookie.Expires = DateTime.Now.AddYears(3);string ShoppingCartStr = oCookie.Value.ToString();/HttpCon

13、text.Current.Response.Write(ShoppingCartStr);string arrCookie = ShoppingCartStr.Split(new char , );/查看cookie中是否有该产品string newCookie = ;for (int i = 0; i arrCookie.Length; i+)newCookie = newCookie + , + arrCookiei.Trim().Remove(arrCookiei.IndexOf(:);newCookie = newCookie.Substring(1);dt = Product.Get

14、ProductByProductIds(newCookie, -1);dt.Columns.Add(Quantity);dt.Columns.Add(Box);foreach (DataRow row in dt.Rows)for (int i = 0; i arrCookie.Length; i+)if (arrCookiei.Trim().Remove(arrCookiei.IndexOf(:) = rowProductId.ToString()rowQuantity = arrCookiei.Substring(arrCookiei.IndexOf(:) + 1);rowQuantity = rowQuantity.ToString().Remove(rowQuantity.ToString().IndexOf(:);string Box = arrCookiei.Substring(arrCookiei.LastIndexOf(:) + 1);if (Box = 1)rowBox = true;elserowBox = false;elsedt = Database.GetDataTable(select top 0 * from View_ProductList);dt.Columns.Add(Quantity);return dt;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁