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

📄 bookinsert.aspx.cs

📁 基于web的图书管理系统 (SQL Server 2000)
💻 CS
字号:
using System;
using System.IO;
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;

namespace WebApplication1
{
	/// <summary>
	/// BookInsert 的摘要说明。
	/// </summary>
	public class BookInsert : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.TextBox BookName;
		protected System.Web.UI.WebControls.TextBox Type;
		protected System.Web.UI.WebControls.TextBox TPI;
		protected System.Web.UI.WebControls.TextBox Writer;
		protected System.Web.UI.WebControls.TextBox Price;
		protected System.Web.UI.WebControls.Image cover;
		protected System.Web.UI.WebControls.TextBox pDate;
		protected System.Web.UI.WebControls.TextBox memo;
		protected System.Web.UI.WebControls.TextBox Introduce;
	    protected System.Web.UI.WebControls.TextBox BookID;
		protected System.Web.UI.HtmlControls.HtmlInputFile imageload;
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.DropDownList state;
		protected System.Web.UI.WebControls.Button btSave;
	    protected CCUtility Utility;
		private void Page_Load(object sender, System.EventArgs e)
		{
				this.Utility=new CCUtility(this);
			Utility.CheckSecurity();
			if (!this.IsPostBack)
			{			
				Page_Show(sender,e);
			}
			
		}

		#region Web 窗体设计器生成的代码
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
			//
			InitializeComponent();
			base.OnInit(e);
		}
		private void InitializeComponent()
		{    
			
			this.btSave.Click += new System.EventHandler(this.btSave_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion
		protected void Page_Show(object sender, EventArgs e)
		{
            this.state.Items.Clear();
    		ListItem item1=new ListItem("请选择");
			this.state.Items.Add(item1);
			this.state.Items.Add("在馆");
    		this.state.Items.Add("出馆");
		}
		public void MsgBox( string msg )
		{
			string strScript =  "<script language='Javascript'>alert('" + msg + "');</script>";
			Page.RegisterStartupScript("alert", strScript);
		}
		

		private void btSave_Click(object sender, System.EventArgs e)
		{
			this.cover.ImageUrl=this.imageload.Value.ToString();
			string path=this.cover.ImageUrl.ToString();
			string filename=System.IO.Path.GetFileName(path); 
			string strInsert;
			if(this.state.SelectedValue.ToString()=="请选择")
			{
			this.MsgBox("请选择图书状态!");return;
			}
			if(this.BookID.Text=="")
			{
				this.MsgBox("请输入图书编号!");return;
			}
			if(this.Price.Text=="")
			{
				 strInsert="insert into DB_bookinfo(BookID,BookName,Type,TPI,Writer,Introduce,Price,pDate,cover,memo,state)VALUES( '"
					+this.BookID.Text+"','"
					+this.BookName.Text+"','"
					+this.Type.Text+"','"
					+this.TPI.Text+"','"
					+this.Writer.Text+"','"
					+this.Introduce.Text+"',0,'"
					+this.pDate.Text+"','"
					+filename+"','"
					+this.memo.Text+"','"
					+this.state.SelectedValue.ToString()+"')";
			}
			else
			{	 strInsert="insert into DB_bookinfo(BookID,BookName,Type,TPI,Writer,Introduce,Price,pDate,cover,memo,state)VALUES( '"
					+this.BookID.Text+"','"
					+this.BookName.Text+"','"
					+this.Type.Text+"','"
					+this.TPI.Text+"','"
					+this.Writer.Text+"','"
					+this.Introduce.Text+"',"
					+this.Price.Text+",'"
					+this.pDate.Text+"','"
					+filename+"','"
					+this.memo.Text+"','"
					+this.state.SelectedValue.ToString()+"')";
		
			}
			this.Label1.Text=strInsert;
			try
			{
				Access acc = new Access();
				bool success=acc.ExecuteSQL(strInsert);		
				if(success==true)
				{
					this.MsgBox("录入成功!");
					this.BookID.Text="";
				    this.BookName.Text="";
					this.Type.Text="";
					this.TPI.Text="";
					this.Writer.Text="";
					this.Introduce.Text="";
					this.Price.Text="";
					this.pDate.Text="";
					filename="";
					this.memo.Text="";
					
				}
				else {this.MsgBox("录入失败!");}
				
			}
			catch(Exception ed){this.MsgBox(ed.ToString());}

			
		}

		
	}
}

⌨️ 快捷键说明

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