cookies购物车类(6页).doc

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

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

1、-cookies购物车类-第 6 页public static DataTable GetShoppingCart()DataTable dt = new DataTable();if (HttpContext.Current.Request.CookiesShoppingCart != null & HttpContext.Current.Request.CookiesShoppingCart.Value.Trim() != )HttpCookie oCookie = (HttpCookie)HttpContext.Current.Request.CookiesShoppingCart;oC

2、ookie.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 arrCookie.Length; i+)newCookie = newCookie + , +

3、 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 (arrCookiei.Trim().Remove(arrCookiei.IndexOf(:)

4、 = 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.GetDat

5、aTable(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);HttpContext.Current.Response.Cookies.Add(oCookie);Ht

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

7、hoppingCart;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;int j = 0;string NewStr = ;for (int i = 0; i arr

8、Cookie.Length; i+)if (arrCookiei.Trim().Remove(arrCookiei.IndexOf(:) != ProductID.ToString()NewStr = NewStr + , + arrCookiei;if (NewStr = )HttpContext.Current.Response.CookiesShoppingCart.Value = ;elseHttpContext.Current.Response.CookiesShoppingCart.Value = NewStr.Substring(1);public static void Upd

9、ateShoppingCart(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.Expires = DateTime.Now.AddYears(3);string Shopp

10、ingCartStr = 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()arrCookiei = arrCookiei.Trim().Remove(arrCookiei.Inde

11、xOf(:) + : + Quantity.ToString() + : + Box.ToString();newCookie = newCookie + , + arrCookiei;HttpContext.Current.Response.CookiesShoppingCart.Value = newCookie.Substring(1);public static DataTable GetShoppingCart()DataTable dt = new DataTable();if (HttpContext.Current.Request.CookiesShoppingCart !=

12、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();/HttpContext.Current.Response.Write(ShoppingCartStr);s

13、tring 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.GetProductByProductIds(newCookie, -1);dt.Columns.

14、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 淘文阁