《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;