// 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>"; } }
// 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; } }
// load adv private void loadadv() { advBLL bs = new advBLL(); List <advDAL> ds = bs.getAdv(); rpQC.DataSource = ds; rpQC.DataBind(); for (int i = 0; i < ds.Count; i++) { CheckBox cbDell = rpQC.Items[i].FindControl("cbDell") as CheckBox; Label lbSTT = rpQC.Items[i].FindControl("lbSTT") as Label; Label lbTT = rpQC.Items[i].FindControl("lbTT") as Label; lbSTT.Text = (i + 1).ToString(); if (ds[i].trangthai == true) { lbTT.Text = "Đang hoạt động"; } else { lbTT.Text = "Đã tắt"; } if (ds[i].trangthai == true) { cbDell.Enabled = false; } } }
// load hinh quangcao: private void quangcao() { //<a style='height: 100%; width: 100%' href='google.com.vn' title='adv'> //<img class="adv_img" src="/images/public/adv.png" alt="adv"></img> //</a> advBLL bs = new advBLL(); List <advDAL> ds = bs.getAdvPubLic(); lbHinhADV.Text = "<a href='" + ds[0].link + "' title='" + ds[0].ten + "'>" + "<img style='height: 100%; width: 233px' src='../adv/" + ds[0].hinhanh + "' alt='Sản phẩm mới'></img>" + "</a>"; }
// 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>"; } }
protected void btnUpDate_Click(object sender, EventArgs e) { advBLL bs = new advBLL(); bool check = false; bool ttf = false; string trangthai = ""; for (int i = 0; i < rpQC.Items.Count; i++) { Label lbTT = rpQC.Items[i].FindControl("lbTT") as Label; CheckBox cbDell = rpQC.Items[i].FindControl("cbDell") as CheckBox; if (cbDell.Checked) { trangthai += (cbDell.ToolTip + ","); // xoa hinh trong file adv: string imageFilePath = Server.MapPath("~/adv/" + cbDell.ValidationGroup + ""); System.IO.File.Delete(imageFilePath); check = true; } } if (check == true) { int le = trangthai.Length - 1; string id_adv = trangthai.Remove(le); ttf = bs.del(id_adv); } if (ttf == true) { Response.Redirect("quangcao.aspx?up=t"); } else { lbError.Text = "<div class='error'>" + "<div class='tl'></div><div class='tr'></div>" + "<div class='desc'>" + "<p>Cập nhật thất bại !</p>" + "</div>" + "<div class='bl'></div><div class='br'></div>" + "</div>"; } }