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());

}

转载于:https://www.cnblogs.com/yyqun/archive/2011/10/29/2228264.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值