📄 addbooks.aspx.cs
字号:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class AddBooks : System.Web.UI.Page
{
Class1 db = new Class1();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DropDownList1Bind();
}
}
protected void DropDownList1Bind()
{
DropDownList1.DataSource = db.createdataset("select * from Categories");
DropDownList1.DataTextField = "CatName";
DropDownList1.DataValueField = "CatID";
DropDownList1.DataBind();
}
protected void CheckCountAngMoney()
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//保存,注意书的数量不能为空或者其他非法字符
string bookname=TextBox1.Text;
string CatName = DropDownList1.SelectedItem.Text;
Decimal BookMarketPrice = Convert.ToDecimal(TextBox2.Text);
Decimal BookPrice = Convert.ToDecimal(TextBox3.Text);//FileUpload1
string BookInfo = FreeTextBox1.Text;
string BookImage = null;
int count =Convert.ToInt32( TextBox4.Text);
string Writer = TextBox5.Text;
string Pree = TextBox6.Text;
string ISBN = TextBox7.Text;
DateTime PreeTime =Convert.ToDateTime( TextBox8.Text);
int catid = -1;
string sql="select CatID from Categories where CatName='"+CatName+"'";
SqlDataReader dr = db.Reader(sql);
if (dr.Read())
{
catid = dr.GetInt32(0);
}
if (FileUpload1.HasFile)
{
string path = Server.MapPath("image\\bookimages\\");
FileUpload1.SaveAs(path + FileUpload1.FileName);
BookImage = path + FileUpload1.FileName;
}
else
{
BookImage = null;
}
//D:\Settings\Desktop\mybookshop\book\image\IMG0097A.jpg
BookImage = BookImage.Substring(36, BookImage.Length-36);
string sqlstr = string.Format("insert into Books(CatID,BookName,BookImage,BookMarketPrice,BookPrice,BookInfo,BookAmount,Pree,Writer,ISBN,PreeTime) values( {0},'{1}','{2}','{3}','{4}' ,'{5}',{6},'{7}','{8}','{9}' ,'{10}' )", catid, bookname, BookImage, BookMarketPrice, BookPrice, BookInfo, count, Pree, Writer, ISBN, PreeTime);
//"exec inserbook " + catid + ",'" + bookname + "','" + BookImage + "','" + BookMarketPrice + "','" + BookPrice + "','" + BookInfo + "'," + count + ",'" + Pree + "','" + Writer + "','" + ISBN + "','" + PreeTime + "'")
if (db.ExecSql(sqlstr))
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", "alert('保存成功')", true);
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "MessageBox", "alert('保存失败,请检查!')", true);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
TextBox5.Text = "";
TextBox6.Text = "";
TextBox7.Text = "";
FreeTextBox1.Text = "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -