以下是引用片段:
核心代码如下: if (this.txtCHMC.Text.Trim() == "") { Page.ClientScript.R('虫害名称不能为空!'>"); &nb,s,p; return; } //将相关的图片上传到@"Image\"路径下 string FileName = ""; string FileName1; string DPath; DPath = Server.MapPath("") + @"\"; DPath = DPath + @"file\"; if (this.File1.PostedFile.FileName != "") { string[] temp = this.File1.PostedFile.FileName.Split('.'); string strHzm = "." + temp[temp.Length - 1];
Guid tmp = Guid.NewGuid(); FileName = tmp.ToString() + strHzm; FileName1 = DPath + tmp.ToString() + strHzm; this.File1.PostedFile.SaveAs(FileName1); if (Session["imgname"] != null) { if (File.Exists(DPath + Session["imgname"].ToString())) { File.Delete(DPath + Session["imgname"].ToString()); }
} }
//根据标志判断是添加还是修改的操作 保存商品信息 if (Request.QueryString["ID"] != null) { if (FileName == "") { Database.Execute("UPDATE [虫害] set [虫害名称] ='" + txtCHMC.Text + "',[虫害介绍] ='" + txtCHJS.Text + "',[植物代码] = " + drZWMC.SelectedValue + ",[虫害部位] = '" + drCHBW.SelectedValue + "',[预防办法] = '" + txtYFFF.Text + "',[消灭办法] = '" + txtXMBF.Text + "' WHERE 虫害代码=" + Request.QueryString["ID"]); } else { Database.Execute("UPDATE [虫害] set [虫害名称] ='" + txtCHMC.Text + "',[虫害介绍] ='" + txtCHJS.Text + "',[虫害图片] = '" + FileName + "',[植物代码] = " + drZWMC.SelectedValue + ",[虫害部位] = '" + drCHBW.SelectedValue + "',[预防办法] = '" + txtYFFF.Text + "',[消灭办法] = '" + txtXMBF.Text + "' WHERE 虫害代码=" + Request.QueryString["ID"]); } } else { Database.Execute("INSERT INTO [虫害] ( [虫害名称] ,[虫害介绍] ,[虫害图片] ,[植物代码] ,[虫害部位] ,[预防办法] ,[消灭办法] ) VALUES ('" + txtCHMC.Text + "','" + txtCHJS.Text + "','" + FileName + "'," + drZWMC.SelectedValue + ",'" + drCHBW.SelectedValue + "','" + txtYFFF.Text + "','" + txtXMBF.Text + "')");
}
|