App_Code/ShoppingCar.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Collections;
using System.Data.SqlClient;

/// <summary>
///ShoppingCar_Cookie 的摘要说明
/// </summary>
public class ShoppingCar
{
    public ShoppingCar()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }
    public void add(ShoppingItem shopitem)
    {
        HttpCookie hc = null;

        if (HttpContext.Current.Request.Cookies["cookieCart"] != null)
        {
            hc = HttpContext.Current.Request.Cookies["cookieCart"];

        }
        else
            hc = new HttpCookie("cookieCart");
        hc.Expires = DateTime.Now.AddHours(3);
        if (IndexOfProduct(shopitem.Id))//判断是否存在相同商品
        {
            string[] books = HttpUtility.UrlDecode(hc[shopitem.Id.ToString()]).Split(new char[] { '|' });

            hc.Values[shopitem.Id.ToString()] = HttpUtility.UrlEncode(books[0] + "|" + books[1] + "|" + books[2] + "|" + (int.Parse(books[3]) + shopitem.Quantity));
        }
        else
            hc.Values[shopitem.Id.ToString()] = HttpUtility.UrlEncode(shopitem.Id + "|" + shopitem.Name + "|" + shopitem.Price + "|" + shopitem.Quantity);
        HttpContext.Current.Response.Cookies.Add(hc);
    }
    public List<ShoppingItem> GetItems()//遍历Cookie中所有的商品
    {
        string strsql = string.Empty;
        SqlParameter[] parameters = null;
        HttpCookie hc = HttpContext.Current.Request.Cookies["cookieCart"];
        List<ShoppingItem> items = new List<ShoppingItem>();
        if (hc != null)
        {
            for (int i = 0; i < hc.Values.Count; i++)
            {
                string[] books = HttpUtility.UrlDecode(hc.Values[i]).Split('|');
                ShoppingItem item = new ShoppingItem();
                item.Id = Int64.Parse(books[0]);
                item.Name = books[1];
                item.Price = double.Parse(books[2]);
                item.Quantity = int.Parse(books[3]);
                //items.Add(item);
                strsql = "Insert Into ShoppingCar (Id,UserId,ShoppingId,GoodsCount,CarTime) values(@Id,@UserId,@ShoppingId,@GoodsCount,@CarTime) ";
                parameters = new SqlParameter[]
后面还有 121 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。