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

📄 s_pricemanger.aspx.cs

📁 asp.net+sql2000超市管理系统
💻 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.Configuration;
using System.Data.SqlClient;

namespace Supermart
{
	/// <summary>
	/// S_priceManger 的摘要说明。
	/// </summary>
	public class S_priceManger : 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_merName;
		protected System.Web.UI.WebControls.DropDownList ddl_mertype;
		protected System.Web.UI.WebControls.Button btn_check;
		protected System.Web.UI.WebControls.Image Image5;
		protected System.Web.UI.WebControls.DataGrid pricelist;
		protected System.Web.UI.WebControls.DataGrid pricelist2;
		private string strConn=System.Configuration.ConfigurationSettings.AppSettings["SQLCONNECTION"];
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!this.IsPostBack)
			{
				Bind_pricelist();
				Bindddl_mertype();
				Bindddl_merName();
				Bind_pricelist();
			}
			// 在此处放置用户代码以初始化页面
		}

		#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.ddl_merName.SelectedIndexChanged += new System.EventHandler(this.ddl_merName_SelectedIndexChanged);
			this.btn_check.Click += new System.EventHandler(this.btn_check_Click);
			this.pricelist.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.pricelist_PageIndexChanged);
			this.pricelist.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.pricelist_CancelCommand);
			this.pricelist.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.pricelist_EditCommand);
			this.pricelist.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.pricelist_UpdateCommand);
			this.pricelist.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.pricelist_ItemDataBound);
			this.pricelist2.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.pricelist2_PageIndexChanged);
			this.pricelist2.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.pricelist2_CancelCommand);
			this.pricelist2.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.pricelist2_EditCommand);
			this.pricelist2.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.pricelist2_UpdateCommand);
			this.pricelist2.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.pricelist2_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();
		}
		public void Bindddl_merName()
		{
			SqlConnection con=new SqlConnection(strConn);
			con.Open();
			SqlCommand cmd=new SqlCommand("select * from merchandise where typeID='"+this.ddl_mertype.SelectedValue+"'",con);
			SqlDataReader sdr=cmd.ExecuteReader();
			this.ddl_merName.DataSource=sdr;
			this.ddl_merName.DataTextField="merName";
			this.ddl_merName.DataValueField="merID";
			this.ddl_merName.DataBind();
			con.Close();
			sdr.Close();
		}

		private void ddl_mertype_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Bindddl_merName();
			Bind_pricelist();
			this.pricelist2.Visible=false;
			this.pricelist.Visible=true;
		}

		private void ddl_merName_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Bind_pricelist();
			this.pricelist2.Visible=false;
			this.pricelist.Visible=true;
		}
		public void Bind_pricelist()
		{
			SqlConnection con=new SqlConnection(strConn);
			con.Open();
			SqlDataAdapter sda=new SqlDataAdapter();
			sda.SelectCommand=new SqlCommand("select * from merchandise where merID='"+this.ddl_merName.SelectedValue+"'",con);
			DataSet ds=new DataSet();
			sda.Fill(ds,"title");
			sda.Dispose();
			this.pricelist.DataKeyField="merID";
			this.pricelist.DataSource=ds.Tables["title"].DefaultView;
			this.pricelist.DataBind();
			con.Close();
		}
		public void Bind_pricelist2()
		{
			SqlConnection con=new SqlConnection(strConn);
			con.Open();
			SqlDataAdapter sda=new SqlDataAdapter();
			sda.SelectCommand=new SqlCommand("select * from merchandise where tradePrice='未定' or retailPrice='未定'",con);
			DataSet ds=new DataSet();
			sda.Fill(ds,"title");
			sda.Dispose();
			this.pricelist2.DataKeyField="merID";
			this.pricelist2.DataSource=ds.Tables["title"].DefaultView;
			this.pricelist2.DataBind();
			con.Close();
		}

		private void pricelist_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			this.pricelist.EditItemIndex=e.Item.ItemIndex;
			this.Bind_pricelist();
		}

		private void pricelist_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			this.pricelist.EditItemIndex=-1;
			this.Bind_pricelist();
		}

		private void pricelist_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			string merID=this.pricelist.DataKeys[e.Item.ItemIndex].ToString();
			string tradePrice=((TextBox)(e.Item.Cells[4].Controls[0])).Text;
			string retailPrice=((TextBox)(e.Item.Cells[5].Controls[0])).Text;
			SqlConnection con=new SqlConnection(strConn);
			con.Open();
			SqlCommand cmd=new SqlCommand("update merchandise set tradePrice='"+tradePrice+"',retailPrice='"+retailPrice+"' where merID='"+merID+"'",con);
			cmd.ExecuteNonQuery();
			this.pricelist.EditItemIndex=-1;
			this.Bind_pricelist();
		}

		private void btn_check_Click(object sender, System.EventArgs e)
		{
			Bind_pricelist2();
			this.pricelist.Visible=false;
			this.pricelist2.Visible=true;
		}

		private void pricelist2_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			this.pricelist2.EditItemIndex=e.Item.ItemIndex;
			this.Bind_pricelist2();
		}

		private void pricelist2_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			this.pricelist2.EditItemIndex=-1;
			this.Bind_pricelist2();
		}

		private void pricelist2_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			string merID=this.pricelist2.DataKeys[e.Item.ItemIndex].ToString();
			string tradePrice=((TextBox)(e.Item.Cells[4].Controls[0])).Text;
			string retailPrice=((TextBox)(e.Item.Cells[5].Controls[0])).Text;
			SqlConnection con=new SqlConnection(strConn);
			con.Open();
			SqlCommand cmd=new SqlCommand("update merchandise set tradePrice='"+tradePrice+"',retailPrice='"+retailPrice+"' where merID='"+merID+"'",con);
			cmd.ExecuteNonQuery();
			this.pricelist.EditItemIndex=-1;
			this.Bind_pricelist2();
		}

		private void pricelist_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 pricelist2_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 pricelist_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			this.pricelist.CurrentPageIndex=e.NewPageIndex;
			this.Bind_pricelist();
		}

		private void pricelist2_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
		{
			this.pricelist2.CurrentPageIndex=e.NewPageIndex;
			this.Bind_pricelist2();
		}
	}
}

⌨️ 快捷键说明

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