code

 public ActionResult _RecentlyViewedPro()
{
IList<TGoodPro> allProucts = new List<TGoodPro>();

#region 注释

//if (WriteCookie("RecentlyPro", "4,5,6,8,9", 10))
//{
// HttpCookie cookie = Request.Cookies["RecentlyPro"];
// int goodId = 0;
// if (cookie != null)
// {
// string[] goodIds = cookie.Value.Split(',');
////foreach (string goodId in goodIds)
// for (int i = 0; i < goodIds.Length - 1; i++)
// {
// goodId = Int32.Parse(goodIds[i]);
// TGood good = db.TGoods.Find(goodId);
// if (good != null)
// {
// p.GoodsID = good.GoodsID;
// p.GoodsNameCN = good.GoodsNameCN;
// p.GoodsPrice = good.GoodsPrice;
// p.ProductImage = good.ProductImage;
// allProucts.Add(p);
// }
// }
// }
//}
//if (WriteCookie3("Recently"))
//{
// HttpCookie cookie = Request.Cookies["Recently"];
// if (cookie != null)
// {
// for (int i = 0; i < cookie.Values.Count; i++)
// {
// TGoodPro p = new TGoodPro();
// string[] g = cookie.Values[i].Split('~');
// if(g.Length == 3)
// {
// p.ProductImage = g[0];
// p.GoodsNameCN = g[1];
// try
// {
// p.GoodsPrice = Int64.Parse(g[2]);
// }
// catch (FormatException e)
// {
////p.GoodsPrice = 52013;
// }

// }
// allProucts.Add(p);
// }
// }

//}
//WriteCookie3("Recently");
#endregion

Random r = new Random(100);

HttpCookie cookie = Request.Cookies["Recently"];
if (cookie != null)
{
for (int i = 11; i < 30; i++)
{
TGoodPro p1 = new TGoodPro();
p1.GoodsID = 7 + i;
p1.GoodsPrice = 200;
p1.GoodsNameCN = "大众汽车" + p1.GoodsID.ToString();
p1.ProductImage = "llj.jpg";
cookie.Values[p1.GoodsID.ToString()] = p1.ProductImage + "~" + p1.GoodsNameCN + "~" +
p1.GoodsPrice.ToString();
WriteCookie2("Recently", p1);

}

}
else
{
WriteCookie3("Recently");
}
if (cookie != null)
{
for (int i = 0; i < 10; i++)
{
TGoodPro p = new TGoodPro();
string[] g = cookie.Values[cookie.Values.AllKeys[i]].Split('~');
if (g.Length == 3)
{
p.ProductImage = g[0];
p.GoodsNameCN = g[1];
try
{
p.GoodsPrice = Int32.Parse(g[2]);
allProucts.Add(p);
}
catch (FormatException)
{
//p.GoodsPrice = 52013;
}
}

}
}

return View(allProucts.ToList());

}
posted @ 2011-10-29 00:08  逆天之群  阅读(162)  评论(0编辑  收藏  举报