- Rongsen.Com.Cn 版权所有 2008-2010 京ICP备08007000号 京公海网安备11010802026356号 朝阳网安编号:110105199号
- 北京黑客防线网安工作室-黑客防线网安服务器维护基地为您提供专业的
服务器维护
,企业网站维护
,网站维护
服务 - (建议采用1024×768分辨率,以达到最佳视觉效果) Powered by 黑客防线网安 ©2009-2010 www.rongsen.com.cn
作者:黑客防线网安ASP维护基地 来源:黑客防线网安ASP维护基地 浏览次数:0 |
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;
}
}
我要申请本站:N点 | 黑客防线官网 | |
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479 |