// sua : private void sua() { string namePic = "none"; string tt = ""; DateTime datet = DateTime.Now; int id = Convert.ToInt32(Request.QueryString["id"]); advBLL bs = new advBLL(); List <advDAL> ds = bs.getAdv(); if (fileHinh.HasFile) { if (CheckFileType(fileHinh.FileName) == true) { string ext = Path.GetExtension(fileHinh.FileName); namePic = string.Format("{0:yyyy-M-d-HH-mm-ss}", datet) + ext; String filePath = "~/adv/" + namePic; fileHinh.SaveAs(MapPath(filePath)); lbErrorPic.Text = filePath; } else { lbErrorPic.Text = "Hình ảnh phải ở dạng đuôi *.png, *.jpg"; } } if (rbYes.Checked == true) { tt = "true"; for (int i = 0; i <= ds.Count - 1; i++) { if (ds[i].trangthai == true) { bs.ttPic(); break; } } } else if (rbNo.Checked == true) { tt = "false"; } bool tf = bs.edit(id, txtTen.Text, txtLink.Text, namePic, tt); if (tf == true) { Response.Redirect("quangcao.aspx?edit=t"); } 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>"; } }
// 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>"; } }