📄 mygood.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace shopping.受保护窗体
{
/// <summary>
/// Mygood 的摘要说明。
/// </summary>
public class Mygood : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
Response.Write(Session["username"].ToString()+"你好!你购买的商品为>>");
if(!Page.IsPostBack)
{
DataGrid();
}
}
private void DataGrid()
{
string str="Provider=Microsoft.Jet.OleDb.4.0;";
str+=@"Data Source=";
str+=Server.MapPath("usergoods.mdb");
OleDbConnection conn=new OleDbConnection(str);
conn.Open();
string strsql="select * from shopping where 客户名='"+Session["username"].ToString()+"'";
OleDbCommand comm=new OleDbCommand(strsql,conn);
comm.CommandType=CommandType.Text;
OleDbDataAdapter oda=new OleDbDataAdapter();
oda.SelectCommand=comm;
DataTable da= new DataTable("shopping");
DataSet ds=new DataSet();
DataTableCollection dc=ds.Tables;
dc.Add(da);
oda.Fill(da);
DataView dv=ds.Tables["shopping"].DefaultView;
DataGrid1.DataSource=dv;
DataGrid1.DataBind();
conn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Response.Redirect("charge.aspx?check="+e.Item.Cells[0].Text);
}
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strcnn="Provider=Microsoft.Jet.OleDb.4.0;";
strcnn+=@"Data Source=";
strcnn+=Server.MapPath("usergoods.mdb");
OleDbConnection conn=new OleDbConnection(strcnn);
conn.Open();
string strsql="select 数量 from shopping where 客户名='"+Session["username"].ToString()+"' and 商品ID='"+e.Item.Cells[0].Text+"'";
OleDbCommand comm=new OleDbCommand(strsql,conn);
comm.CommandType=CommandType.Text;
int num=(int)comm.ExecuteScalar();
num--;
if(num==0)
{
comm.CommandText="delete from shopping where 商品ID='"+e.Item.Cells[0].Text+"' and 客户名='"+Session["username"].ToString()+"'";
comm.ExecuteNonQuery();
}
else
{
comm.CommandText="select 价格 from goods where 商品号='"+e.Item.Cells[0].Text+"'";
int money=(int)comm.ExecuteScalar();
comm.CommandText="select 应付金额 from shopping where 商品ID='"+e.Item.Cells[0].Text+"' and 客户名='"+Session["username"].ToString()+"'";
int payAll=(int)comm.ExecuteScalar();
payAll-=money;
comm.CommandText="update shopping set 数量='"+num.ToString()+"',应付金额='"+payAll.ToString()+"' where 商品ID='"+e.Item.Cells[0].Text+"' and 客户名='"+Session["username"].ToString()+"'";
comm.ExecuteNonQuery();
}
comm.CommandText="select 数量 from goods where 商品号='"+e.Item.Cells[0].Text+"'";
int num1=(int)comm.ExecuteScalar();
num1++;
comm.CommandText="update goods set 数量='"+num1.ToString()+"' where 商品号='"+e.Item.Cells[0].Text+"'";
comm.ExecuteNonQuery();
Label1.Text="退货成功!";
conn.Close();
DataGrid();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -