以下是引用片段:
核心代码如下: protected void Button1_Click(object sender, EventArgs e) { //判断信息是否正确 if (this.txtXM.Text.Trim() == "") { Page.ClientScript.RegisterStartupScript(this.GetType(), "ifo", "alert('姓名不能为空!');"); return; }
//将相关的图片上传到@"Image\"路径下 string FileName = ""; string FileName1; string DPath; DPath = Server.MapPath("") + @"\"; DPath = DPath + @"..\image\person\"; if (this.FileTP.PostedFile.FileName != "") { string[] temp = this.FileTP.PostedFile.FileName.Split('.'); string strHzm = "." + temp[temp.Length - 1];
Guid tmp = Guid.NewGuid(); FileName = tmp.ToString() + strHzm; FileName1 = DPath + tmp.ToString() + strHzm; this.FileTP.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) { string FilePhoto = ""; if (FileName != "") { FilePhoto = ",代表作图片='" + FileName + "'"; } DataBase.ExecSql("UPDATE [制壶名家] set [姓名] ='" + txtXM.Text + "'" + FilePhoto + ",[性别] = '" + rbXB.SelectedValue + "',[所属年代] ='" + drSSND.SelectedValue + "',[名家介绍] = '" + txtMJJS.Text + "',[代表作] = '" + txtDBZMC.Text + "' WHERE 名家编号=" + Request.QueryString["ID"]); } else { DataBase.ExecSql("INSERT INTO [制壶名家] ([姓名] ,[性别] ,[所属年代] ,[名家介绍] ,[代表作] ,[代表作图片] ) VALUES ('"+txtXM.Text+"','"+rbXB.SelectedValue+"','"+drSSND.SelectedValue+"','"+txtMJJS.Text+"','"+txtDBZMC.Text+"','"+FileName+"')");
}
|