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

📄 customer_sale.aspx.cs

📁 用.net开发的一套管理系统,功能比较全,挺好用的啊!
💻 CS
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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;

namespace cms
{
	/// <summary>
	/// customer_sale 的摘要说明。
	/// </summary>
	public class customer_sale : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid Dgd_sale;
		protected System.Web.UI.WebControls.Button Btn_ok;
		protected System.Web.UI.WebControls.Label Lbl_amount;
		protected System.Web.UI.WebControls.Label Lbl_price;
		protected System.Web.UI.WebControls.Button Btn_exit;
		protected System.Web.UI.WebControls.TextBox Tbx_date;
	    SqlConnection cn;
		protected System.Web.UI.WebControls.Label Lbl_note;
		protected System.Web.UI.WebControls.DropDownList Ddl_stat;
		protected System.Web.UI.WebControls.DropDownList Ddl_customer;
		protected System.Web.UI.WebControls.DropDownList Ddl_product;  string mysql;
		private void Page_Load(object sender, System.EventArgs e)
		{//判断用户是否为合法用户
			try
			{
				if(Session["User_power"].ToString ()=="0"||Session["User_power"].ToString ()=="2") ;
				else
				{					
					Response.End ();
				}
			}
			catch
			{
				Response.Write ("您不是合法用户,请登入后再操作,<a href='default.aspx'>返回</a>");
				Response.End ();
			}
			// 在此处放置用户代码以初始化页面
			//客户名称下拉列表框绑定
			string strconn= ConfigurationSettings.AppSettings["dsn"];
			//连接本地计算机的CMS数据库
			SqlConnection cn0= new SqlConnection (strconn);
			if(!IsPostBack)
			{
				cn0.Open ();
				string mysql="select * from customer";
				SqlCommand cm0=new SqlCommand  (mysql,cn0);
				SqlDataReader dr0=cm0.ExecuteReader ();
				while(dr0.Read ())
				{
					Ddl_customer.Items .Add (new ListItem(dr0["Custom_name"].ToString(),dr0["Custom_id"].ToString()) );
				}
				cn0.Close ();
				//产品名称下拉列表框绑定
				cn0.Open ();
				string mysql1="select * from product";
				SqlCommand cm1=new SqlCommand  (mysql1,cn0);
				SqlDataReader dr1=cm1.ExecuteReader ();
				while(dr1.Read ())
				{
					Ddl_product.Items .Add (new ListItem(dr1["Product_name"].ToString() ,dr1["Product_id"].ToString()) );
				}
				cn0.Close ();
			}				
			cn=new SqlConnection(strconn);
			if(!IsPostBack)
			{
				mysql="select custom_sale.*,customer.Custom_name,product.Product_name from custom_sale,customer,product where custom_sale.Custom_id=customer.Custom_id and custom_sale.Product_id=product.Product_id";
				BindGrid();
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.Btn_exit.Click += new System.EventHandler(this.Btn_exit_Click);
			this.Btn_ok.Click += new System.EventHandler(this.Btn_ok_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
		public void DataGrid_Page(object sender,DataGridPageChangedEventArgs e)
		{
			Dgd_sale.CurrentPageIndex=e.NewPageIndex;
			mysql="select custom_sale.*,customer.Custom_name,product.Product_name from custom_sale,customer,product where custom_sale.Custom_id=customer.Custom_id and custom_sale.Product_id=product.Product_id";
			BindGrid();
		}
		public void BindGrid()
		{
			SqlDataAdapter da=new SqlDataAdapter(mysql,cn);
			DataSet ds=new DataSet();
			da.Fill(ds);
			Dgd_sale.DataSource=ds;
			Dgd_sale.DataBind();
		}

		private void Btn_exit_Click(object sender, System.EventArgs e)
		{
			Response.Redirect("customer.aspx");
		}

		public void DataGrid_cancel(object sender,DataGridCommandEventArgs e)
		{
			
			Dgd_sale.EditItemIndex=-1;
			mysql="select custom_sale.*,customer.Custom_name,product.Product_name from custom_sale,customer,product where custom_sale.Custom_id=customer.Custom_id and custom_sale.Product_id=product.Product_id";
			BindGrid();
		}
		
		public void DataGrid_edit(object sender,DataGridCommandEventArgs e)
		{
			if(Session["User_power"].ToString()=="0"||Session["User_power"].ToString ()=="2")
			{
			
				Dgd_sale.EditItemIndex=(int)e.Item.ItemIndex;		
				mysql="select custom_sale.*,customer.Custom_name,product.Product_name from custom_sale,customer,product where custom_sale.Custom_id=customer.Custom_id and custom_sale.Product_id=product.Product_id";
				BindGrid();
			}	
		}
		public void DataGrid_update(object sender,DataGridCommandEventArgs e)
		{
			string strsql="update custom_sale set Custom_id=@Custom_id,Product_id=@Product_id,Product_sale=@Product_sale,Product_price=@Product_price,Product_date=@Product_date where ID=@id";
			SqlCommand cm=new SqlCommand(strsql,cn);
			try
			{
				cm.Parameters.Add(new SqlParameter("@Custom_id",SqlDbType.Char,10));
				cm.Parameters.Add(new SqlParameter("@Product_id",SqlDbType.Char,10));
				cm.Parameters.Add(new SqlParameter("@Product_sale",SqlDbType.Int,4));
				cm.Parameters.Add(new SqlParameter("@Product_price",SqlDbType.Money,8));
				cm.Parameters.Add(new SqlParameter("@Product_date",SqlDbType.Char,10));
				cm.Parameters.Add(new SqlParameter("@id",SqlDbType.Char,10));
				string colvalue=((TextBox)e.Item.Cells[1].Controls[0]).Text;
				cm.Parameters["@Custom_id"].Value=colvalue;
				colvalue=((TextBox)e.Item.Cells[3].Controls[0]).Text;
				cm.Parameters["@Product_id"].Value=colvalue;
				colvalue=((TextBox)e.Item.Cells[5].Controls[0]).Text;
				cm.Parameters["@Product_sale"].Value=colvalue;
				colvalue=((TextBox)e.Item.Cells[6].Controls[0]).Text;
				cm.Parameters["@Product_price"].Value=colvalue;
				colvalue=((TextBox)e.Item.Cells[7].Controls[0]).Text;
				cm.Parameters["@Product_date"].Value=colvalue;
				cm.Parameters["@id"].Value=Dgd_sale.DataKeys[(int)e.Item.ItemIndex];
				cm.Connection.Open();			
				cm.ExecuteNonQuery();
				Lbl_note.Text="编辑成功";
				Dgd_sale.EditItemIndex=-1;
			}
			catch
			{
				Lbl_note.Text="编辑失败";
				Lbl_note.Style["color"]="red";
			}
			cm.Connection.Close();	
			mysql="select custom_sale.*,customer.Custom_name,product.Product_name from custom_sale,customer,product where custom_sale.Custom_id=customer.Custom_id and custom_sale.Product_id=product.Product_id";
			BindGrid();	
		}
		
		public void DataGrid_delete(object sender,DataGridCommandEventArgs e)
		{
			if(Session["User_power"].ToString()=="0")
			{
				string strsql="delete from custom_sale where ID=@id";
				SqlCommand cm=new SqlCommand(strsql,cn);
				cm.Parameters.Add(new SqlParameter("@id",SqlDbType.Char,10));
				cm.Parameters["@id"].Value=Dgd_sale.DataKeys[(int)e.Item.ItemIndex];
				cm.Connection.Open();
				try
				{
					cm.ExecuteNonQuery();
					Lbl_note.Text="删除成功";
				}
				catch
				{
					Lbl_note.Text="删除失败";
					Lbl_note.Style["color"]="red";
				}
				cm.Connection.Close();			
				mysql="select custom_sale.*,customer.Custom_name,product.Product_name from custom_sale,customer,product where custom_sale.Custom_id=customer.Custom_id and custom_sale.Product_id=product.Product_id";
				BindGrid();
			}
		}
		private void Btn_ok_Click(object sender, System.EventArgs e)
		{	Lbl_note.Text ="";
			if(Ddl_stat.SelectedItem.Value=="0")
			{
			string strsql="select Product_sale,Product_price from custom_sale where Custom_id='"+Ddl_customer.SelectedItem.Value+"' and Product_id='"+Ddl_product.SelectedItem.Value+"' and Product_date like '"+Tbx_date.Text+"%'";
			 SqlCommand cm=new SqlCommand(strsql,cn);
			 cn.Open();
			 SqlDataReader dr=cm.ExecuteReader();
				if(dr.Read())
				{
					Lbl_amount.Text="本月销售量为:"+dr[0].ToString();
					Lbl_price.Text="本月销售单价为:"+dr[1].ToString();
				}
				else
				{
						Lbl_amount.Text="本月销售量为:0";
						Lbl_price.Text="本月无销售单价";
				}
				cn.Close();
				cn.Open();
				
			}
			else
			{
				string strsql="select sum(Product_sale),MAX(Product_price) from custom_sale where Custom_id='"+Ddl_customer.SelectedItem.Value+"' and Product_id='"+Ddl_product.SelectedItem.Value+"' and Product_date LIKE '"+Tbx_date.Text+"%'";
				SqlCommand cm=new SqlCommand(strsql,cn);
				cn.Open();
				SqlDataReader dr=cm.ExecuteReader();
				if(dr.Read())
				{
					Lbl_amount.Text="年销售量为:"+dr[0].ToString();
				    Lbl_price.Text="年最高单价为:"+dr[1].ToString();	
				}
				else
				{
					Lbl_amount.Text="年销售量为:0";
					Lbl_price.Text="无年最高单价";
				}       
		        cn.Close();
				}
			    mysql="select custom_sale.*,customer.Custom_name,product.Product_name from custom_sale,customer,product where custom_sale.Custom_id=customer.Custom_id and custom_sale.Product_id=product.Product_id and custom_sale.Custom_id='"+Ddl_customer.SelectedItem.Value+"' and custom_sale.Product_id='"+Ddl_product.SelectedItem.Value+"' and custom_sale.Product_date like '"+Tbx_date.Text+"%'";
				BindGrid();
		}
	}
}

⌨️ 快捷键说明

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