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

📄 stsale.aspx.cs

📁 数据库:Microsoft SQL Server 2000。 技术平台:Microsoft .NET Framework 2.0.0.0版本。 IIS:Internet Informati
💻 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 STcontract.STUser
{
	/// <summary>
	/// STSale 的摘要说明。
	/// </summary>
	public class STSale : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid STmyGrid;
		protected System.Web.UI.WebControls.Label STStat;
		protected System.Web.UI.WebControls.TextBox STSaleNum;
		protected System.Web.UI.WebControls.Button ST_ok;
		protected System.Web.UI.WebControls.DropDownList ST_Prod;
		protected System.Web.UI.WebControls.TextBox STStartTime;
		protected System.Web.UI.WebControls.TextBox STEndTime;
		protected System.Web.UI.WebControls.Label STDepName;

//		private string STNickName;
//		private string STDepID;
		protected System.Web.UI.WebControls.Label ST_Warn;
		SqlConnection STconn;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(Session["STNickName"] != null)
			{
				//获得数据库连接字符串
				string STconnection = ConfigurationSettings.AppSettings["strconnection"];
				//创建数据库连接
				STconn = new SqlConnection(STconnection);
				if(!IsPostBack)
				{
					//自定义BindGrid ()方法,加载自己连锁店销售产品的统计信息
					BindGrid();
					//得到连锁店名字
					STconn.Open();
					string STNickName =  Session["STNickName"].ToString();
					string STmysql = "select STDep.* from STDep,STUser where STUser.STDepID = STDep.STDepID and STUser.STNickName = '" + STNickName + "' and STUser.STNoAdmin = 0";
					SqlCommand STcmd2 = new SqlCommand(STmysql,STconn);
					SqlDataReader STsdr2 = STcmd2.ExecuteReader();
					while(STsdr2.Read())
					{
						Session["STDepID"] = STsdr2["STDepID"];
						Session["STDepName"] = STsdr2["STDepName"];
						STDepName.Text = Session["STDepName"].ToString();
					}
					STconn.Close();
					//加载产品下拉列表框
					STconn.Open ();
					string STmysql1 = "select * from STProd";
					SqlCommand STcmd1 =new SqlCommand(STmysql1,STconn);
					SqlDataReader STdr1 = STcmd1.ExecuteReader ();
					ST_Prod.Items.Add(new ListItem("","-1") );
					while(STdr1.Read ())
					{
						ST_Prod.Items.Add(new ListItem(STdr1["STProdName"].ToString() ,STdr1["STProdID"].ToString()) );
					}
					STconn.Close ();
				}
			}
			else
			{
				Response.Redirect("../Index.aspx");
			}
		
			
		}

		//处理分页
		public void STmyGrid_Page(object sender,DataGridPageChangedEventArgs e)
		{
			STmyGrid.CurrentPageIndex=e.NewPageIndex;
			BindGrid();
		}
		
		//加载自己连锁店销售产品的统计信息
		public void BindGrid()
		{
			string STNickName = Session["STNickName"].ToString();
			string STstrsql="select STSale.ID,STDep.STDepName,STProdName,STSale.STSaleNum,STSale.STStartTime,STSale.STEndTime from STSale,STDep,STProd,STUser where STSale.STProdID = STProd.STProdID and STSale.STDepID = STDep.STDepID and STUser.STDepID = STDep.STDepID and STUser.STNickName = '" + STNickName + "'";
			SqlDataAdapter STsda=new SqlDataAdapter(STstrsql,STconn);
			DataSet STds=new DataSet();
			STsda.Fill(STds);
			STmyGrid.DataSource = STds;
			
			STmyGrid.DataBind();
		
		}

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

		}
		#endregion

		private void ST_ok_Click(object sender, System.EventArgs e)
		{
			if(ST_Prod.SelectedItem.Value != "-1")
			{
				string STDepID = Session["STDepID"].ToString();
				
				//创建数据库SqlCommand对象
				SqlCommand STcmd =new SqlCommand("insert_STSale_1",STconn);
				//获取存储过程名
				STcmd.CommandType=CommandType.StoredProcedure;
				//向SqlCommand对象添加参数
				STcmd.Parameters.Add(new SqlParameter("@STProdID",SqlDbType.Int,10));
				STcmd.Parameters.Add(new SqlParameter("@STDepID",SqlDbType.VarChar,50));
				STcmd.Parameters.Add(new SqlParameter("@STSaleNum",SqlDbType.Decimal,9));
				STcmd.Parameters.Add(new SqlParameter("@STStartTime",SqlDbType.DateTime,8));
				STcmd.Parameters.Add(new SqlParameter("@STEndTime",SqlDbType.DateTime,8));
				//向参数赋值
				STcmd.Parameters["@STDepID"].Value = STDepID;
				STcmd.Parameters["@STProdID"].Value = ST_Prod.SelectedItem.Value;
				STcmd.Parameters["@STSaleNum"].Value = STSaleNum.Text;
				STcmd.Parameters["@STStartTime"].Value = STStartTime.Text;
				STcmd.Parameters["@STEndTime"].Value = STEndTime.Text;
				STcmd.Connection.Open();
				try
				{
					//执行sql语句
					STcmd.ExecuteNonQuery();
					Response.Redirect("STSale.aspx");
				}
				catch(SqlException)
				{
					ST_Warn.Text="添加失败";
					ST_Warn.Style["color"]="red";
				}
				STcmd.Connection.Close();
			}
	

	
		}
	}
}

⌨️ 快捷键说明

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