using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Web.Mail;

public partial class WebMain_Product_cart : System.Web.UI.UserControl
{
    private int Integralyz = 0;
    private Label l1 = new Label();
    private Label l2 = new Label();
    private Label l3 = new Label();
    private Label l4 = new Label();
    private Label l5 = new Label(); 
    private Label l6 = new Label();
    private Label l7 = new Label();
    private RadioButton r0=new RadioButton();
    private RadioButton r1=new RadioButton();
    protected void Page_Load(object sender, EventArgs e)
    {
        # region 面版初始复值
        string Cuserid = Session["userid"].ToString().Trim();

            this.Panel2.Visible = false;
            if (IsPostBack)
            {
                this.Panel2.Visible = true;
            }
        
        this.Panel3.Visible = false;
        //从购物车中清除产品
        if (Request.QueryString["do"] == "delall")
        {
            string sql = "delete from cart where userid=" + Cuserid;
            TOPdo.Execsql(sql);
            Response.Redirect("~/china/cart.aspx");
        }
        if (Request.QueryString["do"] == "del")
        {
            string sql = "delete from cart where id=" + Request.QueryString["id"].Trim();
            TOPdo.Execsql(sql);
            Response.Redirect("~/china/cart.aspx");
        }
        if (Request.QueryString["do"] == "addPP")
        {
            string Cid;
            string Cattr = "";
            int Camount;
            decimal Cprice;
            Cid = Request.QueryString["Pid"].Trim();
            # region 重组属性配件
            SqlConnection connattr = CDatabase.wtoconn();
            connattr.Open();
            SqlCommand smdatrr = new SqlCommand("select XX,ThumbnailsPic,Products from ProductInfo where id=" + Cid, connattr);
            SqlDataReader sdr2 = smdatrr.ExecuteReader();
            sdr2.Read();
            Cattr = "00";
            string picurl = sdr2.GetString(1);
            string pname = sdr2.GetString(2);
            sdr2.Close();
            connattr.Close();
            # endregion
            //更新或新添记录
            Camount = 1;
            Cprice = Convert.ToDecimal(Request.QueryString["price"].Trim());
            string strsql = "";
            if (TOPdo.ExecW(Convert.ToInt32(Cuserid), Convert.ToInt32(Cid.Trim()), Cattr))
            {
                strsql = "update cart set amount=amount+1 where userid=" + Cuserid + " and pid=" + Cid;
            }
            else
            {
                strsql = "insert into cart(userid,pid,amount,price,Attribute,pic,pname) values(" + Cuserid + "," + Cid + "," + Camount + "," + Cprice + ",'" + Cattr + "','" + picurl + "','" + pname + "')";
            }
            if (TOPdo.Execsql(strsql))
            {
                Response.Redirect("cart.aspx");
            }
            else
            {
                Response.Write("<script>alert('此次提交失败!!')</script>");
            }
        }
        if (!IsPostBack)
        {
            # region 购物车绑定
            SqlConnection connsc = CDatabase.wtoconn();
            connsc.Open();
            SqlCommand smd8 = new SqlCommand("select * from cart  where userid=" + Cuserid, connsc);
            SqlDataReader sdr8 = smd8.ExecuteReader();
            if (sdr8.HasRows == false)
            {
                this.counttj.Visible = false;
                this.tt1.Visible = false;
                this.tt2.Visible = true;
            }
            else
            {
                sdr8.Close();
                connsc.Close();
                SqlConnection conn = CDatabase.wtoconn();
                conn.Open();
                SqlCommand smd = new SqlCommand("select * from cart where userid=" + Cuserid, conn);
                SqlDataReader sdr = smd.ExecuteReader();
                decimal counttotal = 0;
                while (sdr.Read())
                {
                    counttotal += sdr.GetInt32(3) * sdr.GetDecimal(4);
                }
                sdr.Close();
                SqlDataAdapter sda = new SqlDataAdapter("select * from cart where userid=" + Cuserid, conn);
                DataSet ds = new DataSet();
                sda.Fill(ds, "cuu");
                this.GridView1.DataSource = ds;
                this.GridView1.DataKeyNames = new string[] { "ID" };
                this.GridView1.DataBind();
                SqlDataReader sdrg;
                SqlCommand smdg;
                System.Web.UI.WebControls.Image imgg;
                HyperLink hyg;
                TextBox txtg;
                Label llg;
                ImageButton imgg2;
                for (int i = 0; i < GridView1.Rows.Count; i++)
                {
                    smd = new SqlCommand("select * from cart where id=" + GridView1.DataKeys[i].Value, conn);
                    sdr = smd.ExecuteReader();
                    sdr.Read();
                    imgg2 = (System.Web.UI.WebControls.ImageButton)GridView1.Rows[i].FindControl("pic");
                    imgg2.ImageUrl = "~/upfile/" + sdr.GetString(6);
                    imgg2.Width = 60;
                    imgg2.Height = 40;
                    imgg2.PostBackUrl = "~/china/productlist.aspx?id="+sdr.GetInt32(2);
                    txtg = (TextBox)GridView1.Rows[i].FindControl("txtamount");
                    txtg.Text = Convert.ToString(sdr.GetInt32(3));
                    hyg = (HyperLink)GridView1.Rows[i].FindControl("HyperLink1");
                    hyg.NavigateUrl = "~/china/cart.aspx?id=" + sdr.GetInt32(0) + "&do=del";
                    llg = (Label)GridView1.Rows[i].FindControl("tj");
                    llg.Text = "￥：" + Convert.ToString(sdr.GetInt32(3) * Convert.ToDecimal(sdr.GetDecimal(4).ToString("0.00")));
                    sdr.Close();
                }
                conn.Close();
                counttj.Text = "合计：￥&nbsp;" + Convert.ToString(counttotal.ToString("0.00"));
                img3.Click += new ImageClickEventHandler(img1_Click);
           

            }
         # endregion
        }
        # endregion
    }
 
        # region 单击下一步 会员选择句块

