📄 next.aspx.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 + -