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

📄 bookbuying.aspx.cs

📁 教材管理系统 asp设计本文主要介绍了基于JSP技术的电子商务动态网站
💻 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;

namespace BookManager
{
	/// <summary>
	/// BookBuying 的摘要说明。
	/// </summary>
	public class BookBuying : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Button btSubmit;
		protected System.Web.UI.WebControls.Button btReset;
		protected System.Data.SqlClient.SqlDataAdapter sqlAdapter;
		protected BookManager.dsBookOrd dsBookPreOrd;
		protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
		protected System.Data.SqlClient.SqlConnection sqlConn;
		protected System.Web.UI.WebControls.Button btBoughtSum;
		protected System.Web.UI.WebControls.DataGrid dgBookOrd;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			btSubmit.Attributes.Add("onclick", "return confirm('您确实要提交该信息吗?');");
			if(!IsPostBack)
			{
				
				if(Session["Role"].ToString()!="2")
				{
					Response.Redirect("NotAllow.htm");
					return;
				}
				this.BindDat();
				if(dgBookOrd.Items.Count==0)
				{
					Response.Redirect("NoBuying.htm");
				}
				
			}
			if(dgBookOrd.Items.Count==0)
			{
				Response.Redirect("NoBuying.htm");
			}
		}

		private void BindDat()
		{
			sqlAdapter.Fill(dsBookPreOrd);
			dgBookOrd.DataBind();

		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{    
			this.sqlAdapter = new System.Data.SqlClient.SqlDataAdapter();
			this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlConn = new System.Data.SqlClient.SqlConnection();
			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.dsBookPreOrd = new BookManager.dsBookOrd();
			((System.ComponentModel.ISupportInitialize)(this.dsBookPreOrd)).BeginInit();
			this.dgBookOrd.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgBookOrd_ItemDataBound);
			this.btSubmit.Click += new System.EventHandler(this.btSubmit_Click);
			this.btReset.Click += new System.EventHandler(this.btReset_Click);
			this.btBoughtSum.Click += new System.EventHandler(this.btBoughtSum_Click);
			// 
			// sqlAdapter
			// 
			this.sqlAdapter.InsertCommand = this.sqlInsertCommand1;
			this.sqlAdapter.SelectCommand = this.sqlSelectCommand1;
			this.sqlAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																								 new System.Data.Common.DataTableMapping("Table", "BookOrd_View", new System.Data.Common.DataColumnMapping[] {
																																																				 new System.Data.Common.DataColumnMapping("BookAttribute", "BookAttribute"),
																																																				 new System.Data.Common.DataColumnMapping("ID", "ID"),
																																																				 new System.Data.Common.DataColumnMapping("BookName", "BookName"),
																																																				 new System.Data.Common.DataColumnMapping("Author", "Author"),
																																																				 new System.Data.Common.DataColumnMapping("Price", "Price"),
																																																				 new System.Data.Common.DataColumnMapping("Publish", "Publish"),
																																																				 new System.Data.Common.DataColumnMapping("Storage", "Storage")})});
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO BookOrd_View(BookAttribute, BookName, Author, Price, Publish, Storage" +
				") VALUES (@BookAttribute, @BookName, @Author, @Price, @Publish, @Storage); SELEC" +
				"T BookAttribute, ID, BookName, Author, Price, Publish, Storage FROM BookOrd_View" +
				"";
			this.sqlInsertCommand1.Connection = this.sqlConn;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BookAttribute", System.Data.SqlDbType.VarChar, 20, "BookAttribute"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@BookName", System.Data.SqlDbType.VarChar, 30, "BookName"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Author", System.Data.SqlDbType.VarChar, 25, "Author"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Price", System.Data.SqlDbType.NVarChar, 19, "Price"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Publish", System.Data.SqlDbType.VarChar, 20, "Publish"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Storage", System.Data.SqlDbType.Int, 4, "Storage"));
			// 
			// sqlConn
			// 
			this.sqlConn.ConnectionString = "workstation id=QMX;packet size=4096;user id=sa;data source=\"QMX\\THUNDER\";persist " +
				"security info=True;initial catalog=BookManager;password=gliu0307";
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT BookAttribute, ID, BookName, Author, Price, Publish, Storage FROM BookOrd_" +
				"View";
			this.sqlSelectCommand1.Connection = this.sqlConn;
			// 
			// dsBookPreOrd
			// 
			this.dsBookPreOrd.DataSetName = "dsBookOrd";
			this.dsBookPreOrd.Locale = new System.Globalization.CultureInfo("zh-CN");
			this.Load += new System.EventHandler(this.Page_Load);
			((System.ComponentModel.ISupportInitialize)(this.dsBookPreOrd)).EndInit();

		}
		#endregion

		private void btSubmit_Click(object sender, System.EventArgs e)
		{
			this.FindBuying();
		}


		private void ExecuteSql(string strSql)
		{
			try
			{
				
				SqlCommand cmd = new SqlCommand(strSql,sqlConn);
				sqlConn.Open();
				cmd.ExecuteNonQuery();
				sqlConn.Close();
			} 
			catch(Exception e)
			{
				Response.Write("<script language = 'javascript'>alert('"+e.Message+"');</script>") ;
							
			}
		}

		private  void FindBuying()
		{
			int Nochecked=0;
			foreach(DataGridItem dgi in dgBookOrd.Items)
			{
				CheckBox cb = (CheckBox)dgi.FindControl("cbBuying");
				if(cb.Checked)
				{
					//以下执行更新操作
					int nID = int.Parse(dgi.Cells[7].Text);
					string strSql = "update tblBookInfo set Attribute='3'  where ID="+nID;
					this.ExecuteSql(strSql);
				}
				else
				{
					Nochecked+=1;
				}
				
			}
			if(Nochecked==dgBookOrd.Items.Count)
			{
				Response.Write("<script language='javascript'>alert('请选择要订购的教材,再确定!');</script>");
				return;
			}
			this.BindDat();
			if(dgBookOrd.Items.Count==0)
			{
				Response.Redirect("NoBuying.htm");
			}
		}

		private void btReset_Click(object sender, System.EventArgs e)
		{
			foreach(DataGridItem dgi in dgBookOrd.Items)
			{
				CheckBox cb = (CheckBox)dgi.FindControl("cbBuying");
				if(cb.Checked)
				{
					cb.Checked=false;
				}
			}
			this.BindDat();
		
		}

		private void dgBookOrd_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			
			if((e.Item.ItemType ==ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item )||(e.Item.ItemType==ListItemType.Separator)) 
			{  
				e.Item.Attributes.Add("onclick","this.style.backgroundColor='#9671D8'");
				e.Item.Attributes.Add("onmouseout", "this.style.backgroundColor='#DEDFDE'"); 
			}
			
		}

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






	}
}

⌨️ 快捷键说明

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