- /// <summary>
- /// ProInfo页, 获取单个商品详细信息
- /// </summary>
- /// <returns></returns>
- public IDbTable GetSingleGoodsInfo()
- {
- string conn = Settings.Systems.Current.ConnectionString;
- using (var db = DBCreate.CreateDb_GoodsWEB(classname, conn) as IDBGoodsWEB)
- {
- decimal goodsId = Settings.Page.GetDecimal("goodsId");
- IDbTable table = db.GetSingleGoodsInfo(goodsId);
- string shopsId = table[0]["SHOPSID"].ToString();
- string spic=table[0]["SPIC"].ToString();
- string sgoodsname = table[0]["SGOODSNAME"].ToString();
- string price = table[0]["PRICE"].ToString();
- string proprice = table[0]["PROPRICE"].ToString();
- string Id = Convert.ToString(goodsId);
- SetCookie(shopsId, Id, spic, sgoodsname, price, proprice);
- return table;
- }
- }
- /// <summary>
- /// 设置cookie
- /// </summary>
- public void SetCookie(string shopId, string goodsId, string spic, string sgoodsname, string price, string proprice)
- {
- System.Web.HttpContext context = base.Settings.Context;
- HttpCookie cookie = context.Request.Cookies[shopId];
- if (cookie == null)
- {
- cookie = new HttpCookie(shopId);
- DateTime dt = DateTime.Now;
- TimeSpan ts = new TimeSpan(30, 0, 0, 0);
- cookie.Expires = dt.Add(ts);
- cookie.Value = Convert.ToBase64String(Encoding.UTF8.GetBytes("<Goods></Goods>"));
- context.Response.Cookies.Add(cookie);
- }
- XDocument xml = XDocument.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(cookie.Value)));
- var goodsNodes = from a in xml.Root.Elements("Good") where a.Attribute("ID").Value == goodsId select a;
- goodsNodes.Remove<XElement>();
- XElement node = new XElement("Good");
- node.SetAttributeValue("ID", goodsId);
- node.SetAttributeValue("SPIC", spic);
- node.SetAttributeValue("SGOODSNAME", sgoodsname);
- node.SetAttributeValue("PRICE", price);
- node.SetAttributeValue("PROPRICE", proprice);
- xml.Root.AddFirst(node);
- cookie.Value = Convert.ToBase64String(Encoding.UTF8.GetBytes(xml.ToString()));
- }
- public IDbTable GetCookie()
- {
- string shopsId = base.GetString("shopsId");
- System.Web.HttpContext context = base.Settings.Context;
- HttpCookie cookie = context.Request.Cookies[shopsId];
- //if (cookie != null)
- //{
- // cookie.Expires = DateTime.Now.AddDays(-1);
- // context.Response.AppendCookie(cookie);
- //}
- DbTable table = new DbTable(new string[] { "ID", "SPIC", "SGOODSNAME", "PRICE", "PROPRICE" },
- new DbDataType[] { DbDataType.String, DbDataType.String, DbDataType.String, DbDataType.String, DbDataType.String });
- if (cookie != null)
- {
- XDocument xml = XDocument.Parse(Encoding.UTF8.GetString(Convert.FromBase64String(cookie.Value)));
- foreach (XElement x in xml.Root.Elements("Good"))
- {
- string Id = x.Attribute("ID").Value;
- string spic = x.Attribute("SPIC").Value;
- string sgoodsname = x.Attribute("SGOODSNAME").Value;
- string price = x.Attribute("PRICE").Value;
- string proprice = x.Attribute("PROPRICE").Value;
- table.Add(new object[] { Id, spic, sgoodsname, price, proprice });
- }
- }
- return table;
- }