知识大全 自创Asp.net-cookies的购物车类

Posted 产品

篇首语:黄沙百战穿金甲,不破楼兰终不还。本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 自创Asp.net-cookies的购物车类相关的知识,希望对你有一定的参考价值。

自创Asp.net-cookies的购物车类  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!

    自己写的一个 cookies 购物车类 实现购物车功能 实现无需注册就可购物    using System;    using System Data;    using System Configuration;    using System Web;    using System Web Security;    using System Web UI;    using System Web UI WebControls;    using System Web UI WebControls WebParts;    using System Web UI HtmlControls;    //文章来源 x    public class CookieShoppingCart        ///    /// 加入购物车    ///    ///    ///    public static void AddToShoppingCart(int ProductID int Quantity int Box)        if (HttpContext Current Request Cookies[ ShoppingCart ] == null)        HttpCookie oCookie = new HttpCookie( ShoppingCart );    //Set Cookie to expire in hours    oCookie Expires = DateTime Now AddYears( );    oCookie Value = ProductID ToString() + : + Quantity ToString() + : + Box ToString();    HttpContext Current Response Cookies Add(oCookie);        //如果cookie已经存在    else        bool bExists = false;    HttpCookie oCookie = (HttpCookie)HttpContext Current Request Cookies[ ShoppingCart ];    oCookie Expires = DateTime Now AddYears( );    string ShoppingCartStr = oCookie Value ToString();    string[] arrCookie = ShoppingCartStr Split(new char[] );    //查看cookie中是否有该产品    string newCookie = ;    for (int i = ; i < arrCookie Length; i++)        if (arrCookie[i] Trim() Remove(arrCookie[i] IndexOf( : )) == ProductID ToString() Trim())        bExists = true;    string OldQuantity = arrCookie[i] Trim() Substring(arrCookie[i] Trim() IndexOf( : ) + );//得到数量    OldQuantity = OldQuantity Remove(OldQuantity LastIndexOf( : ));    OldQuantity = (Convert ToInt (OldQuantity) + Quantity) ToString();    arrCookie[i] = arrCookie[i] Trim() Remove(arrCookie[i] IndexOf( : )) + : + OldQuantity + : + Box ToString();    //HttpContext Current Response Write(arrCookie[i] Trim() Remove(arrCookie[i] IndexOf( : )) + 已存在!数量 + OldQuantity +     );    //HttpContext Current Response Write(arrCookie[i] +     );        newCookie = newCookie + + arrCookie[i];        //如果没有该产品    if (!bExists)        oCookie Value = oCookie Value + + ProductID ToString() + : + Quantity ToString() + : + Box ToString();        else        oCookie Value = newCookie Substring( );        HttpContext Current Response Cookies Add(oCookie);    HttpContext Current Response Write( ShoppingCart: + HttpContext Current Request Cookies[ ShoppingCart ] Value);            ///    /// 移除购物车子项    ///    ///    public static void RemoveShoppingCart(int ProductID)        if (HttpContext Current Request Cookies[ ShoppingCart ] != null)        HttpCookie oCookie = (HttpCookie)HttpContext Current Request Cookies[ ShoppingCart ];    oCookie Expires = DateTime Now AddYears( );    //Check if Cookie already contain same item    string ShoppingCartStr = oCookie Value ToString();    string[] arrCookie = ShoppingCartStr Split(new char[] );    string[] arrCookie = new string[arrCookie Length ];    int j = ;    string NewStr = ;    for (int i = ; 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( );            public static void UpdateShoppingCart(int ProductID int Quantity bool box)        int Box = ;    if (!box)    Box = ;    if (HttpContext Current Request Cookies[ ShoppingCart ] != null)        bool bExists = false;    HttpCookie oCookie = (HttpCookie)HttpContext Current Request Cookies[ ShoppingCart ];    oCookie Expires = DateTime Now AddYears( );    string ShoppingCartStr = oCookie Value ToString();    string[] arrCookie = ShoppingCartStr Split(new char[] );    //查看cookie中是否有该产品    string newCookie = ;    for (int i = ; 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( );            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( );    string ShoppingCartStr = oCookie Value ToString();    //HttpContext Current Response Write(ShoppingCartStr);    string[] arrCookie = ShoppingCartStr Split(new char[] );    //查看cookie中是否有该产品    string newCookie = ;    for (int i = ; i < arrCookie Length; i++)        newCookie = newCookie + + arrCookie[i] Trim() Remove(arrCookie[i] IndexOf( : ));        newCookie = newCookie Substring( );    dt = Product GetProductByProductIds(newCookie );    dt Columns Add( Quantity );    dt Columns Add( Box );    foreach (DataRow row in dt Rows)        for (int i = ; i < arrCookie Length; i++)        if (arrCookie[i] Trim() Remove(arrCookie[i] IndexOf( : )) == row[ ProductId ] ToString())        row[ Quantity ] = arrCookie[i] Substring(arrCookie[i] IndexOf( : ) + );    row[ Quantity ] = row[ Quantity ] ToString() Remove(row[ Quantity ] ToString() IndexOf( : ));    string Box = arrCookie[i] Substring(arrCookie[i] LastIndexOf( : ) + );    if (Box == )    row[ Box ] = true;    else    row[ Box ] = false;                    else        dt = Database GetDataTable( select top * from View_ProductList );    dt Columns Add( Quantity );        return dt;        cha138/Article/program/net/201311/11694

