⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 next.aspx.cs

📁 购物车主要是为广大网上顾客购物的资源平台。购物车主要目标是建设在网上对用户进行信息服务互动平台。
💻 CS
字号:
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 Next : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Uid"] == null)
        {
            Response.Redirect("Default.aspx");
        }
        bind();


        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);  // 显示余额
        conn.Open();
        string sql2 = "select Umomey from Userlist where Uid='"+Session["Uid"]+"'";
        SqlCommand cmd2 = new SqlCommand(sql2, conn);
        DataSet ds2 = new DataSet();
        SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
        da2.Fill(ds2);
        this.Label4.Text = ds2.Tables[0].Rows[0][0].ToString();
       
    }
    public void bind()
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        conn.Open();
        string sql = "select Temp.id as 序号,Goods.Gpicture as 照片,Goods.Gname as 名称,Goods.Gprice as 价格,Goods.Gdescribe as 描述 from Temp,Goods where Temp.Gid=Goods.Gid and Uid='"+Session["Uid"]+"'";
        SqlCommand cmd = new SqlCommand(sql, conn);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "序号" };
        GridView1.DataBind();
        int sum = 0;
        for (int i = 0; i < this.GridView1.Rows.Count; i++)
        {
            sum = int.Parse(GridView1.Rows[i].Cells[3].Text.Trim()) + sum;
        }
        this.Label2.Text = sum.ToString();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {   int a=int.Parse(this.Label2.Text);
        int b=int.Parse(this.Label4.Text);
        if (a < b)
        {
            int c = b - a;
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
            conn.Open();
            string sql = "update  userlist set Umomey='" +c+ "'";
            SqlCommand cmd = new SqlCommand(sql, conn);
            if (cmd.ExecuteNonQuery() > 0)
            {
                string sql2 = "delete Temp where Uid='" + Session["Uid"] + "'";
                SqlCommand cmd2 = new SqlCommand(sql2,conn);
                if (cmd2.ExecuteNonQuery() > 0)
                {
                    Response.Redirect("success.aspx");
                }
            }
            conn.Close();

           
        }
        else
        {
            Response.Write("<script> alert('余额不足!');</script>");
        }
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["connstring"].ConnectionString);
        int ID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
        string sql = "delete  from Temp where Id='" + ID + "'";
        conn.Open();
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.ExecuteNonQuery();
        conn.Close();
        bind();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -