以下是引用片段: 核心代码如下: protected void Button1_Click(object sender, EventArgs e) { //判断信息是否正确 if (this.TextBox1.Text.Trim() == "") { Page.ClientScri'餐品名称不能为空!'>"); return; } //将相关的图片上传到@"Image\"路径下 string FileName = ""; string FileName1; string DPath; DPath = Server.MapPath("..") + @"\"; DPath = DPath + @"Image\"; 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.ExecSql("update spxx set spmc='" + TextBox1.Text + "', spjg=" + this.Textbox2.Text.Trim() + ",spjs='" + this.Textbox3.Text.Trim() + "',sccj='" + this.Textbox4.Text.Trim() + "',spflbh=" + this.Dropdownlist2.SelectedValue + " where spbh=" + Request.QueryString["ID"]); } else { DataBase.ExecSql("update spxx set spmc='" + TextBox1.Text + "',spjg=" + this.Textbox2.Text.Trim() + ",spjs='" + this.Textbox3.Text.Trim() + "',sccj='" + this.Textbox4.Text.Trim() + "',spflbh=" + this.Dropdownlist2.SelectedValue + ",sptpwjm='" + FileName + "' where spbh=" + Request.QueryString["ID"]); } } else { DataBase.ExecSql("insert into spxx(spmc,sptpwjm,spjs,sccj,spflbh,spjg) values('" + this.TextBox1.Text.Trim() + "','" + FileName + "','" + this.Textbox3.Text.Trim() + "','" + this.Textbox4.Text.Trim() + "'," + this.Dropdownlist2.SelectedValue + "," + Textbox2.Text + ")"); }
|