📄 s_stockmanger.aspx.cs
字号:
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.Configuration;
namespace Supermart
{
/// <summary>
/// S_stockManger 的摘要说明。
/// </summary>
public class S_stockManger : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Image Image4;
protected System.Web.UI.WebControls.Image Image1;
protected System.Web.UI.WebControls.DropDownList ddl_mertype;
protected System.Web.UI.WebControls.Image Image2;
protected System.Web.UI.WebControls.Image Image5;
protected System.Web.UI.WebControls.DataGrid depotManger;
private string strConn=System.Configuration.ConfigurationSettings.AppSettings["SQLCONNECTION"];
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
Bindddl_mertype();
Bind_depotlist();
}
// 在此处放置用户代码以初始化页面
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.ddl_mertype.SelectedIndexChanged += new System.EventHandler(this.ddl_mertype_SelectedIndexChanged);
this.depotManger.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.depotManger_PageIndexChanged);
this.depotManger.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.depotManger_CancelCommand);
this.depotManger.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.pricelist_EditCommand);
this.depotManger.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.depotManger_UpdateCommand);
this.depotManger.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.depotManger_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
public void Bindddl_mertype()
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("select * from type",con);
SqlDataReader sdr=cmd.ExecuteReader();
this.ddl_mertype.DataSource=sdr;
this.ddl_mertype.DataTextField="typeName";
this.ddl_mertype.DataValueField="typeID";
this.ddl_mertype.DataBind();
con.Close();
sdr.Close();
}
private void pricelist_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.depotManger.EditItemIndex=e.Item.ItemIndex;
this.Bind_depotlist();
}
public void Bind_depotlist()
{
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select merchandise.merID,merchandise.merName,type.typeName,merchandise.merBit,merchandise.stock,merchandise.cost,depot.depotName from merchandise,depot,type where merchandise.depotID=depot.depotID and merchandise.typeID=type.typeID and type.typeName='"+this.ddl_mertype.SelectedItem.Text+"'",con);
DataSet ds=new DataSet();
sda.Fill(ds,"title");
sda.Dispose();
this.depotManger.DataKeyField="merID";
this.depotManger.DataSource=ds.Tables["title"].DefaultView;
this.depotManger.DataBind();
con.Close();
}
private void depotManger_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.depotManger.EditItemIndex=-1;
this.Bind_depotlist();
}
private void depotManger_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string merID=this.depotManger.DataKeys[e.Item.ItemIndex].ToString();
string depotName=((TextBox)(e.Item.Cells[5].Controls[0])).Text;
SqlConnection con=new SqlConnection(strConn);
con.Open();
SqlCommand cmd=new SqlCommand("update merchandise set merchandise.depotID=(select depotID from depot where depotName='"+depotName+"') where merID='"+merID+"'",con);
cmd.ExecuteNonQuery();
this.depotManger.EditItemIndex=-1;
this.Bind_depotlist();
}
private void ddl_mertype_SelectedIndexChanged(object sender, System.EventArgs e)
{
Bind_depotlist();
}
private void depotManger_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","c=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=c");
}
}
private void depotManger_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.depotManger.CurrentPageIndex=e.NewPageIndex;
this.Bind_depotlist();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -