以下是引用片段:
其主要代码实现过程如下: protected void Page_Load(object sender, EventArgs e) { // 在此处放置用户代码以初始化页面 if (!Page.IsPostBack) { this.Button3.Visible = false; if (Request.QueryString["ID"] != null) { //显示当前的楼盘信息 DataTable tmpda = new DataTable(); tmpda = Database.Get_Table("select * from 楼盘信息 where 楼牌代码=" + Request.QueryString["ID"]); if (tmpda.Rows.Count > 0) { this.TextBox1.Text = tmpda.Rows[0]["楼盘名称"].ToString(); this.TextBox3.Text = tmpda.Rows[0]["所在地址"].ToString(); this.TextBox2.Text = tmpda.Rows[0]["楼盘简介"].ToString(); Hidden1.Value = tmpda.Rows[0]["楼盘照片"].ToString(),; this.Button3.Visible = true; } } }
} protected void Button1_Click(object sender, EventArgs e) { //将相关的图片上传到@"Pic\"路径下 string FileName = ""; string FileName1; string DPath; if (Server.MapPath("").Substring(Server.MapPath("").Length - 1, 1) == @"\") { DPath = Server.MapPath(""); } else { DPath = Server.MapPath("") + @"\"; } DPath = DPath + @"Pic\"; if (this.File2.PostedFile.FileName != "") { string[] temp = this.File2.PostedFile.FileName.Split('.'); string strHzm = "." + temp[temp.Length - 1];
Guid tmp = Guid.NewGuid(); FileName = tmp.ToString() + strHzm; FileName1 = DPath + tmp.ToString() + strHzm; this.File2.PostedFile.SaveAs(FileName1); if (File.Exists(DPath + Hidden1.Value)) { File.Delete(DPath + Hidden1.Value); } } //根据标志判断是添加还是修改的操作 保存楼盘信息 if (Request.QueryString["ID"] != null) { if (FileName == "") { Database.ExecSql("update 楼盘信息 set 楼盘名称='" + TextBox1.Text + "', 所在地址='" + this.TextBox3.Text + "',楼盘简介='" + TextBox2.Text + "' where 楼牌代码=" + Request.QueryString["ID"]); } else { Database.ExecSql("update 楼盘信息 set 楼盘照片='" + FileName + "',楼盘名称='" + TextBox1.Text + "', 楼盘简介='" + TextBox2.Text + "' where 楼牌代码=" + Request.QueryString["ID"]); } } else { Database.ExecSql("insert into 楼盘信息(楼盘名称,所在地址,楼盘简介,楼盘照片) values('" + TextBox1.Text + "'" + " ,'" + TextBox3.Text + "','" + TextBox2.Text + "','" + FileName + "')");
}
|