protected void SelectedIndexChanged(object sender, EventArgs e) { string categorie = DdlCategories.SelectedValue; if (categorie == "Toutes") { Publication[] publications = pf.GetAll(); afficherTableauRepeater(publications); } else { Publication[] publications = pf.GetAllByCategoryId(Convert.ToInt32(categorie)); afficherTableauRepeater(publications); } }
private void btn_Supprimer_Click(object sender, EventArgs e) { string confirmValue = Request.Form["confirm_delete"]; if (confirmValue == "Oui") { Button button = (Button)sender; int id = Convert.ToInt32(button.Attributes["data-id"]); Category category = cf.GetCategoryById(id); try { //Supprimer l'image string FileToDelete = Server.MapPath(category.pictureUrl); File.Delete(FileToDelete); //Supprimer les publications de la catégorie PublicationFactory pf = new PublicationFactory(cnnStr); Publication[] publicationsASupprimer = pf.GetAllByCategoryId(id); if (publicationsASupprimer.Length > 0) { string[] IDsToString = new string[publicationsASupprimer.Length]; string[] PDFs = new string[publicationsASupprimer.Length]; for (int i = 0; i < publicationsASupprimer.Length; i++) { IDsToString[i] = publicationsASupprimer[i].publicationId.ToString(); PDFs[i] = publicationsASupprimer[i].url; } pf.DeleteByArray(IDsToString); //Supprimer les PDFs for (int j = 0; j < publicationsASupprimer.Length; j++) { string PDFtoDelete = Server.MapPath(PDFs[j]); File.Delete(PDFtoDelete); } } //Supprime de la BD (deletionDate) cf.delete(id); } finally { Response.Redirect(Request.RawUrl); } } }
protected void Page_Load(object sender, EventArgs e) { // ----------- Vérification le l'état du module ----------- // ModuleFactory moduleFactory = new ModuleFactory(cnnStr); Module m = moduleFactory.Get((int)Module.AllModules.Publications);/* Module id 3 = Module des documents PDF */ if (m.active == false) { Response.Redirect("Default.aspx"); } // ------------------------------------------------------- // int category; if (Request.QueryString["cat"] != null) { if (Int32.TryParse(Request.QueryString["cat"], out category)) { Publication[] publications = pf.GetAllByCategoryId(category); CategoryFactory cf = new CategoryFactory(cnnStr); Category cat = cf.GetCategoryById(category); if (cat.name == null && cat.pictureUrl == null) { Response.Redirect("Publications.aspx"); } titreCategorie.InnerText = cat.name; if (publications.Length < 1) { divPublications.Visible = false; divNotif.Visible = true; } else { divPublications.Visible = true; divNotif.Visible = false; HtmlGenericControl ht = publicationsPortfolio; foreach (Publication p in publications) { HtmlGenericControl newDiv = new HtmlGenericControl("div"); HtmlGenericControl divPubli = new HtmlGenericControl("div"); Button button = new Button(); button.Text = "Télécharger"; button.CssClass = "btn mainButton3"; button.CommandName = "download"; button.CommandArgument = p.publicationId.ToString(); button.Click += new EventHandler(Download_Click); newDiv.Attributes["class"] = "col-lg-6 pt-2 pb-5 text-center"; divPubli.InnerHtml = "<div><h2>" + p.title + "</h2></div><object data=\"" + p.url + "\" type=\"application/pdf\" style=\"width:100%; height:300px;\" class=\"box-shadow box-admin\"></object>"; newDiv.Controls.Add(divPubli); newDiv.Controls.Add(button); publicationsPortfolio.Controls.Add(newDiv);; } } } else { Response.Redirect("Publications.aspx"); } } else { Response.Redirect("Publications.aspx"); } }