自己写的一个a.net-cookies购物车类(2)_.NET概论及软件使用_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

自己写的一个a.net-cookies购物车类(2)

作者:黑客防线网安ASP维护基地 来源:黑客防线网安ASP维护基地 浏览次数:0

本篇关键词:购物车一个自己string
黑客防线网安网讯:   RemoveShoppingCart(int ProductID)  {  if (HttpContext.Current.Request.Cookies["ShoppingCart"] != null)  {  HttpCookie oCookie = (HttpCookie)HttpContext.Current.Reque...

   RemoveShoppingCart(int ProductID)

  {

  if (HttpContext.Current.Request.Cookies["ShoppingCart"] != null)

  {

  HttpCookie oCookie = (HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"];

  oCookie.Expires = DateTime.Now.AddYears(3);

  //Check if Cookie already contain same item

  string ShoppingCartStr = oCookie.Value.ToString();

  string[] arrCookie = ShoppingCartStr.Split(new char[] { ',' });

  string[] arrCookie2 = new string[arrCookie.Length - 1];

  int j = 0;

  string NewStr = "";

  for (int i = 0; i < arrCookie.Length; i++)

  {

  if (arrCookie[i].Trim().Remove(arrCookie[i].IndexOf(':')) != ProductID.ToString())

  NewStr = NewStr + "," + arrCookie[i];

  }

  if (NewStr == "")

  HttpContext.Current.Response.Cookies["ShoppingCart"].Value = "";

  else

  HttpContext.Current.Response.Cookies["ShoppingCart"].Value = NewStr.Substring(1);

  }

  }

  public static void UpdateShoppingCart(int ProductID, int Quantity, bool box)

  {

  int Box = 1;

  if (!box)

  Box = 0;

  if (HttpContext.Current.Request.Cookies["ShoppingCart"] != null)

  {

  bool bExists = false;

  HttpCookie oCookie = (HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"];

  oCookie.Expires = 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 (arrCookie[i].Trim().Remove(arrCookie[i].IndexOf(':')) == ProductID.ToString().Trim())

  arrCookie[i] = arrCookie[i].Trim().Remove(arrCookie[i].IndexOf(':')) + ":" + Quantity.ToString() + ":" + Box.ToString();

  newCookie = newCookie + "," + arrCookie[i];

  }

  HttpContext.Current.Response.Cookies["ShoppingCart"].Value = newCookie.Substring(1);

  }

  }
   public static DataTable GetShoppingCart()
  {

  DataTable dt = new DataTable();

  if (HttpContext.Current.Request.Cookies["ShoppingCart"] != null && HttpContext.Current.Request.Cookies["ShoppingCart"].Value.Trim() != "")

  {

  HttpCookie oCookie = (HttpCookie)HttpContext.Current.Request.Cookies["ShoppingCart"];

  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 < arrCookie.Length; i++)

  {

  newCookie = newCookie + "," + arrCookie[i].Trim().Remove(arrCookie[i].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 (arrCookie[i].Trim().Remove(arrCookie[i].IndexOf(':')) == row["ProductId"].ToString())

  {

  row["Quantity"] = arrCookie[i].Substring(arrCookie[i].IndexOf(":") + 1);

  row["Quantity"] = row["Quantity"].ToString().Remove(row["Quantity"].ToString().IndexOf(":"));

  string Box = arrCookie[i].Substring(arrCookie[i].LastIndexOf(":") + 1);

  if (Box == "1")

  row["Box"] = true;

  else

  row["Box"] = false;

  }

  }

  }

  }

  else

  {

  dt = Database.GetDataTable("select top 0 * from View_ProductList");

  dt.Columns.Add("Quantity");

  }

  return dt;

  }

  }

 

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-14156-1.html
网站维护教程更新时间:2012-03-30 05:29:30  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer