// load thong tin: private void loadTT() { int id = Convert.ToInt32(Request.QueryString["id"]); advBLL bs = new advBLL(); List <advDAL> ds = bs.getAdvById(id); txtTen.Text = ds[0].ten; txtLink.Text = ds[0].link; if (ds[0].hinhanh != "") { lbHinh.Visible = true; btnXoaHinh.Visible = true; fileHinh.Visible = false; lbErrorPic.Visible = false; lbHinh.Text = "<img widt='70px' height='70px' src='../adv/" + ds[0].hinhanh + "' />"; } else { lbHinh.Visible = false; btnXoaHinh.Visible = false; fileHinh.Visible = true; lbErrorPic.Visible = true; } if (ds[0].trangthai == true) { rbYes.Checked = true; } else { rbNo.Checked = true; } }
// xoa hinh : private void xoaHinh() { string tt = ""; int id = Convert.ToInt32(Request.QueryString["id"]); advBLL bs = new advBLL(); List <advDAL> ds = bs.getAdvById(id); bool xoa = false; // xoa hinh trong file adv: string imageFilePath = Server.MapPath("~/adv/" + ds[0].hinhanh + ""); try { System.IO.File.Delete(imageFilePath); xoa = true; } catch { xoa = false; } if (rbYes.Checked == true) { tt = "true"; } else if (rbNo.Checked == true) { tt = "false"; } // xoa hinh trong csdl: bool tf = bs.edit(id, txtTen.Text, txtLink.Text, "", tt); if (xoa == true && tf == true) { lbHinh.Visible = false; btnXoaHinh.Visible = false; fileHinh.Visible = true; lbErrorPic.Visible = true; } else { lbError.Text = "<div class='error'>" + "<div class='tl'></div><div class='tr'></div>" + "<div class='desc'>" + "<p>Cập nhật bị lỗi !</p>" + "</div>" + "<div class='bl'></div><div class='br'></div>" + "</div>"; } }