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

📄 bookmodify.aspx.cs

📁 在书店系统,access数据库和.net
💻 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.Configuration ;
using System.Data .SqlClient ;
namespace BMS
{
	/// <summary>
	/// BookModify 的摘要说明。
	/// </summary>
	public class BookModify : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox tbx_bname;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfv_bname;
		protected System.Web.UI.WebControls.TextBox tbx_bisbn;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfv_bisbn;
		protected System.Web.UI.WebControls.RegularExpressionValidator rev_bisbn;
		protected System.Web.UI.WebControls.TextBox tbx_bauthor;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfv_banthor;
		protected System.Web.UI.WebControls.TextBox tbx_bpress;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfv_bpress;
		protected System.Web.UI.WebControls.DropDownList ddl_bgroup;
		protected System.Web.UI.WebControls.TextBox tbx_bdescribe;
		protected System.Web.UI.WebControls.Button btn_modify;
		protected System.Web.UI.WebControls.Button btn_delete;
		protected System.Web.UI.WebControls.TextBox tbx_pprice;
		protected System.Web.UI.WebControls.DropDownList ddl_pdiscount;
		protected System.Web.UI.WebControls.RequiredFieldValidator rfv_pprice;
		protected System.Web.UI.WebControls.RegularExpressionValidator rev_pprice;
		protected System.Web.UI.WebControls.Label lbl_bid;
		protected System.Web.UI.WebControls.HyperLink hlk_bookmanage;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if(!IsPostBack)
			{	//从文件Web.config中读取连接字符串
				string strconn= ConfigurationSettings.AppSettings["dsn"];
				//连接本地计算机的BMS数据库
				SqlConnection cn= new SqlConnection (strconn);
				//创建查询相应书目信息的sql语句
				string mysql="select * from book,bookprice where book.bid=bookprice.ppid and book.bid=@bid";
				//创建SqlCommand
				SqlCommand cm=new SqlCommand (mysql,cn);
				//添加并设置参数的值
				cm.Parameters .Add ("@BID", SqlDbType.Int );
				cm.Parameters ["@BID"].Value =Request.QueryString [0];
				//打开连接
				cn.Open ();
				//执行ExecuteReader
				SqlDataReader dr=cm.ExecuteReader ();
				if(dr.Read ())//有数据读出,即有匹配用户
				{
					//进行Label绑定
					lbl_bid.Text =dr["bid"].ToString ();
					tbx_bname.Text =dr["bname"].ToString ();
					tbx_bisbn.Text =dr["bisbn"].ToString ();
					tbx_bauthor.Text =dr["bauthor"].ToString ();
					tbx_bpress.Text =dr["bpress"].ToString ();
					tbx_pprice.Text =dr["pprice"].ToString ();
					ddl_pdiscount.SelectedIndex =Convert.ToInt16 (dr["pdiscount"].ToString ());
					ddl_bgroup.SelectedIndex =Convert.ToInt16 (dr["bgroup"].ToString ());
					tbx_bdescribe.Text =dr["bdescribe"].ToString ();
					cn.Close ();
				}
			
				else
				{
					Response.Write ("该书目不存在,请返回");
					Response.End ();
				}
			}
		}

		#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_modify.Click += new System.EventHandler(this.btn_modify_Click);
			this.btn_delete.Click += new System.EventHandler(this.btn_delete_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btn_modify_Click(object sender, System.EventArgs e)
		{	//从文件Web.config中读取连接字符串
			string strconn= ConfigurationSettings.AppSettings["dsn"];
			//连接本地计算机的BMS数据库
			SqlConnection cn= new SqlConnection (strconn);
			cn.Open ();
			//创建cm1,用于book表中数据的操作
			string bookmodify="UPDATE Book SET BISBN = @BISBN,BName = @BName,BAuthor = @BAuthor,BPress = @BPress,BGroup = @BGroup,BDescribe = @BDescribe WHERE  BID = @BID";
			SqlCommand cm1=new SqlCommand (bookmodify,cn);
			cm1.Parameters .Add ("@BID",SqlDbType.Int  );
			cm1.Parameters .Add ("@BISBN",SqlDbType.VarChar );
			cm1.Parameters .Add ("@BName",SqlDbType.VarChar );
			cm1.Parameters .Add ("@BAuthor",SqlDbType.VarChar );
			cm1.Parameters .Add ("@BPress",SqlDbType.VarChar );
			cm1.Parameters .Add ("@BGroup",SqlDbType.Int );
			cm1.Parameters .Add ("@BDescribe",SqlDbType.VarChar );
			//cm1.CommandType =CommandType.StoredProcedure ;
			//创建cm2,用于bookprice表中数据的操作
			SqlCommand cm2=new SqlCommand ("bookpricemodify",cn);
			cm2.Parameters .Add ("@PPID",SqlDbType.Int  );
			cm2.Parameters .Add ("@PPrice",SqlDbType.Money );
			cm2.Parameters .Add ("@PDiscount",SqlDbType.Float );
			cm2.CommandType =CommandType.StoredProcedure ;
			//从Label中取得要更新内容的书的书目号
			string bidvalue=lbl_bid.Text .ToString ();
			cm1.Parameters ["@BID"].Value =Convert.ToInt16 (bidvalue);
			cm2.Parameters ["@PPID"].Value =Convert.ToInt16 (bidvalue);
			//从各TextBox中取得要更新的值
			//往book表中参数付值
			cm1.Parameters ["@BName"].Value =tbx_bname.Text .ToString ();
			cm1.Parameters ["@BISBN"].Value =tbx_bisbn.Text .ToString ();
			cm1.Parameters ["@BAuthor"].Value =tbx_bauthor.Text .ToString ();
			cm1.Parameters ["@BPress"].Value =tbx_bpress.Text .ToString ();
			cm1.Parameters ["@BDescribe"].Value =tbx_bdescribe.Text .ToString ();
			cm1.Parameters ["@BGroup"].Value =ddl_bgroup.SelectedItem .Value.ToString () ;
			//往bookprice表中参数付值
			cm2.Parameters ["@PPrice"].Value =Convert.ToDouble (tbx_pprice.Text .ToString ());
			cm2.Parameters ["@PDiscount"].Value =Convert.ToInt16 (ddl_pdiscount.SelectedItem .Value .ToString());
			cm1.ExecuteNonQuery ();
			cm2.ExecuteNonQuery ();
			cn.Close ();
		}

		private void btn_delete_Click(object sender, System.EventArgs e)
		{
			//从文件Web.config中读取连接字符串
			string strconn= ConfigurationSettings.AppSettings["dsn"];
			//连接本地计算机的BMS数据库
			SqlConnection cn= new SqlConnection (strconn);
			cn.Open ();
			//创建cm1,用于book表中数据的操作
			SqlCommand cm1=new SqlCommand ("bookdelete",cn);
			cm1.Parameters .Add ("@BID",SqlDbType.Int  );
			cm1.CommandType =CommandType.StoredProcedure ;
			//创建cm2,用于bookprice表中数据的操作
			SqlCommand cm2=new SqlCommand ("bookpricedelete",cn);
			cm2.Parameters .Add ("@PPID",SqlDbType.Int  );
			cm2.CommandType =CommandType.StoredProcedure ;
			//从Label中取得要更新内容的书的书目号
			string bidvalue=lbl_bid.Text .ToString ();
			cm1.Parameters ["@BID"].Value =Convert.ToInt16 (bidvalue);
			cm2.Parameters ["@PPID"].Value =Convert.ToInt16 (bidvalue);
			cm1.ExecuteNonQuery ();
			cm2.ExecuteNonQuery ();
			cn.Close ();
			Response.Redirect ("bookmanage.aspx");
		}
	}
}

⌨️ 快捷键说明

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