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

📄 admin_book_update.aspx.cs

📁 《ASP.NET程序设计实用教程》源代码,这本书非常使用,有次源码更是锦上添花,谢谢使用
💻 CS
字号:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;									//因为用到了文件上传控件
using System.Data;
using System.IO	;												//因为用到了Stream对象
using nsShop;										            //因为用到了自定义业务对象,所以导入


public class admin_book_update: System.Web.UI.Page
{
	public TextBox txtBookName,txtBookAuthor,txtBookPrice,txtBookNum,txtBookIntro,txtBookIndex,txtBookId ; 
	public DropDownList dropKindId;
	public Button btnEnter ;
	public HtmlInputFile UploadFile;
	public Label lblMessage;
	public System.Web.UI.WebControls.Image imgPicture;

	public void Page_Load(object sender, System.EventArgs e)
	{		
		if (! Page.IsPostBack) 
			myDataBind();
	}

	//该过程用来添加新书本
	public void btnEnter_Click(Object Sender,EventArgs E )
	{
		//判断一下,如果不是管理员,就返回到首页
		if (DataUserLog.IsAdmin() == false )
			Response.Write("<script language='javascript'>top.document.location='../index.aspx';</script>");
		
		//下面首先获取书名等普通数据
		String strBookName,strBookAuthor,strBookIntro,strBookIndex;
		Single sglBookPrice;
		int intBookNum,intKindId,intBookId ;
		strBookName = txtBookName.Text;
		strBookAuthor = txtBookAuthor.Text;
		strBookIntro = txtBookIntro.Text;
		strBookIndex = txtBookIndex.Text;
		sglBookPrice =(Convert.ToSingle( txtBookPrice.Text));
		intBookNum = Convert.ToInt32(txtBookNum.Text);
		intKindId = Convert.ToInt32(dropKindId.SelectedItem.Value);
		intBookId = Convert.ToInt32(txtBookId.Text);

		//下面获取上传的图片数据,并利用Stream对象将其保存到二进制数组中
		int FileSize = UploadFile.PostedFile.ContentLength;
		Byte [] bytPicture  = new Byte[FileSize];//建立一个和文件大小一致的二进制数组					
		Stream objStream ;			//定义一个Stream对象变量
		objStream = UploadFile.PostedFile.InputStream;		//读取上传文件到Stream对象中
		objStream.Read(bytPicture,0,FileSize);				//读取整个文件到buffer数租中
		
		//下面调用方法添加记录
		DataBusiness dbs = new DataBusiness();
		if (dbs.UpdateBook(intBookId,strBookName,strBookAuthor,sglBookPrice,intBookNum,bytPicture,strBookIntro, strBookIndex,intKindId)== true )
			//更新成功,返回列表页面
			Response.Redirect("admin_book_list.aspx");
		else
			lblMessage.Text = "发生错误,没有更新";
	}


	//该过程用于绑定类别
	public void myDataBind()
	{
		//下面首先获取本书的有关信息
		DataBook dbk = new DataBook(Convert.ToInt32(Request.QueryString["BookId"]));
		txtBookName.Text = dbk.BookName;
		txtBookAuthor.Text = dbk.BookAuthor;
		txtBookPrice.Text = Convert.ToString(dbk.BookPrice);
		txtBookNum.Text = Convert.ToString(dbk.BookNum);
		txtBookIntro.Text = dbk.BookIntro;
		txtBookIndex.Text = dbk.BookIndex;
		txtBookId.Text = Convert.ToString(dbk.BookId);			//将BookId保存到隐藏文本框中

		imgPicture.ImageUrl = "../showimage.aspx?BookId=" + dbk.BookId;

		//下面建立DataBusiness对象,返回所有文章
		DataBusiness dbs = new DataBusiness();
		DataView dv = dbs.GetKind();
		//下面绑定数据
		dropKindId.DataSource=dv;
		dropKindId.DataTextField="KindName";
		dropKindId.DataValueField="KindId";
		dropKindId.SelectedValue=Convert.ToString(dbk.KindId);						//设置预选项
		dropKindId.DataBind();	
	}

}

⌨️ 快捷键说明

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