📄 admin_book_add.aspx.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_add: System.Web.UI.Page
{
public TextBox txtBookName,txtBookAuthor,txtBookPrice,txtBookNum,txtBookIntro,txtBookIndex;
public DropDownList dropKindId ;
public Button btnEnter ;
public HtmlInputFile UploadFile;
public Label lblMessage;
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;
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);
//下面获取上传的图片数据,并利用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.InsertBook(strBookName,strBookAuthor,sglBookPrice,intBookNum,bytPicture,strBookIntro, strBookIndex,intKindId)== true)
//插入成功,返回列表页面
Response.Redirect("admin_book_list.aspx");
else
lblMessage.Text = "发生错误,没有添加";
}
//该过程用于绑定类别
public void myDataBind()
{
//下面建立DataBusiness对象,返回所有类别信息
DataBusiness dbs = new DataBusiness();
DataView dv = dbs.GetKind();
//下面绑定数据
dropKindId.DataSource=dv;
dropKindId.DataTextField="KindName";
dropKindId.DataValueField="KindId";
dropKindId.DataBind() ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -