62,266
社区成员
发帖
与我相关
我的任务
分享 protected void Button2_Click(object sender, EventArgs e)
{
try
{
typeID = Convert.ToInt32(DropDownListtype.SelectedItem.Value);
}
catch (Exception)
{
typeID = 6;
}
if (DropDownList5.Text != "" && TextBox1.Text != "" && TextBox2.Text != "" && TextBox3.Text != "" && TextBox4.Text != "" && TextBox5.Text != "" && FreeTextBox1.Text != "")
{
string sql = "select count(*) from Books where bookName='" + TextBox1.Text.Trim().ToString() + "'";
int sqlcount = int.Parse(Class1.SelOne(sql));
if (sqlcount == 0)
{
filename = FileUpload1.FileName.ToString();
string filepath = Server.MapPath("image");
FileUpload1.SaveAs(filepath + "\\" + filename);
string sqlisert = "insert into Books(classid,classname,bookName,author,price,publish,publishDate,description,pictureurl,IsSelling) values(" + typeID + ",'" + DropDownList5.Text.Trim().ToString() + "','" + TextBox1.Text.Trim().ToString() + "','" + TextBox2.Text.Trim().ToString() + "'," + TextBox3.Text.Trim().ToString() + ", '" + TextBox4.Text.Trim().ToString() + "','" + TextBox5.Text.Trim().ToString() + "','" + FreeTextBox1.Text.Trim().ToString() + "','" + filename + "',0)";
Class1.ExecSql(sqlisert);
}
else
{
Response.Write("<scrip javalaguage='javascript'>alert('此书籍已经存在!');</script>");
}
}
else
{
Response.Write("<scrip javalaguage='javascript'>alert('请填写全部信息!');</script>");
}
Response.Redirect("Admin-guanli.aspx");
}if (sqlcount == 0)
{
filename = FileUpload1.FileName.ToString();
string filepath = Server.MapPath("image");
string filesavePat=filepath + "\\" + filename;
FileUpload1.SaveAs(filesavePath);
string fileswebPath= filesavePath.Replace(System.Web.HttpContext.Current.Request.MapPath("~/image"), "/image/");
fileswebPath= "/" + fileswebPath.Replace("\\", "/");
fileswebPath= fileswebPath.Replace("//", "/");
string sqlisert = "insert into Books(classid,classname,bookName,author,price,publish,publishDate,description,pictureurl,IsSelling) values(" + typeID + ",'" + DropDownList5.Text.Trim().ToString() + "','" + TextBox1.Text.Trim().ToString() + "','" + TextBox2.Text.Trim().ToString() + "'," + TextBox3.Text.Trim().ToString() + ", '" + TextBox4.Text.Trim().ToString() + "','" + TextBox5.Text.Trim().ToString() + "','" + FreeTextBox1.Text.Trim().ToString() + "','" + fileswebPath+ "',0)";
Class1.ExecSql(sqlisert);
}