相关参考

知识大全 自创C#扫雷代码

趣味编程:自创C#扫雷代码  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  &

知识大全 咦!大家知道购物比价网站和购物返现网站有什么区别吗

咦!大家知道购物比价网站和购物返现网站有什么区别吗?还是他们是同一个网站?对于现在的大部分这类网站来说,比如:一淘网、帮5买、返现网,他们都有购物比价和返现功能的,比如帮5买,我一般购物都是先去这家网

知识大全 在北京网上购物哪个网站价格质量适中

在北京网上购物哪个网站价格质量适中?京东商城是不是只有电器是保证质量的!京东是国内最大的电子电器类产品的网上商城,质量和信誉都没问题。另外,凡客,当当等都是不错的购物网站。另外你如果通过券券在线购买京

咖啡厅装修设计怎样选择风格?

咖啡厅装修设计怎样选择风格?一、人文风格目前,人文类咖啡店连锁品牌较少,一般都是以个人自创品牌经营。人文类咖啡店比较注重文化内涵和修养,所以此类咖啡店对于经营者的要求很高,对于消费者的要求也很高。能经

何为“限塑令”

从2008年6月1日起,在全国范围内禁止生产、销售、使用厚度小于0.025毫米的塑料购物袋。发展改革委要抓紧修订《产业结构调整指导目录》,将超薄塑料购物袋列入淘汰类产品目录。质检总局要加快修订塑料购物

何为“限塑令”

从2008年6月1日起,在全国范围内禁止生产、销售、使用厚度小于0.025毫米的塑料购物袋。发展改革委要抓紧修订《产业结构调整指导目录》,将超薄塑料购物袋列入淘汰类产品目录。质检总局要加快修订塑料购物

科学名家故事 立志学医

   阿根廷医学专家贝尔纳多?豪塞,自创生理药物研究院,开创了用脑下垂体腺作用诊断糖尿病,并利用注射感应有效地治疗糖尿病的先河,为人类医学作出卓越贡献。 &nb

知识大全 双11购物怎么才能买到比平时便宜的多的东西

双11购物怎么才能买到比平时便宜的多的东西?是不是只有11月11日才便宜你可以在淘宝的搜索框里输入双十一来搜索,也可以在淘宝首页双11的选项那里点击进主会场选东西,主会场里面分了很多类,女装男装鞋子饰

知识大全 用Java实现基于XML的购物车

用Java实现基于XML的购物车  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!  购物车是电子商务

知识大全 JSP培训之购物车实例

JSP培训之购物车实例  以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!cha138/Art