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

namespace Mall.Order
{
    public partial class Order_Check : System.Web.UI.Page
    {
        public List<MODEL.MModelProductListHelper> plists = new List<MODEL.MModelProductListHelper>();

        protected void Page_Load(object sender, EventArgs e)
        {
            BLL.Models.MemberModels models_member = new BLL.Models.MemberModels();
            models_member.CheckUserIdOrder();

            //payid=web&linbank=1
            string payinfo = Request["payid"] == null ? "" : Request["payid"].ToString();
            string paytype = Request["linbank"] == null ? "0" : Request["linbank"].ToString();
            MODEL.MOrder model_order = new MODEL.MOrder();
            model_order = (MODEL.MOrder)Session["model_order"];
            BLL.Models.MPayMModels models_pay = new BLL.Models.MPayMModels();
            model_order.Paytype = Convert.ToInt32(paytype);
            if (payinfo == "web")
            {

                model_order.PayInfo = models_pay.GetPayNameById(paytype);
            }
            else if (payinfo == "bank")
            {

                model_order.PayInfo = "银行电汇";
            }

            string buylist = string.Empty;
            buylist = Request.Cookies["cart"] == null ? "" : Request.Cookies["cart"].Value.ToString();
            buylist = Server.UrlDecode(buylist);
            string[] plist = buylist.Split(new char[] { ',' });
            int buypoint = 0;
            int buyprice = 0;
            foreach (string s in plist)
            {
                MODEL.MModelProductListHelper model = new MODEL.MModelProductListHelper();
                string[] pInfos = s.Split(new string[] { "{$s$}" }, StringSplitOptions.None);
                string priductid = pInfos[0];
                string[] tempstrs = pInfos[1].Split(new string[] { "{$yc$}" }, StringSplitOptions.None);
                string Pcount = tempstrs[0];
                tempstrs = tempstrs[1].Replace(" ", "").Split(new string[] { "\"\"" }, StringSplitOptions.None);
                string yanse = tempstrs[0].Replace("\"", "");
                string cima = tempstrs[1].Replace("\"", "");
                BLL.Models.ProductModels models = new BLL.Models.ProductModels();
                MODEL.MProduct model_product = new MODEL.MProduct();
                model.Priductid = Convert.ToInt32(priductid);
                model.CountBuy = Convert.ToInt32(Pcount);
                model.Cima = cima;
                model.Yanse = yanse;
                model_product = models.GetProductById(model.Priductid.ToString());
                model.Model_product = model_product;
                buypoint = buypoint + Convert.ToInt32(model_product.Point) * Convert.ToInt32(model.CountBuy);
                buyprice = buyprice + Convert.ToInt32(model_product.Price) * Convert.ToInt32(model.CountBuy);
                plists.Add(model);
            }
            model_order.Price = buyprice;
            model_order.Point = buypoint;
            //ViewData["plistorder"] = plists;
            //ViewData["plist"] = plist;
           // TempData["model_order"] = model_order;

        }
    }
}