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

📄 backbook.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>
	/// BackBook 的摘要说明。
	/// </summary>
	public class BackBook : System.Web.UI.Page
	{
		protected System.Data.SqlClient.SqlDataAdapter sqlAdapter;
		protected BookManager.dsBookBack dsBookBackInfo;
		protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
		protected System.Data.SqlClient.SqlConnection sqlConn;
		protected System.Web.UI.WebControls.DataGrid dgBackBook;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// 在此处放置用户代码以初始化页面
			
			if(!IsPostBack)
			{
				
								
				if(Session["Role"].ToString()!="2")
				{
					Response.Redirect("NotAllow.htm");
					return;
				}
				this.DataBd();
				if(dgBackBook.Items.Count==0)
					Response.Redirect("NoData.aspx");
			}
		}

		#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.dsBookBackInfo = new BookManager.dsBookBack();
			((System.ComponentModel.ISupportInitialize)(this.dsBookBackInfo)).BeginInit();
			this.dgBackBook.ItemCreated += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgBackBook_ItemCreated);
			this.dgBackBook.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgBackBook_ItemCommand);
			this.dgBackBook.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgBackBook_DeleteCommand);
			// 
			// 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", "BackBook_View", new System.Data.Common.DataColumnMapping[] {
																																																				  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("PublishData", "PublishData"),
																																																				  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("Memo", "Memo"),
																																																				  new System.Data.Common.DataColumnMapping("Stor", "Stor"),
																																																				  new System.Data.Common.DataColumnMapping("Attr", "Attr")})});
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = @"INSERT INTO BackBook_View(BookName, Author, PublishData, Price, Publish, BookMark, Pic, Attribute, Memo, Stor, Attr) VALUES (@BookName, @Author, @PublishData, @Price, @Publish, @BookMark, @Pic, @Attribute, @Memo, @Stor, @Attr); SELECT ID, BookName, Author, PublishData, Price, Publish, BookMark, Pic, Attribute, Memo, Stor, Attr FROM BackBook_View";
			this.sqlInsertCommand1.Connection = this.sqlConn;
			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("@PublishData", System.Data.SqlDbType.DateTime, 8, "PublishData"));
			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("@BookMark", System.Data.SqlDbType.VarChar, 20, "BookMark"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Pic", System.Data.SqlDbType.VarChar, 30, "Pic"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Attribute", System.Data.SqlDbType.Int, 4, "Attribute"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Memo", System.Data.SqlDbType.VarChar, 2147483647, "Memo"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Stor", System.Data.SqlDbType.Int, 4, "Stor"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Attr", System.Data.SqlDbType.VarChar, 20, "Attr"));
			// 
			// 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 ID, BookName, Author, PublishData, Price, Publish, BookMark, Pic, Attribut" +
				"e, Memo, Stor, Attr FROM BackBook_View";
			this.sqlSelectCommand1.Connection = this.sqlConn;
			// 
			// dsBookBackInfo
			// 
			this.dsBookBackInfo.DataSetName = "dsBookBack";
			this.dsBookBackInfo.Locale = new System.Globalization.CultureInfo("zh-CN");
			this.Load += new System.EventHandler(this.Page_Load);
			((System.ComponentModel.ISupportInitialize)(this.dsBookBackInfo)).EndInit();

		}
		#endregion
		
		private void DataBd()
		{
			sqlAdapter.Fill(dsBookBackInfo);
			dgBackBook.DataBind();
		}
		private void dgBackBook_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{

			string sqlStr;
			e.Item.Attributes.Add("onclick", "return confirm('您真的要删除所选项吗?');");
			sqlStr="update  tblBookInfo set Attribute=4 where ID="+e.Item.Cells[0].Text.ToString();
			this.ExecSql(sqlStr);
			this.DataBd();
			if(dgBackBook.Items.Count==0)
			{
				Response.Redirect("NoData.aspx");
			}
		}
		private void ExecSql(string sqlStr)
		{
			SqlCommand cmd=new SqlCommand(sqlStr,sqlConn);
			sqlConn.Open();
			cmd.ExecuteNonQuery();
			sqlConn.Close();
		}

		private void dgBackBook_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 dgBackBook_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			if(e.CommandName=="UsrDelete")
				dgBackBook_DeleteCommand(source,e);
		}
	}
}

⌨️ 快捷键说明

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