1. /// <summary> 
  2.         /// ProInfo页, 获取单个商品详细信息 
  3.         /// </summary> 
  4.         /// <returns></returns> 
  5.         public IDbTable GetSingleGoodsInfo() 
  6.         { 
  7.             string conn = Settings.Systems.Current.ConnectionString; 
  8.             using (var db = DBCreate.CreateDb_GoodsWEB(classname, conn) as IDBGoodsWEB) 
  9.             { 
  10.                 decimal goodsId = Settings.Page.GetDecimal("goodsId"); 
  11.                 IDbTable table = db.GetSingleGoodsInfo(goodsId); 
  12.                 string shopsId = table[0]["SHOPSID"].ToString(); 
  13.                 string spic=table[0]["SPIC"].ToString(); 
  14.                 string sgoodsname = table[0]["SGOODSNAME"].ToString(); 
  15.                 string price = table[0]["PRICE"].ToString(); 
  16.                 string proprice = table[0]["PROPRICE"].ToString(); 
  17.                 string Id = Convert.ToString(goodsId); 
  18.                 SetCookie(shopsId, Id, spic, sgoodsname, price, proprice); 
  19.                 return table; 
  20.             } 
  21.         } 

 

  1. /// <summary> 
  2.        /// 设置cookie 
  3.        /// </summary>       
  4.        public void SetCookie(string shopId, string goodsId, string spic, string sgoodsname, string price, string proprice) 
  5.        { 
  6.            System.Web.HttpContext context = base.Settings.Context; 
  7.            HttpCookie cookie = context.Request.Cookies[shopId]; 
  8.            if (cookie == null
  9.            { 
  10.                cookie = new HttpCookie(shopId); 
  11.                DateTime dt = DateTime.Now; 
  12.                TimeSpan ts = new TimeSpan(30, 0, 0, 0); 
  13.                cookie.Expires = dt.Add(ts); 
  14.                cookie.Value = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Goods></Goods>")); 
  15.                context.Response.Cookies.Add(cookie); 
  16.            } 
  17.            XDocument xml = XDocument.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(cookie.Value))); 
  18.            var goodsNodes = from a in xml.Root.Elements("Good") where a.Attribute("ID").Value == goodsId select a; 
  19.            goodsNodes.Remove<XElement>(); 
  20.            XElement node = new XElement("Good"); 
  21.            node.SetAttributeValue("ID", goodsId); 
  22.            node.SetAttributeValue("SPIC", spic); 
  23.            node.SetAttributeValue("SGOODSNAME", sgoodsname); 
  24.            node.SetAttributeValue("PRICE", price); 
  25.            node.SetAttributeValue("PROPRICE", proprice); 
  26.            xml.Root.AddFirst(node); 
  27.            cookie.Value = Convert.ToBase64String(Encoding.UTF8.GetBytes(xml.ToString())); 
  28.        } 

 

  1. public IDbTable GetCookie() 
  2.        { 
  3.            string shopsId = base.GetString("shopsId"); 
  4.            System.Web.HttpContext context = base.Settings.Context; 
  5.            HttpCookie cookie = context.Request.Cookies[shopsId]; 
  6.            //if (cookie != null) 
  7.            //{ 
  8.            //    cookie.Expires = DateTime.Now.AddDays(-1); 
  9.            //    context.Response.AppendCookie(cookie); 
  10.            //}      
  11.            DbTable table = new DbTable(new string[] { "ID""SPIC""SGOODSNAME""PRICE""PROPRICE" }, 
  12.                new DbDataType[] { DbDataType.String, DbDataType.String, DbDataType.String, DbDataType.String, DbDataType.String }); 
  13.            if (cookie != null
  14.            { 
  15.                XDocument xml = XDocument.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(cookie.Value))); 
  16.                foreach (XElement x in xml.Root.Elements("Good")) 
  17.                { 
  18.                    string Id = x.Attribute("ID").Value; 
  19.                    string spic = x.Attribute("SPIC").Value; 
  20.                    string sgoodsname = x.Attribute("SGOODSNAME").Value; 
  21.                    string price = x.Attribute("PRICE").Value; 
  22.                    string proprice = x.Attribute("PROPRICE").Value; 
  23.                    table.Add(new object[] { Id, spic, sgoodsname, price, proprice }); 
  24.                } 
  25.            } 
  26.            return table; 
  27.        }