using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class WebMain_Product_cart_smallcart : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand cmd = new SqlCommand("select amount,price,userid from cart where userid=" + Session["userid"], conn);
        SqlDataReader sdr = cmd.ExecuteReader();
        int amo = 0, pri = 0;
        while (sdr.Read())
        {
            amo++;
            pri += sdr.GetInt32(0) * Convert.ToInt32(sdr.GetDecimal(1));
        }
        Label l1;
        l1 = new Label();
        l1.Text = "购物车有" + amo + "种产品";
        TableRow tr;
        TableCell tc;
        tr = new TableRow();
        tc = new TableCell();
        tc.Controls.Add(l1);
        tc.HorizontalAlign = HorizontalAlign.Center;
        tr.Controls.Add(tc);
        TB.Controls.Add(tr);
        tc = new TableCell();
        l1 = new Label();
        l1.Text="总计 ：￥"+pri+"元";
        tc.Controls.Add(l1);
        tc.HorizontalAlign = HorizontalAlign.Center;
        tr.Controls.Add(tc);
        TB.Controls.Add(tr);
       HyperLink lk = new HyperLink();
        lk.Text = "进入购物车";
        lk.Target = "_blank";
        lk.NavigateUrl = "~/china/cart.aspx";
        tc = new TableCell();
        tc.Controls.Add(lk);
        tc.HorizontalAlign = HorizontalAlign.Right;
        tr.Controls.Add(tc);
        TB.Controls.Add(tr);
        conn.Close();
    }
}