    protected void img1_Click(object sender, EventArgs e)
       {
           TextBox txtbox;
           string sql = "";
           for (int j = 0; j < GridView1.Rows.Count; j++)
           {
               txtbox = (TextBox)GridView1.Rows[j].FindControl("txtamount");
               Doadmin.Execsql("update cart set amount=" + txtbox.Text + " where id=" + GridView1.DataKeys[j].Value);
           }

        string Cuserid = Session["userid"].ToString().Trim();
        this.Panel1.Visible = false;
        this.Panel2.Visible = true;
        this.Panel3.Visible = false;
        if (Session["Wtouser"] == "vipadmin")
        {
            SqlConnection connsc = CDatabase.wtoconn();
            connsc.Open();
            SqlCommand smd8 = new SqlCommand("select * from cart  where userid=" + Cuserid, connsc);
            SqlDataReader sdr8 = smd8.ExecuteReader();
            if (sdr8.HasRows == false)
            {
                Response.Write("<script>alert('购物车没产品');window.location.href='/default.aspx'</script>");
                sdr8.Close();
                connsc.Close();
                Response.End();
            }
            sdr8.Close();
            SqlDataAdapter sdae = new SqlDataAdapter("select * from ServiceArea", connsc);
            DataSet dds = new DataSet();
            sdae.Fill(dds, "sa");
            this.txtpostadd.DataSource = dds;
            this.txtpostadd.DataTextField = "AreaName";
            this.txtpostadd.DataValueField = "id";
            this.txtpostadd.DataBind();
            connsc.Close();
            connsc.Close();
            //从购物车中清除单一产品
            l1.Text = "货号";
            l2.Text = "商品名称";
            l3.Text = "优惠价格";
            l5.Text = "数量";
            l6.Text = "小计";
            TableRow tr;
            TableCell tc;
            tr = new TableRow();
            tr.HorizontalAlign = HorizontalAlign.Center;
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l2);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l3);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l5);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l6);
            tr.Controls.Add(tc);
            TB2.Controls.Add(tr);
            TB2.HorizontalAlign = HorizontalAlign.Center;
            tr.CssClass = "carttr";

            ImageButton img1;
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smd = new SqlCommand("select * from cart where userid="+Cuserid, conn);
            SqlDataReader sdr = smd.ExecuteReader();
            if (!sdr.HasRows)
            {
                Response.Write("<script>alert('购物车没产品');window.location.href='/default.aspx'</script>");
            }
            Label lbl1 = new Label();
            TableCell tc2;
            TextBox txtBox;
            decimal counttotal = 0;
            while (sdr.Read())
            {
                l1 = new Label();
                SqlConnection connid = CDatabase.wtoconn();
                connid.Open();
                SqlCommand smdid = new SqlCommand("select ProductsNo from ProductInfo where id=" + sdr.GetInt32(2), connid);
                l1.Text = Convert.ToString(smdid.ExecuteScalar());
                connid.Close();
                smdid.Cancel();
                tr = new TableRow();
                tr.CssClass = "carttrM";
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = sdr.GetString(7);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = " ￥：" + Convert.ToString(sdr.GetDecimal(4).ToString("0.00"));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = Convert.ToString(sdr.GetInt32(3));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = "￥：" + Convert.ToString(sdr.GetInt32(3) *Convert.ToDecimal(sdr.GetDecimal(4).ToString("0.00")));
                counttotal += sdr.GetInt32(3) * sdr.GetDecimal(4);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                TB2.Controls.Add(tr);
            }

            this.dsp();
            TB2.CellPadding = 0;
            TB2.CellSpacing = 0;
            TB2.CssClass = "cartTB2";
            sdr.Close();
            this.Label20.Text = Session["zk"].ToString();
            this.counttotal.Text = Convert.ToString(counttotal.ToString("0.00"));
            SqlCommand freesmd = new SqlCommand("select freesonfei from SystemBasicInformation", conn);
            decimal freeint = Convert.ToDecimal(freesmd.ExecuteScalar());
            if (freeint > Convert.ToDecimal(this.counttotal.Text))
            {
                SqlCommand sonfei = new SqlCommand("select sonfei from SystemBasicInformation", conn);
                Session["sonfei"] = Convert.ToString(sonfei.ExecuteScalar());
                ordermoney.Text = (Convert.ToDecimal((Convert.ToDecimal(counttotal.ToString("0.00"))*Convert.ToDecimal(Session["zk"])/10) + Convert.ToDecimal(Session["sonfei"].ToString()))).ToString("0.00");
                this.sonfei.Text = Session["sonfei"].ToString();
                this.sflal.Text = this.sonfei.Text.ToString();
                this.link.Text = "购足<b><font color=red> " + freeint + "</b> </font>元；我们将免费送货上门;";

                link.PostBackUrl = "~/";
                this.link.Visible = true;
            }
            else
            {
                ordermoney.Text = (Convert.ToDecimal(Convert.ToDecimal(counttotal.ToString("0.00")) * Convert.ToDecimal(Session["zk"]) / 10)).ToString("0.00");
                this.link.Visible = true;
                this.link.Text = "您购买金额超过了<b><font color=red> " + freeint + "</b> </font>元，我们将免费送货上门;"; ;
            }
            SqlCommand smdtxt = new SqlCommand("select * from MemberVIP where id="+Session["userid"], conn);
            SqlDataReader sdrtxt = smdtxt.ExecuteReader();
            sdrtxt.Read();
            this.txtname.Text = sdrtxt.GetString(2);
            this.txtemail.Text = sdrtxt.GetString(7);
            this.txttel.Text = sdrtxt.GetString(14);
            this.txtmobi.Text = sdrtxt.GetString(13);
            this.txtadd.Text = sdrtxt.GetString(11);
            this.txtpost.Text = sdrtxt.GetString(12);
            sdrtxt.Close();
            conn.Close();

        }
        else
        {
            this.Panel3.Visible = true;
            this.Panel2.Visible = false;
            this.Panel1.Visible = false;
        }
    }
        # endregion

    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        this.Panel2.Visible = false;
        this.Panel1.Visible = true;
    }
    # region 直接购物
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        string Cuserid = Session["userid"].ToString().Trim();
        this.Panel2.Visible = true;
        SqlConnection connsc = CDatabase.wtoconn();
        connsc.Open();
        SqlCommand smd8 = new SqlCommand("select * from cart  where userid=" + Cuserid, connsc);
        SqlDataReader sdr8 = smd8.ExecuteReader();
        if (sdr8.HasRows == false)
        {
            Response.Write("购物车没产品");
            sdr8.Close();
            connsc.Close();
            Response.End();
        }
        sdr8.Close();
        SqlDataAdapter sdae = new SqlDataAdapter("select * from ServiceArea", connsc);
        DataSet dds = new DataSet();
        sdae.Fill(dds, "sa");
        this.txtpostadd.DataSource = dds;
        this.txtpostadd.DataTextField = "AreaName";
        this.txtpostadd.DataValueField = "id";
        this.txtpostadd.DataBind();
        connsc.Close();

        //从购物车中清除单一产品
        l1.Text = "货号";
        l2.Text = "商品名称";
        l3.Text = "优惠价格";
        l5.Text = "数量";
        l6.Text = "小计";
        TableRow tr;
        TableCell tc;
        tr = new TableRow();
        tr.HorizontalAlign = HorizontalAlign.Center;
        tc = new TableCell();
        tc.Controls.Add(l1);
        tr.Controls.Add(tc);
        tc = new TableCell();
        tc.Controls.Add(l2);
        tr.Controls.Add(tc);
        tc = new TableCell();
        tc.Controls.Add(l3);
        tr.Controls.Add(tc);
        tc = new TableCell();
        tc.Controls.Add(l5);
        tr.Controls.Add(tc);
        tc = new TableCell();
        tc.Controls.Add(l6);
        tr.Controls.Add(tc);
        TB2.Controls.Add(tr);
        TB2.HorizontalAlign = HorizontalAlign.Center;
        tr.CssClass = "carttr";

        ImageButton img1;
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select * from cart where userid=" + Cuserid, conn);
        SqlDataReader sdr = smd.ExecuteReader();
        if (!sdr.HasRows)
        {
            Response.Write("<script>alert('购物车没产品');window.location.href='/default.aspx'</script>");
        }
        Label lbl1 = new Label();
        TableCell tc2;
        TextBox txtBox;
        decimal counttotal = 0;
        while (sdr.Read())
        {
            l1 = new Label();
            SqlConnection connid = CDatabase.wtoconn();
            connid.Open();
            SqlCommand smdid = new SqlCommand("select ProductsNo from ProductInfo where id=" + sdr.GetInt32(2), connid);
            l1.Text = Convert.ToString(smdid.ExecuteScalar());
            connid.Close();
            smdid.Cancel();
            tr = new TableRow();
            tr.CssClass = "carttrM";
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);

            l1 = new Label();
            l1.Text = sdr.GetString(7);
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);

            l1 = new Label();
            l1.Text = " ￥：" + Convert.ToString(sdr.GetDecimal(4).ToString("0.00"));
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);

            l1 = new Label();
            l1.Text = Convert.ToString(sdr.GetInt32(3));
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);


            l1 = new Label();
            l1.Text = "￥：" + Convert.ToString(sdr.GetInt32(3) *Convert.ToDecimal(sdr.GetDecimal(4).ToString("0.00")));
            counttotal += sdr.GetInt32(3) * sdr.GetDecimal(4);
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            TB2.Controls.Add(tr);
        }


        this.dsp();
        TB2.CellPadding = 0;
        TB2.CellSpacing = 0;
        TB2.CssClass = "cartTB2";
        sdr.Close();  
        this.counttotal.Text = Convert.ToString(counttotal.ToString("0.00"));
        SqlCommand freesmd = new SqlCommand("select freesonfei from SystemBasicInformation", conn);
        decimal freeint = Convert.ToDecimal(freesmd.ExecuteScalar());
        if (freeint > Convert.ToDecimal(this.counttotal.Text))
        {
            SqlCommand sonfei = new SqlCommand("select sonfei from SystemBasicInformation", conn);
            Session["sonfei"] = Convert.ToString(sonfei.ExecuteScalar());
            ordermoney.Text = (Convert.ToDecimal(Convert.ToDecimal(counttotal.ToString("0.00")) + Convert.ToDecimal(Session["sonfei"].ToString()))).ToString();
            this.sonfei.Text = Session["sonfei"].ToString();
            this.sflal.Text = Session["sonfei"].ToString();
            this.link.Text = "购足<b><font color=red> " + freeint + "</b> </font>元；我们将免费送货上门;";
            link.PostBackUrl = "~/";
            this.link.Visible = true;
        }
        else
        {
            ordermoney.Text = Convert.ToString(Convert.ToDecimal(counttotal.ToString("0.00")));
            this.link.Visible = true;
            this.link.Text = "您购买金额超过了<b><font color=red> " + freeint + "</b> </font>元，我们将免费送货上门;";;
        }
        conn.Close();
    }
    # endregion
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smdreg = new SqlCommand("select RegVIPset,IntegralSet,RegEmailSet from SystemBasicInformation", conn);
        SqlDataReader sdr = smdreg.ExecuteReader();
        sdr.Read();
        string regvipset = sdr.GetString(0).Trim();
        int integralset = sdr.GetInt32(1);
        string regemailset = sdr.GetString(2).Trim();
        sdr.Close();
        conn.Close();
        string reguser, regpwd, email;
        reguser = this.reguser.Text.Trim();
        regpwd = this.regpwd2.Text.Trim();
        email = this.email.Text;
        string userip;
        if (Request.ServerVariables["HTTP_VIA"] != null)
        {

            userip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();

        }
        else
        {
            userip = Request.ServerVariables["REMOTE_ADDR"].ToString();
        }
        conn.Open();
        SqlCommand smmd = new SqlCommand("select count(*) from MemberVIP where vipusername='" + reguser + "'", conn);
        int count = Convert.ToInt32(smmd.ExecuteScalar());
        if (count == 0)
        {
            if (Doadmin.Exec("insert into MemberVIP (isok,vipusername,vipuserpwd,vipemail,addtime,logintimes,vipright,loginIP,Integral,enddate) values('" + regvipset + "','" + reguser + "','" + regpwd + "','" + email + "','" + DateTime.Now.ToString() + "'," + 1 + ",'" + 0 + "','" + userip + "'," + integralset + ",'" + DateTime.Now.ToString() + "')"))
            {
                SqlCommand smd = new SqlCommand("select * from  MemberVIP where vipusername='" + reguser + "' and vipuserpwd='" + regpwd + "'", conn);
                SqlDataReader sdr7 = smd.ExecuteReader();
                sdr7.Read();
                Session["Wtouser"] = "vipadmin";
                Session["wtouserid"] = sdr7.GetInt32(0);
                Session["vipname"] = sdr7.GetString(2);
                Session["vipright"] = "0";
                Session["username"] = reguser;
                Session["times"] = "0";
                Session["times2"] = "0";
                Session["zk"] = sdr["vipzk"].ToString();
                string sqlstr2 = "update cart set userid=" + sdr7.GetInt32(0) + " where userid=" + Session["userid"];
                TOPdo.Execsql(sqlstr2);
                Session["userid"] = Convert.ToString(sdr7.GetInt32(0));

                sdr7.Close();
                SqlCommand smdj;

                smdj = new SqlCommand("select * from cart where userid=" + Session["userid"].ToString(), conn);
                SqlDataReader sdrj;
                sdrj = smdj.ExecuteReader();
                string pidstr = "";
                while (sdrj.Read())
                {
                    pidstr += sdrj["id"].ToString() + "$";
                }
                sdrj.Close();
                string[] txt = pidstr.Split('$');
                string pidd = "";
                decimal price;
                for (int i = 0; i < txt.Length - 1; i++)
                {
                    smdj = new SqlCommand("select pid from cart where id=" + txt[i].ToString(), conn);
                    pidd = Convert.ToString(smdj.ExecuteScalar());
                    smdj = new SqlCommand("select VIPPrice from ProductInfo where id=" + pidd.Trim(), conn);
                    price = Convert.ToDecimal(smdj.ExecuteScalar());
                    Doadmin.Execsql("update cart set price=" + price + " where id=" + txt[i]);
                }


                SqlCommand Msmd = new SqlCommand("select * from SystemBasicInformation", conn);
                SqlDataReader Msdr = Msmd.ExecuteReader();
                Msdr.Read();
                string Mform, Muid, Mpwd, Mstmp, Misopen, Mcont, MCompanyName, MWEBName, MTel, MFax, MEmail, MQQ, MAddress, MMSN, TBWW, MLOGOpic, Memailto;
                Mform = Msdr.GetString(7);
                Muid = Mform;
                Mpwd = Msdr.GetString(26);
                Mstmp = Msdr.GetString(25);
                Misopen = Msdr.GetString(1).ToString().Trim();
                MCompanyName = Msdr.GetString(2);
                MWEBName = Msdr.GetString(3);
                MTel = Msdr.GetString(5);
                MFax = Msdr.GetString(6);
                MEmail = Msdr.GetString(7);
                MQQ = Msdr.GetString(8);
                MAddress = Msdr.GetString(10);
                MMSN = Msdr.GetString(13);
                TBWW = Msdr.GetString(14);
                Memailto = Msdr.GetString(20);
                MLOGOpic = "<a href=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "><img src=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "/images/" + Msdr.GetString(15) + " border=0></a>";
                Msdr.Close();
                if (Memailto == "y")
                {
                    SqlCommand Msmd2 = new SqlCommand("select content from email where lx='1'", conn);
                    Mcont = Server.HtmlDecode(Convert.ToString(Msmd2.ExecuteScalar())).Replace("http://127.0.0.1/","../");
                    SqlCommand Msmd3 = new SqlCommand("select title from email where lx='1'", conn);
                    string Mti = Convert.ToString(Msmd3.ExecuteScalar());

                    MailMessage msg = new MailMessage();
                    msg.From = Mform;  //发送方地址(如test@163.com)
                    msg.To = this.email.Text; //接收方地址(如test@163.com) 
                    msg.BodyFormat = MailFormat.Html;   //正文内容类型 
                    msg.BodyEncoding = System.Text.Encoding.Default;    //正文内容编码 
                    //msg.Attachments.Add(new MailAttachment("d:\\d.txt"));
                    //主题 
                    msg.Subject = Mti;
                    //内容 
                    //编码定义
                    Mcont = ((Mcont.Replace("$UID$", this.reguser.Text)).Replace("$PWD$", this.regpwd2.Text));
                    Mcont = Mcont.Replace("$CMY$", MCompanyName);
                    Mcont = Mcont.Replace("$WEBN$", MWEBName);
                    Mcont = Mcont.Replace("$TEL$", MTel);
                    Mcont = Mcont.Replace("$FAX$", MFax);
                    Mcont = Mcont.Replace("$EMA$", MEmail);
                    Mcont = Mcont.Replace("$QQ$", MQQ);
                    Mcont = Mcont.Replace("$ADD$", MAddress);
                    Mcont = Mcont.Replace("$MSN$", MMSN);
                    Mcont = Mcont.Replace("$TBW$", TBWW);
                    Mcont = Mcont.Replace("$LOGO$", MLOGOpic);
                    Mcont = Mcont.Replace("$ORN$", this.reguser.Text);
                    msg.Body = Mcont;
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置为需要用户验证 
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Muid); //设置验证用户名 
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Mpwd); //设置验证密码 
                    SmtpMail.SmtpServer = Mstmp;  //邮件服务器地址(如smtp.163.com) 
                    SmtpMail.Send(msg);  //发送 

                }
                this.Panel6.Visible = false;
                this.Panel5.Visible = true;
                this.okmsg.Visible = true;
                this.cotinu.Visible = true;
                this.rereg.Visible = true;
                this.regerr.Visible = false;
                this.nook.Visible = false;
            }
            else
            {
                this.Panel6.Visible = true;
                this.Panel5.Visible = false;
                this.nook.Visible = true;
                this.okmsg.Visible = false;
                this.cotinu.Visible = false;
                this.regerr.Visible = false;
                this.rereg.Visible = false;
            }

        }
        else
        {
            this.regerr.Visible = true;
            this.okmsg.Visible =false;
            this.cotinu.Visible = false;
            this.nook.Visible = false;
            this.rereg.Visible = false;
        }
        conn.Close();
        this.Panel3.Visible = true;
        this.Panel2.Visible = false;

    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string UserName = this.vipuser2.Text.ToString().Trim();
        string PassWord = this.vippwd2.Text.ToString().Trim();
        if (TOPdo.checkUser(UserName, PassWord))
        {
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smdd = new SqlCommand("select intwhere1,intwhere2 from SystemBasicInformation", conn);
            SqlDataReader sdrd = smdd.ExecuteReader();
            sdrd.Read();
            int intwhere1 = sdrd.GetInt32(0);
            int intwhere2 = sdrd.GetInt32(1);
            sdrd.Close();
            if (Session["Wtouser"] != "vipadmin")
            {
                string sqlstr = "update MemberVIP set logintimes=logintimes+1,enddate='" + DateTime.Now.ToString() + "' where vipusername='" + UserName + "' and vipuserpwd='" + PassWord + "'";
                TOPdo.Execsql(sqlstr);
            }

            SqlDataAdapter sdae = new SqlDataAdapter("select * from ServiceArea", conn);
            DataSet dds = new DataSet();
            sdae.Fill(dds, "sa");
            this.txtpostadd.DataSource = dds;
            this.txtpostadd.DataTextField = "AreaName";
            this.txtpostadd.DataValueField = "id";
            this.txtpostadd.DataBind();

            SqlCommand smd = new SqlCommand("select * from  MemberVIP where vipusername='" + UserName + "' and vipuserpwd='" + PassWord + "'", conn);
            SqlDataReader sdr = smd.ExecuteReader();
            sdr.Read();
            DateTime d1 = sdr.GetDateTime(24).AddMonths(intwhere1);
            DateTime d2 = sdr.GetDateTime(25).AddMonths(intwhere2);
            if (DateTime.Now > d1 || DateTime.Now > d2)
            {
                Session["intj"] = "0";
            }
            else
            {
                Session["intj"] = sdr["Integral"].ToString();
            }
            if (DateTime.Now > d1)
            {
                TOPdo.Execsql("update MemberVIP set Integral=0 where id=" + sdr.GetInt32(0));
                Session["time1"] = DateTime.Now.AddMonths(intwhere1).ToString("d");

            }
            else
            {
                Session["time1"] = d1.ToString("d");

            }
            if (DateTime.Now > d2)
            {
                TOPdo.Execsql("update MemberVIP set Integral=0 where id=" + sdr.GetInt32(0));
                Session["time2"] = DateTime.Now.AddMonths(intwhere2).ToString("d");
            }
            else
            {
                Session["time2"] = d2.ToString("d");
            }

            Session["Wtouser"] = "vipadmin";
            Session["wtouserid"] = sdr.GetInt32(0);
            Session["vipname"] = sdr.GetString(2);
            Session["times"] = "0";
            Session["times2"] = "0";
            Session["zk"] = sdr["vipzk"].ToString();
            string sqlstr2 = "update cart set userid=" + sdr.GetInt32(0) + " where userid=" + Session["userid"];
            TOPdo.Execsql(sqlstr2);
            Session["userid"] = Convert.ToString(sdr.GetInt32(0));
            this.Panel2.Visible = true;
            this.txtname.Text = sdr.GetString(2);
            this.txtemail.Text = sdr.GetString(7);
            this.txttel.Text = sdr.GetString(14);
            this.txtmobi.Text = sdr.GetString(13);
            this.txtadd.Text = sdr.GetString(11);
            this.txtpost.Text =sdr.GetString(12);
            sdr.Close();
            string Cuserid = Session["userid"].ToString().Trim();
            this.Panel2.Visible = true;
            SqlConnection connsc = CDatabase.wtoconn();
            connsc.Open();
            SqlCommand smd8 = new SqlCommand("select * from cart  where userid=" + Cuserid, connsc);
            SqlDataReader sdr8 = smd8.ExecuteReader();
            if (sdr8.HasRows == false)
            {
                Response.Write("<script>alert('购物车没产品');window.location.href='/default.aspx'</script>");
                sdr8.Close();
                connsc.Close();
            }
            sdr8.Close();
            connsc.Close();
            //从购物车中清除单一产品
            l1.Text = "货号";
            l2.Text = "商品名称";
            l3.Text = "优惠价格";
            l5.Text = "数量";
            l6.Text = "小计";
            TableRow tr;
            TableCell tc;
            tr = new TableRow();
            tr.HorizontalAlign = HorizontalAlign.Center;
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l2);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l3);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l5);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l6);
            tr.Controls.Add(tc);
            TB2.Controls.Add(tr);
            TB2.HorizontalAlign = HorizontalAlign.Center;
            tr.CssClass = "carttr";

            ImageButton img1;
            SqlCommand smd2 = new SqlCommand("select * from cart where userid=" + Cuserid, conn);
            SqlDataReader sdra = smd2.ExecuteReader();
            if (!sdra.HasRows)
            {
                Response.Write("<script>alert('购物车没产品');window.location.href='/default.aspx'</script>");
            }
            Label lbl1 = new Label();
            TableCell tc2;
            TextBox txtBox;
            decimal counttotal = 0;
            while (sdra.Read())
            {
                l1 = new Label();
                SqlConnection connid = CDatabase.wtoconn();
                connid.Open();
                SqlCommand smdid = new SqlCommand("select ProductsNo from ProductInfo where id=" + sdra.GetInt32(2), connid);
                l1.Text = Convert.ToString(smdid.ExecuteScalar());
                connid.Close();
                smdid.Cancel();
                tr = new TableRow();
                tr.CssClass = "carttrM";
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = sdra.GetString(7);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = " ￥：" + Convert.ToString(sdra.GetDecimal(4).ToString("0.00"));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = Convert.ToString(sdra.GetInt32(3));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = "￥：" + Convert.ToString(sdra.GetInt32(3) *Convert.ToDecimal(sdra.GetDecimal(4).ToString("0.00")));
                counttotal += sdra.GetInt32(3) * sdra.GetDecimal(4);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                
                TB2.Controls.Add(tr);
            }

            this.dsp();
            TB2.CellPadding = 0;
            TB2.CellSpacing = 0;
            TB2.CssClass = "cartTB2";
            sdra.Close();    
            this.counttotal.Text = Convert.ToString(counttotal.ToString("0.00"));
            SqlCommand freesmd = new SqlCommand("select freesonfei from SystemBasicInformation", conn);
            int freeint = Convert.ToInt32(freesmd.ExecuteScalar());
            if (freeint > Convert.ToInt32(this.counttotal.Text))
            {
                SqlCommand sonfei = new SqlCommand("select sonfei from SystemBasicInformation", conn);
                Session["sonfei"] = Convert.ToString(sonfei.ExecuteScalar());
                ordermoney.Text = (Convert.ToDecimal(Convert.ToDecimal(counttotal.ToString("0.00")) + Convert.ToDecimal(Session["sonfei"].ToString()))).ToString("0.00");
                this.sonfei.Text = Session["sonfei"].ToString();
                this.sflal.Text = Session["sonfei"].ToString();
                this.link.Text = "购足<b><font color=red> " + freeint + "</b> </font>元；我们将免费送货上门;";
                link.PostBackUrl = "~/";
                this.link.Visible = true;
            }
            else
            {
                ordermoney.Text = Convert.ToString(counttotal.ToString("0.00"));
                this.link.Text = "您购买金额超过了<b><font color=red> " + freeint + "</b> </font>元，我们将免费送货上门;";
            }
            SqlCommand smdj;
            smdj = new SqlCommand("select * from cart where userid=" + Session["userid"].ToString(), conn);
            SqlDataReader sdrj;
            sdrj = smdj.ExecuteReader();
            string pidstr = "";
            while (sdrj.Read())
            {
                pidstr += sdrj["id"].ToString() + "$";
            }
            sdrj.Close();
            string[] txt = pidstr.Split('$');
            string pidd = "";
            decimal price;
            for (int i = 0; i < txt.Length - 1; i++)
            {
                smdj = new SqlCommand("select pid from cart where id=" + txt[i].ToString(), conn);
                pidd = Convert.ToString(smdj.ExecuteScalar());
                smdj = new SqlCommand("select VIPPrice from ProductInfo where id=" + pidd.Trim(), conn);
                price = Convert.ToDecimal(smdj.ExecuteScalar());
                Doadmin.Execsql("update cart set price=" + price + " where id=" + txt[i]);
            }
            conn.Close();
        }
        else
        {
            this.Panel3.Visible = true;
            this.Panel2.Visible = false;
            this.msgerror.Visible = true;
        }
        string Url = "http://" + Request.ServerVariables["Server_NAME"] + Request.CurrentExecutionFilePath.ToString() + "?" + HttpContext.Current.Request.QueryString.ToString();
        Response.Redirect(Url);
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        string postson = Request.Form["t1"].ToString().Trim();//配送方式       
        string payway = Request.Form["t2"].ToString().Trim();//支付方式
        if (postson == ""||payway=="")
        {
            Response.Write("<script>alert('支持方式或送货方式未填写好!');history.go(-1);</script>");
        }
        else
        { 
        SqlConnection coN = CDatabase.wtoconn();
        coN.Open();
        SqlCommand smD = new SqlCommand("select title,DefrayExpenses,GuaranteesPrice from PWway where isshow='y' and id=" + postson, coN);
        SqlDataReader sdR = smD.ExecuteReader();
        sdR.Read();
        string orderson = sdR.GetString(0);
        string sonfei =Convert.ToString(sdR.GetDecimal(1));
        string sonbao = Convert.ToString(sdR.GetDecimal(2));
        
        sdR.Close();

        SqlCommand smD2 = new SqlCommand("select title,Payment,paywayID from Payway where isshow='y' and id=" + payway, coN);
        SqlDataReader sdR2 = smD2.ExecuteReader();
        sdR2.Read();
        string orderpay = sdR2.GetString(0);
        string payfei = Convert.ToString(sdR2.GetDecimal(1));
        Session["payid"] = payway;
       
        if (Convert.ToString(sdR2.GetInt32(2)).Trim() == "10000001")
        {
            this.onlinepay.Visible = true;
            this.HyperLink3.Visible = true;
            Label8.Text = "总金额：" + ordermoney.Text + " CNY ";
            
        }
        else
        {
            this.onlinepay.Visible = false;
            this.HyperLink3.Visible = false;
        } 
        sdR2.Close();
        coN.Close();
        this.Panel1.Visible = false;
        this.Panel2.Visible = false;
        this.Panel3.Visible = false;
        this.Panel4.Visible = true;
        // Order表添加信息
        string Orderno, OrderUserId, Ordername, OrderEmail, OrderTel, OrderMobi, OrderAdd, OrderPost, Orderaear, OrderPostTime, OrderMone, OrderPayM, OrderSonF, OrderTatal, OrderAddDate, OrderState,isvip;
        Orderno = "SALE" + DateTime.Now.ToString("yyyymmddssss");
        OrderUserId = Session["userid"].ToString();
        Ordername = this.txtname.Text.ToString().Trim();
        OrderEmail = this.txtemail.Text.ToString().Trim();
        OrderTel = this.txttel.Text.ToString().Trim();
        OrderMobi = this.txtmobi.Text.ToString().Trim();
        OrderAdd = this.txtadd.Text.ToString().Trim();
        OrderPost = this.txtpost.Text.ToString().Trim();
        Orderaear = this.txtpostadd.SelectedValue.ToString().Trim() ;
        if (TextBox3.Text == "")
        {
            OrderPostTime = this.DropDownList1.SelectedItem.Text;
        }
        else
        {
            OrderPostTime = this.TextBox3.Text +"  "+ this.DropDownList1.SelectedItem.Text;
        }
        OrderMone = this.txtmone.Text.ToString().Trim();
        OrderPayM = orderpay;//暂留
        OrderSonF = orderson;
        if (Session["Wtouser"] != null)
        {
            isvip = "y";
        }
        else
        {
            isvip = "n";
        }
        OrderTatal = this.ordermoney.Text.ToString();
        OrderAddDate = DateTime.Now.ToString();
        OrderState = "0";
        float zk;
        if (Session["Wtouser"] == "vipadmin")
        {
            zk =Convert.ToSingle(Session["zk"].ToString());
        }
        else
        {
            zk = 10.00f;
        }
            coN.Open();
            int intt=0;
        if (Session["Wtouser"] != null)
        {

            SqlCommand freesmd = new SqlCommand("select freesonfei from SystemBasicInformation", coN);
            decimal freeint = Convert.ToDecimal(freesmd.ExecuteScalar());
            if (freeint > Convert.ToDecimal(this.counttotal.Text))
            {
                SqlCommand sonfei2 = new SqlCommand("select sonfei from SystemBasicInformation", coN);
                Session["sonfei"] = Convert.ToString(sonfei2.ExecuteScalar());
                this.sonjf.Text = "赠送 " + Convert.ToString((int)(Convert.ToDouble(ordermoney.Text) - Convert.ToDouble(Session["sonfei"]))) + " 分";
                intt = (int)(Convert.ToDouble(ordermoney.Text) - Convert.ToDouble(Session["sonfei"]));
            }
            else
            {
                this.sonjf.Text = "赠送 " + Convert.ToString((int)(Convert.ToDouble(ordermoney.Text))) + " 分";
                intt = (int)Convert.ToDouble(ordermoney.Text);
            }

            //int where1, result1, where2, result2, where3, result3, result4;
            //SqlCommand smdjf;
            //SqlDataReader sdrjf;
            //smdjf = new SqlCommand("select * from Integral",coN);
            //sdrjf = smdjf.ExecuteReader();
            //sdrjf.Read();
            //where1 = Convert.ToInt32(sdrjf["where1"].ToString());
            //result1 = Convert.ToInt32(sdrjf["result1"].ToString());
            //where2 = Convert.ToInt32(sdrjf["where2"].ToString());
            //result2 = Convert.ToInt32(sdrjf["result2"].ToString());
            //where3 = Convert.ToInt32(sdrjf["where3"].ToString());
            //result3 = Convert.ToInt32(sdrjf["result3"].ToString());
            //result4 = Convert.ToInt32(sdrjf["result4"].ToString());
            //sdrjf.Close();
           
            //if (Convert.ToInt32(this.counttotal.Text) < where1)
            //{
            //    //Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result1+ " where id=" + Session["userid"].ToString());
            //    this.sonjf.Text = "赠送 0 分";
            //    intt = 0;
            //}

            //if (Convert.ToInt32(this.counttotal.Text) >= where1 && Convert.ToInt32(this.counttotal.Text) < where2)
            //{
            //    //Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result1+ " where id=" + Session["userid"].ToString());
            //    this.sonjf.Text = "赠送 " + result1.ToString() + " 分";
            //    intt = result1;
            //}

            //if (Convert.ToInt32(this.counttotal.Text) >= where2 && Convert.ToInt32(this.counttotal.Text) < where3)
            //{
            //    //Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result2 + " where id=" + Session["userid"].ToString());
            //    this.sonjf.Text = "赠送 " + result2.ToString() + " 分";
            //    intt = result2;
            //}

            //if (Convert.ToInt32(this.counttotal.Text) == where3)
            //{
            //    //Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result1 + " where id=" + Session["userid"].ToString());
            //    this.sonjf.Text = "赠送 " + result3.ToString() + " 分";
            //    intt = result3;
            //}

            //if (Convert.ToInt32(this.counttotal.Text) > where3)
            //{
            //    //Doadmin.Execsql("update MemberVIP set Integral=Integral+" + result4 + " where id=" + Session["userid"].ToString());
            //    this.sonjf.Text = "赠送 " + result3.ToString() + " 分";
            //    intt = result3;
            //}
        }
        else
        {
            intt = 0;
            this.sonjf.Text = "只有会员才能赠送积分";
            Label15.Visible = false;
        }
        SqlCommand smdCC = new SqlCommand("select count(*) from cart where userid=" + Session["userid"], coN);
        if (Convert.ToInt32(smdCC.ExecuteScalar()) == 0)
        {
            Response.Write("<script>alert('购物车没产品');window.location.href='/default.aspx'</script>");
            Response.Redirect("~/");
        }
        coN.Close();
        string sql1 = "insert into Orderw(Orderno,OrderUserId,Ordername,OrderEmail,OrderTel,OrderMobi,OrderAdd,OrderPost,Orderaear,OrderPostTime,OrderMone,OrderPayM,OrderSonF,OrderTatal,OrderAddDate,OrderState,isvip,psfy,xszk,b3) ";
        sql1 += "values ('" + Orderno + "'," + OrderUserId + ",'" + Ordername + "','" + OrderEmail + "','" + OrderTel + "','" + OrderMobi + "','" + OrderAdd + "','" + OrderPost + "','" + Orderaear + "','" + OrderPostTime + "','" + OrderMone + "','" + OrderPayM + "','" + OrderSonF + "'," + Convert.ToDecimal(OrderTatal) + ",'" + OrderAddDate + "'," + OrderState + ",'" + isvip + "'," +this.sonfei.Text.ToString()+ "," + zk + ","+intt+")";
        if (TOPdo.Execsql(sql1))
        {
            string ProductName, Attribute, pic, sql8;
            decimal price;
            int Amount, Pid, OrderID;

            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            SqlCommand smd2 = new SqlCommand("select id from Orderw where Orderno='"+Orderno+"'", conn);
            OrderID = Convert.ToInt32(smd2.ExecuteScalar());
            SqlCommand smd = new SqlCommand("select * from cart where userid=" + Session["userid"], conn);
            SqlDataReader sdr = smd.ExecuteReader();
            SqlCommand smd8;
            while (sdr.Read())
            {
                Pid = sdr.GetInt32(2);
                ProductName = sdr.GetString(7);
                price = sdr.GetDecimal(4);
                Amount = sdr.GetInt32(3);
                Attribute = sdr.GetString(5);
                pic = sdr.GetString(6);
                TOPdo.Execsql("insert into OrderInfo(OrderID,Pid,ProductName,price,Amount,Attr,pic,addtime,OrderState) values (" + OrderID + "," + Pid + ",'" + ProductName + "'," + price + "," + Amount + ",'" + Attribute + "','" + pic + "','" + DateTime.Now.ToString() + "',0)");
            }
            sdr.Close();
            SqlCommand smdorder = new SqlCommand("select * from Orderw where Orderno='" + Orderno + "'", conn);
            SqlDataReader sdrorder = smdorder.ExecuteReader();
            sdrorder.Read();
            this.lno.Text = sdrorder.GetString(1);
            this.lname.Text = sdrorder.GetString(3);
            this.lemail.Text = sdrorder.GetString(4);
            this.ltel.Text = sdrorder.GetString(5);
            this.lmobi.Text = sdrorder.GetString(6);
            this.lp.Text = sdrorder.GetString(13);
            this.lz.Text = sdrorder.GetString(12);
            this.ltotal.Text =this.ordermoney.Text.ToString();
            this.lorderdate.Text =Convert.ToString(sdrorder.GetDateTime(15));
            this.lpostdate.Text = sdrorder.GetString(10);
            string laear = sdrorder.GetString(9);
            this.ladd.Text = sdrorder.GetString(7);
            this.lpost.Text = sdrorder.GetString(8);
            this.lmone.Text = sdrorder.GetString(11);
            this.sflal.Text = this.sonfei.Text.ToString();
            Session["v_oid"] = sdrorder.GetString(1);
            Session["v_amount"] = this.ordermoney.Text.ToString();
            //收货人信息
            Session["v_rcvname"] = sdrorder.GetString(3);
            Session["v_rcvaddr"] = sdrorder.GetString(7);
            Session["v_rcvtel"] = sdrorder.GetString(5);
            Session["v_rcvpost"] = sdrorder.GetString(8);
            Session["v_rcvemail"] = sdrorder.GetString(4);
            Session["v_rcvmobile"] = sdrorder.GetString(6);

            //订货人信息
            Session["v_ordername"] = sdrorder.GetString(3);
            Session["v_orderaddr"] = sdrorder.GetString(7);
            Session["v_ordertel"] = sdrorder.GetString(5);
            Session["v_orderpost"] = sdrorder.GetString(8);
            Session["v_orderemail"] = sdrorder.GetString(4);
            Session["v_ordermobile"] = sdrorder.GetString(6);

            //备注信息
            Session["remark1"] = sdrorder.GetString(11);
            Session["remark2"] = sdrorder.GetString(11);
            
            if (sdrorder.GetString(17) == "y")
            {
                this.lvipimg.Visible = true;
                this.lvip.Visible = true;
            }
            else { this.lmin.Visible = true; }
            sdrorder.Close();
            SqlCommand smdordert = new SqlCommand("select AreaName from ServiceArea where id=" + laear.ToString(), conn);
            this.larea.Text = Convert.ToString(smdordert.ExecuteScalar());
            //TB3-------------------------------------------------------------------
            l1.Text = "货号";
            l2.Text = "商品名称";
            l3.Text = "优惠价格";
            l4.Text = "属性配件";
            l5.Text = "数量";
            l6.Text = "小计";
            TableRow tr;
            TableCell tc;
            tr = new TableRow();
            tr.HorizontalAlign = HorizontalAlign.Center;
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l2);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l3);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l4);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l5);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l6);
            tr.Controls.Add(tc);
            TB3.Controls.Add(tr);
            TB3.HorizontalAlign = HorizontalAlign.Center;
            tr.CssClass = "carttr";
            ImageButton img1;
            SqlCommand smdo = new SqlCommand("select * from cart where userid=" + OrderUserId, conn);
            SqlDataReader sdro = smdo.ExecuteReader();
            Label lbl1 = new Label();
            TableCell tc2;
            TextBox txtBox;
            decimal counttotal = 0;
            while (sdro.Read())
            {
                l1 = new Label();
                SqlConnection connid = CDatabase.wtoconn();
                connid.Open();
                SqlCommand smdid = new SqlCommand("select ProductsNo from ProductInfo where id=" + sdro.GetInt32(2), connid);
                l1.Text = Convert.ToString(smdid.ExecuteScalar());
                connid.Close();
                smdid.Cancel();
                tr = new TableRow();
                tr.CssClass = "carttrM";
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = sdro.GetString(7);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = " ￥：" + Convert.ToString(sdro.GetDecimal(4).ToString("0.00"));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = Convert.ToString(sdro.GetString(5));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);
                l1 = new Label();

                l1 = new Label();
                l1.Text = Convert.ToString(sdro.GetInt32(3));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = "￥：" + Convert.ToString(sdro.GetInt32(3) *Convert.ToDecimal(sdro.GetDecimal(4).ToString("0.00")));
                counttotal += sdro.GetInt32(3) * sdro.GetDecimal(4);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                TB3.Controls.Add(tr);
            }
            this.counttotal.Text = Convert.ToString(counttotal.ToString("0.00"));
            ordermoney.Text = Convert.ToString(counttotal.ToString("0.00"));
            TB3.CellPadding = 0;
            TB3.CellSpacing = 0;
            TB3.CssClass = "cartTB2";
            sdro.Close();
            conn.Close();
            //TB3 OVER


            //发送邮件

            //邮件发送

            SqlConnection Mconn = CDatabase.wtoconn();
            Mconn.Open();
            SqlCommand Msmd = new SqlCommand("select * from SystemBasicInformation", Mconn);
            SqlDataReader Msdr = Msmd.ExecuteReader();
            Msdr.Read();
            string Mform, Muid, Mpwd, Mstmp, Misopen, Mcont, MCompanyName, MWEBName, MTel, MFax, MEmail, MQQ, MAddress, MMSN, TBWW, MLOGOpic, Memailto;
            Mform = Msdr.GetString(7);
            Muid = Mform;
            Mpwd = Msdr.GetString(26);
            Mstmp = Msdr.GetString(25);
            Misopen = Msdr.GetString(1).ToString().Trim();
            MCompanyName = Msdr.GetString(2);
            MWEBName = Msdr.GetString(3);
            MTel = Msdr.GetString(5);
            MFax = Msdr.GetString(6);
            MEmail = Msdr.GetString(7);
            MQQ = Msdr.GetString(8);
            MAddress = Msdr.GetString(10);
            MMSN = Msdr.GetString(13);
            TBWW = Msdr.GetString(14);
            Memailto = Msdr.GetString(24).Trim();
            MLOGOpic = "<a href=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "><img src=http://" + Request.ServerVariables["SERVER_NAME"].ToString() + "/images/" + Msdr.GetString(15) + " border=0></a>";
            Msdr.Close();
            if (txtemail.Text != "")
            {
                if (Memailto == "y")
                {
                    SqlCommand Msmd2 = new SqlCommand("select content from email where lx='4'", Mconn);
                    Mcont = Server.HtmlDecode(Convert.ToString(Msmd2.ExecuteScalar())).Replace("http://127.0.0.1/", "../");
                    SqlCommand Msmd3 = new SqlCommand("select title from email where lx='4'", Mconn);
                    string Mti = Convert.ToString(Msmd3.ExecuteScalar());
                    MailMessage msg = new MailMessage();
                    msg.From = Mform;  //发送方地址(如test@163.com)
                    msg.To = this.lemail.Text; //接收方地址(如test@163.com) 
                    msg.BodyFormat = MailFormat.Html;   //正文内容类型 
                    msg.BodyEncoding = System.Text.Encoding.Default;    //正文内容编码 
                    //msg.Attachments.Add(new MailAttachment("d:\\d.txt"));
                    //主题 
                    msg.Subject = Mti;
                    //内容 
                    //编码定义
                    Mcont = Mcont.Replace("$CMY$", MCompanyName);
                    Mcont = Mcont.Replace("$WEBN$", MWEBName);
                    Mcont = Mcont.Replace("$TEL$", MTel);
                    Mcont = Mcont.Replace("$FAX$", MFax);
                    Mcont = Mcont.Replace("$EMA$", MEmail);
                    Mcont = Mcont.Replace("$QQ$", MQQ);
                    Mcont = Mcont.Replace("$ADD$", MAddress);
                    Mcont = Mcont.Replace("$MSN$", MMSN);
                    Mcont = Mcont.Replace("$TBW$", TBWW);
                    Mcont = Mcont.Replace("$LOGO$", MLOGOpic);
                    Mcont = Mcont.Replace("$ORD$", this.lno.Text);
                    Mcont = Mcont.Replace("$ODT$", this.lorderdate.Text);
                    Mcont = Mcont.Replace("$OTA$", this.ltotal.Text);
                    Mcont = Mcont.Replace("$ORN$", this.lname.Text);
                    msg.Body = Mcont;
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置为需要用户验证 
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", Muid); //设置验证用户名 
                    msg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", Mpwd); //设置验证密码 
                    SmtpMail.SmtpServer = Mstmp;  //邮件服务器地址(如smtp.163.com) 
                    SmtpMail.Send(msg);  //发送 

                }
            }

            TOPdo.Execsql("delete from cart  where userid=" + Session["userid"]);
            //Session["userid"] = null;
            //Session["userid"] = DateTime.Now.ToString("hmmssffff");
            Session.Timeout = 2000;
            Mconn.Close();
        }
        else
        {
            //Response.Write(sql1);
            Response.Write("<script>alert('数据格式不完整！');window.location.href='/';</script>");
        }
        // Orderinfo表添加信息
        }

 


    }
    protected void txtpostadd_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select * from PWway where isshow='y' order by sort", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        TableRow tr;
        TableCell tc;
        int j = 0;
        while (sdr.Read())
        {
            tr = new TableRow();
            tc = new TableCell();
            r0 = new RadioButton();
            r0.CssClass = "carttitle2";
            r0.Text = sdr.GetString(3);
            r0.GroupName = "post";
            r0.Attributes.Add("onclick", "a(" + sdr.GetInt32(0)+ ")");
            tc.Controls.Add(r0);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc = new TableCell();
            l1 = new Label();
            l1.Text = "";
            l1.CssClass = "carttitle2";
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            l1 = new Label();
            l1.Text = "";
            l1.CssClass = "carttitle2";
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            son.Controls.Add(tr);
            tr = new TableRow();
            tc = new TableCell();
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc.ColumnSpan = 3;
            l1 = new Label();
            l1.Text =Server.HtmlDecode(sdr.GetString(6)).Replace("http://127.0.0.1/","../");
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            son.Controls.Add(tr);
        }
        sdr.Close();
        SqlCommand smd2 = new SqlCommand("select * from Payway where isshow='y' order by sort", conn);
        SqlDataReader sdr2 = smd2.ExecuteReader();
        while (sdr2.Read())
        {
            tr = new TableRow();
            tc = new TableCell();
            r0 = new RadioButton();
            r0.CssClass = "carttitle2";
            r0.Text = sdr2.GetString(5);
            r0.GroupName = "pay";
            r0.Attributes.Add("onclick", "b(" + sdr2.GetInt32(0) + ")");
            tc.Controls.Add(r0);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc = new TableCell();
            l1 = new Label();
            l1.Text = "" ;
            l1.CssClass = "carttitle2";
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            pay.Controls.Add(tr);
            tr = new TableRow();
            tc = new TableCell();
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc.ColumnSpan = 2;
            l1 = new Label();
            l1.Text = Server.HtmlDecode(sdr2.GetString(7)).Replace("http://127.0.0.1/","../");
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            pay.Controls.Add(tr);
            tr = new TableRow();
            tc = new TableCell();
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc.ColumnSpan = 2;
            tr.Height = 10;
            tr.Controls.Add(tc);
            pay.Controls.Add(tr);
        }
        sdr2.Close();
        conn.Close();

    }
    #region 配送方式与支付方式过程
    protected void dsp()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlCommand smd = new SqlCommand("select * from PWway where isshow='y' order by sort", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        TableRow tr;
        TableCell tc;
        while (sdr.Read())
        {
            tr = new TableRow();
            tc = new TableCell();
            r0 = new RadioButton();
            r0.CssClass = "carttitle2";
            r0.Text = sdr.GetString(3);
            r0.GroupName = "post";
            r0.Attributes.Add("onclick", "a(" + sdr.GetInt32(0) + ")");
            tc.Controls.Add(r0);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc = new TableCell();
            l1 = new Label();
            l1.Text = "";
            l1.CssClass = "carttitle2";
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            l1 = new Label();
            l1.Text = "";
            l1.CssClass = "carttitle2";
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            son.Controls.Add(tr);
            tr = new TableRow();
            tc = new TableCell();
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc.ColumnSpan = 3;
            l1 = new Label();
            l1.Text = Server.HtmlDecode(sdr.GetString(6));
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            son.Controls.Add(tr);
        }
        sdr.Close();
        SqlCommand smd2 = new SqlCommand("select * from Payway where isshow='y'  order by sort", conn);
        SqlDataReader sdr2 = smd2.ExecuteReader();
        while (sdr2.Read())
        {
            tr = new TableRow();
            tc = new TableCell();
            r0 = new RadioButton();
            r0.CssClass = "carttitle2";
            r0.Text = sdr2.GetString(5);
            r0.GroupName = "pay";
            r0.Attributes.Add("onclick", "b(" + sdr2.GetInt32(0) + "," + this.counttotal.Text + ")");
            tc.Controls.Add(r0);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc = new TableCell();
            l1 = new Label();
            l1.Text = "";
            l1.CssClass = "carttitle2";
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc.HorizontalAlign = HorizontalAlign.Left;
            pay.Controls.Add(tr);
            tr = new TableRow();
            tc = new TableCell();
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc.ColumnSpan = 2;
            l1 = new Label();
            l1.Text = Server.HtmlDecode(sdr2.GetString(7)).Replace("http://127.0.0.1/", "../");
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            pay.Controls.Add(tr);
            tr = new TableRow();
            tc = new TableCell();
            tc.HorizontalAlign = HorizontalAlign.Left;
            tc.ColumnSpan = 2;
            tr.Height = 10;
            tr.Controls.Add(tc);
            pay.Controls.Add(tr);
        }
        sdr2.Close();
        conn.Close();
    }
    #endregion
    protected void cotinu_Click(object sender, EventArgs e)
    {
        this.Panel2.Visible = true;
        this.Panel3.Visible = false;
        string UserName = this.reguser.Text.ToString().Trim();
        string PassWord = this.regpwd2.Text.ToString().Trim();
            SqlConnection conn = CDatabase.wtoconn();
            conn.Open();
            if (Session["Wtouser"] != "vipadmin")
            {
                string sqlstr = "update MemberVIP set logintimes=logintimes+1,enddate='" + DateTime.Now.ToString() + "' where vipusername='" + UserName + "' and vipuserpwd='" + PassWord + "'";
                TOPdo.Execsql(sqlstr);
            }

            SqlDataAdapter sdae = new SqlDataAdapter("select * from ServiceArea", conn);
            DataSet dds = new DataSet();
            sdae.Fill(dds, "sa");
            this.txtpostadd.DataSource = dds;
            this.txtpostadd.DataTextField = "AreaName";
            this.txtpostadd.DataValueField = "id";
            this.txtpostadd.DataBind();

            SqlCommand smd = new SqlCommand("select * from  MemberVIP where vipusername='" + UserName + "' and vipuserpwd='" + PassWord + "'", conn);
            SqlDataReader sdr = smd.ExecuteReader();
            sdr.Read();
            Session["Wtouser"] = "vipadmin";
            Session["wtouserid"] = sdr.GetInt32(0);
            Session["vipname"] = sdr.GetString(2);
            string sqlstr2 = "update cart set userid=" + sdr.GetInt32(0) + " where userid=" + Session["userid"];
            TOPdo.Execsql(sqlstr2);
            Session["userid"] = Convert.ToString(sdr.GetInt32(0));
            this.Panel2.Visible = true;
            this.txtemail.Text = sdr.GetString(7);
            sdr.Close();
            string Cuserid = Session["userid"].ToString().Trim();
            this.Panel2.Visible = true;
            SqlConnection connsc = CDatabase.wtoconn();
            connsc.Open();
            SqlCommand smd8 = new SqlCommand("select * from cart  where userid=" + Cuserid, connsc);
            SqlDataReader sdr8 = smd8.ExecuteReader();
            if (sdr8.HasRows == false)
            {
                Response.Write("购物车没产品");
                sdr8.Close();
                connsc.Close();
            }
            sdr8.Close();

            connsc.Close();
            //从购物车中清除单一产品
            l1.Text = "货号";
            l2.Text = "商品名称";
            l3.Text = "优惠价格";
            l4.Text = "数量";
            l5.Text = "小计";
            TableRow tr;
            TableCell tc;
            tr = new TableRow();
            tr.HorizontalAlign = HorizontalAlign.Center;
            tc = new TableCell();
            tc.Controls.Add(l1);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l2);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l3);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l4);
            tr.Controls.Add(tc);
            tc = new TableCell();
            tc.Controls.Add(l5);
            tr.Controls.Add(tc);
            TB2.Controls.Add(tr);
            TB2.HorizontalAlign = HorizontalAlign.Center;
            tr.CssClass = "carttr";

            ImageButton img1;
            SqlCommand smd2 = new SqlCommand("select * from cart where userid=" + Cuserid, conn);
            SqlDataReader sdra = smd2.ExecuteReader();

            Label lbl1 = new Label();
            TableCell tc2;
            TextBox txtBox;
            decimal counttotal = 0;
            while (sdra.Read())
            {
                l1 = new Label();
                SqlConnection connid = CDatabase.wtoconn();
                connid.Open();
                SqlCommand smdid = new SqlCommand("select ProductsNo from ProductInfo where id=" + sdra.GetInt32(2), connid);
                l1.Text = Convert.ToString(smdid.ExecuteScalar());
                connid.Close();
                smdid.Cancel();
                tr = new TableRow();
                tr.CssClass = "carttrM";
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = sdra.GetString(7);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = " ￥：" + Convert.ToString(sdra.GetDecimal(4).ToString("0.00"));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);

                l1 = new Label();
                l1.Text = Convert.ToString(sdra.GetInt32(3));
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                l1 = new Label();
                l1.Text = "￥：" + Convert.ToString(sdra.GetInt32(3) * Convert.ToDecimal(sdra.GetDecimal(4).ToString("0.00")));
                counttotal += sdra.GetInt32(3) * sdra.GetDecimal(4);
                tc = new TableCell();
                tc.Controls.Add(l1);
                tr.Controls.Add(tc);


                TB2.Controls.Add(tr);
            }
            this.dsp();
            TB2.CellPadding = 0;
            TB2.CellSpacing = 0;
            TB2.CssClass = "cartTB2";
            sdra.Close();
            this.counttotal.Text = Convert.ToString(counttotal.ToString("0.00"));
            SqlCommand freesmd = new SqlCommand("select freesonfei from SystemBasicInformation", conn);
            int freeint = Convert.ToInt32(freesmd.ExecuteScalar());
            if (freeint>Convert.ToInt32(this.counttotal.Text))
            {
                SqlCommand sonfei = new SqlCommand("select sonfei from SystemBasicInformation", conn);
                Session["sonfei"] = Convert.ToString(sonfei.ExecuteScalar());
                ordermoney.Text = Convert.ToString(Convert.ToDecimal(counttotal.ToString("0.00")) + Convert.ToDecimal(Session["sonfei"].ToString()));
                this.sonfei.Text = Session["sonfei"].ToString();
                this.sflal.Text = Session["sonfei"].ToString();
                this.link.Text = "购足<b><font color=red> " + freeint + "</b> </font>元；我们将免费送货上门;";
                link.PostBackUrl = "~/";
                this.link.Visible = true;
            }
            else
            {
                ordermoney.Text = Convert.ToString(counttotal.ToString("0.00"));
                this.link.Text = " 您购买金额超过了<b><font color=red> " + freeint + "</b> </font>元，我们将免费送货上门;";
            }
            conn.Close();
    }
    protected void rereg_Click(object sender, EventArgs e)
    {
        string UserName = this.reguser.Text.ToString().Trim();
        string PassWord = this.regpwd2.Text.ToString().Trim();
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        if (Session["Wtouser"] != "vipadmin")
        {
            string sqlstr = "update MemberVIP set logintimes=logintimes+1,enddate='" + DateTime.Now.ToString() + "' where vipusername='" + UserName + "' and vipuserpwd='" + PassWord + "'";
            TOPdo.Execsql(sqlstr);
        }
        SqlCommand smd = new SqlCommand("select * from  MemberVIP where vipusername='" + UserName + "' and vipuserpwd='" + PassWord + "'", conn);
        SqlDataReader sdr = smd.ExecuteReader();
        sdr.Read();
        string sqlstr2 = "update cart set userid=" + sdr.GetInt32(0) + " where userid=" + Session["userid"];
        TOPdo.Execsql(sqlstr2);
        Session["userid"] = Convert.ToString(sdr.GetInt32(0));
        Session["times"] = "0";
        Session["Wtouser"] = "vipadmin";
        Session["wtouserid"] = sdr.GetInt32(0);
        Session["vipname"] = sdr.GetString(2);
        Session["id"] = Convert.ToString(sdr.GetInt32(0));
        //int tme = 1;
        //if (tme == 1)
        //{
        //    Response.Write("<script>alert('亲爱的" + sdr.GetString(2) + ",感谢您莅临我们购物网站\\n您上次登录日期：" + sdr.GetDateTime(20) + "。\\n共登录次数：" + Convert.ToString(sdr.GetInt32(16)) + "')</script>");
        //    tme = 2;
        //}
        sdr.Close();
        conn.Close();
        Response.Redirect("~/china/vipmain.aspx?doing=editgr");
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        # region 行变色
        int i;
        int g = 0;
        //执行循环，保证每条数据都可以更新
        for (i = 0; i < GridView1.Rows.Count; i++)
        {
            //首先判断是否是数据行
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#f3f3f3'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
            }
            g++;
        }
        //如果是绑定数据行 
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //鼠标经过时，行背景色变 
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#f3f3f3'");
            //鼠标移出时，行背景色变 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
        }
        # endregion
        //如果是绑定数据行 
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
        //    {
        //        ((HyperLink)e.Row.Cells[5].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
        //    }
        //}
    }
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        TextBox txtbox;
        string sql="";
        for (int j = 0; j < GridView1.Rows.Count; j++)
        {
            txtbox = (TextBox)GridView1.Rows[j].FindControl("txtamount");
            Doadmin.Execsql("update cart set amount="+txtbox.Text+" where id="+GridView1.DataKeys[j].Value);
        }
        Response.Redirect("~/china/cart.aspx");
    }
    protected void LinkButton4_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/");
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        TextBox txtbox;
        string sql = "";
        for (int j = 0; j < GridView1.Rows.Count; j++)
        {
            txtbox = (TextBox)GridView1.Rows[j].FindControl("txtamount");
            Doadmin.Execsql("update cart set amount=" + txtbox.Text + " where id=" + GridView1.DataKeys[j].Value);
        }
        Response.Redirect("~/china/cart.aspx");
    }
}
