protected void btn_OK_Click(object sender, EventArgs e)
{
string name = "";
if (FileUpload1.HasFile)
{
try
{
string ex_filename = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower();
name = DateTime.Now.ToString("yyyyMMddHHmmss") + ex_filename;
if (ex_filename == ".jpg" || ex_filename == ".bmp" || ex_filename == ".png" || ex_filename == ".gif")
{
FileUpload1.SaveAs(Server.MapPath("~/images/products/") + "\\" + name);
}
else
{
Response.Write("<script language='javascript'>alert('这不是图像文件!')</script>");
}
}
catch (Exception ex)
{
throw (ex);
}
}
else
{
Response.Write("<script language='javascript'>alert('请选选择要上传的文件!')</script>");
}
button(name);
}
protected void button(string name)
{
string str = "insert into products (pname,guige,weight,intro,photo,pubdate,price) values('" + txt_name.Text + "','" + txt_guige.Text + "','" + txt_weight.Text + "','" + txt_je.Text + "','" + name + "','" + DateTime.Now + "','" + txt_price.Text + "')";
int result = 0;
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["sweetConnectionString"].ToString();
SqlCommand mycom = new SqlCommand(str, mycon);
try
{
mycon.Open();
result = mycom.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
mycon.Close();
}
if (result != 0)
{
Response.Write("<script language='javascript'>alert('发布成功!')</script>");
}
else
Response.Write("<script language='javascript'>alert('发布失败!')</script>");
}
{
string name = "";
if (FileUpload1.HasFile)
{
try
{
string ex_filename = System.IO.Path.GetExtension(FileUpload1.FileName).ToString().ToLower();
name = DateTime.Now.ToString("yyyyMMddHHmmss") + ex_filename;
if (ex_filename == ".jpg" || ex_filename == ".bmp" || ex_filename == ".png" || ex_filename == ".gif")
{
FileUpload1.SaveAs(Server.MapPath("~/images/products/") + "\\" + name);
}
else
{
Response.Write("<script language='javascript'>alert('这不是图像文件!')</script>");
}
}
catch (Exception ex)
{
throw (ex);
}
}
else
{
Response.Write("<script language='javascript'>alert('请选选择要上传的文件!')</script>");
}
button(name);
}
protected void button(string name)
{
string str = "insert into products (pname,guige,weight,intro,photo,pubdate,price) values('" + txt_name.Text + "','" + txt_guige.Text + "','" + txt_weight.Text + "','" + txt_je.Text + "','" + name + "','" + DateTime.Now + "','" + txt_price.Text + "')";
int result = 0;
SqlConnection mycon = new SqlConnection();
mycon.ConnectionString = ConfigurationManager.ConnectionStrings["sweetConnectionString"].ToString();
SqlCommand mycom = new SqlCommand(str, mycon);
try
{
mycon.Open();
result = mycom.ExecuteNonQuery();
}
catch (Exception ex)
{
throw (ex);
}
finally
{
mycon.Close();
}
if (result != 0)
{
Response.Write("<script language='javascript'>alert('发布成功!')</script>");
}
else
Response.Write("<script language='javascript'>alert('发布失败!')</script>");
}