using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Mall.Cart
{
    public partial class Buy : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string id = string.Empty;
            string count = string.Empty;
            string yscm = string.Empty;
            string buylist = string.Empty;
            if (Request.Form["id"] != null)
            {

                //获得当前放入购物车商品信息
                id = Request.Form["id"].ToString();
                count = Request.Form["count"].ToString();
                yscm = Request.Form["yansecm"].ToString();
                yscm = yscm.Replace("<SPAN id=sku-select-size>", "").Replace("</SPAN>", "");
                StringBuilder str_productinfo = new StringBuilder();
                //加入购物车
                buylist = Request.Cookies["cart"] == null ? string.Empty : Request.Cookies["cart"].Value.ToString();
                buylist = Server.UrlDecode(buylist);
                StringBuilder str_cart = new StringBuilder();

                str_productinfo.Append(count);
                str_productinfo.Append("{$yc$}");
                str_productinfo.Append(yscm);

                if (string.IsNullOrEmpty(buylist))
                {
                    str_cart.Append(id);
                    str_cart.Append("{$s$}");
                    str_cart.Append(str_productinfo.ToString());
                }
                else
                {

                    str_cart.Append(buylist);
                    str_cart.Append(",");
                    str_cart.Append(id);
                    str_cart.Append("{$s$}");
                    str_cart.Append(str_productinfo.ToString());
                }







                //写入cookies

                Response.Cookies["cart"].Value = Server.UrlEncode(str_cart.ToString());

            }
            else
            {


            }
            Response.Redirect("/cart/cart.aspx");
        }
    }
}