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

📄 bookord_view.aspx.cs

📁 是一个教材管理系统
💻 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>
	/// BookOrd_view 的摘要说明。
	/// </summary>
	public class BookOrd_view : System.Web.UI.Page
	{
		protected System.Data.SqlClient.SqlDataAdapter sqlAdapter;
		protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		protected BookManager.dsOrd_view dsOrd_viewInfo;
		protected System.Web.UI.WebControls.DataGrid dgOrdView;
		protected System.Web.UI.WebControls.Button btBack;
		protected System.Data.SqlClient.SqlConnection sqlConn;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			if(!IsPostBack)
			{
				ViewState["BackUrl"]=Request.UrlReferrer.ToString();
				this.DataBinds();
				if(dgOrdView.Items.Count==0)
				{
					Response.Redirect("NoData.aspx");
				}

			}
		}
		private void DataBinds()
		{
			sqlAdapter.Fill(dsOrd_viewInfo);
			dgOrdView.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.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlConn = new System.Data.SqlClient.SqlConnection();
			this.dsOrd_viewInfo = new BookManager.dsOrd_view();
			((System.ComponentModel.ISupportInitialize)(this.dsOrd_viewInfo)).BeginInit();
			this.dgOrdView.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgOrdView_ItemCreated);
			this.dgOrdView.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgOrdView_ItemCommand);
			this.dgOrdView.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgOrdView_DeleteCommand);
			this.btBack.Click += new System.EventHandler(this.btBack_Click);
			// 
			// sqlAdapter
			// 
			this.sqlAdapter.SelectCommand = this.sqlSelectCommand1;
			this.sqlAdapter.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																								 new System.Data.Common.DataTableMapping("Table", "tblBookAttribute", new System.Data.Common.DataColumnMapping[] {
																																																					 new System.Data.Common.DataColumnMapping("BookAttribute", "BookAttribute"),
																																																					 new System.Data.Common.DataColumnMapping("Storage", "Storage"),
																																																					 new System.Data.Common.DataColumnMapping("InfoID", "InfoID"),
																																																					 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("BookMark", "BookMark"),
																																																					 new System.Data.Common.DataColumnMapping("Pic", "Pic"),
																																																					 new System.Data.Common.DataColumnMapping("Attribute", "Attribute"),
																																																					 new System.Data.Common.DataColumnMapping("ID", "ID"),
																																																					 new System.Data.Common.DataColumnMapping("Expr1", "Expr1")})});
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = @"SELECT tblBookAttribute.BookAttribute, tblBookStorage.Storage, tblBookInfo.ID AS InfoID, tblBookInfo.BookName, tblBookInfo.Author, tblBookInfo.Price, tblBookInfo.Publish, tblBookInfo.BookMark, tblBookInfo.Pic, tblBookInfo.Attribute, tblBookAttribute.ID, tblBookStorage.ID AS Expr1 FROM tblBookAttribute INNER JOIN tblBookInfo ON tblBookAttribute.ID = tblBookInfo.Attribute INNER JOIN tblBookStorage ON tblBookInfo.ID = tblBookStorage.BookId WHERE (tblBookInfo.Attribute = 2) ORDER BY tblBookInfo.ID DESC";
			this.sqlSelectCommand1.Connection = this.sqlConn;
			// 
			// 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";
			// 
			// dsOrd_viewInfo
			// 
			this.dsOrd_viewInfo.DataSetName = "dsOrd_view";
			this.dsOrd_viewInfo.Locale = new System.Globalization.CultureInfo("zh-CN");
			this.Load += new System.EventHandler(this.Page_Load);
			((System.ComponentModel.ISupportInitialize)(this.dsOrd_viewInfo)).EndInit();

		}
		#endregion

		private void ExecSql(string sqlStr)
		{
			SqlCommand cmd=new SqlCommand(sqlStr,sqlConn);
			sqlConn.Open();
			cmd.ExecuteNonQuery();
			sqlConn.Close();
		}

		private void btBack_Click(object sender, System.EventArgs e)
		{
			if(ViewState["BackUrl"]!=null)
			{
				Response.Redirect(ViewState["BackUrl"].ToString());
			}
		}

		private void dgOrdView_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			string sqlStr;
			e.Item.Attributes.Add("onclick", "return confirm('您真的要删除所选项吗?');");
			sqlStr="delete  from tblBookInfo where ID="+e.Item.Cells[0].Text.ToString();
			this.ExecSql(sqlStr);
			this.DataBinds();
			if( dgOrdView.Items.Count==0)
			{
				Response.Redirect("NoData.aspx");
			}
		}

		private void dgOrdView_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			switch(e.Item.ItemType)
			{
				case ListItemType.Item:
				case ListItemType.EditItem:
				case ListItemType.AlternatingItem:
					Button 	  myDeleteButton = (Button)e.Item.FindControl("btDelete");
					myDeleteButton.Text = "删除";
					myDeleteButton.Attributes.Add("onclick", "return confirm('您真的要删除吗?');");
					break;
			}
		}

		private void dgOrdView_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if(e.CommandName=="UserDelete")
				this.dgOrdView_DeleteCommand(source,e);
		}
	}
}

⌨️ 快捷键说明

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