protected void btn_yes_Click(object sender, EventArgs e) { News news = DataMapping.GetNews_EN(Request.QueryString["newsid"]); News.Bloc bloc = null; List <News.Bloc> blocsAfter = new List <News.Bloc>(); foreach (News.Bloc b in news.GetListBlocs()) { if (b.id == Request.QueryString["blocid"]) { bloc = b; } if (bloc != null && b.ord > bloc.ord) { blocsAfter.Add(b); } } if (bloc != null) { if (!DataMapping.DeleteNewsBloc(bloc)) { throw new Exception("Can't delete bloc"); } } foreach (News.Bloc b in blocsAfter) { b.ord -= 10; if (!DataMapping.UpdateNewsBloc(b)) { throw new Exception("Error update ord"); } } string url = Functions.UrlAddParam(Globals.NavigateURL(), "newsid", Request.QueryString["newsid"]); Response.Redirect(url); }
protected void LI_Blocs_ItemCommand(object source, RepeaterCommandEventArgs e) { try { News.Bloc bloc = new News.Bloc(); News news = DataMapping.GetNews_EN(Request.QueryString["newsid"]); if (Request.QueryString["blocid"] != "" && Request.QueryString["blocid"] != null) { foreach (News.Bloc b in news.GetListBlocs()) { if (b.id == Request.QueryString["blocid"]) { bloc = b; } } } if (e.CommandSource == e.Item.FindControl("lbt_delete")) { LinkButton lbt_delete = (LinkButton)e.Item.FindControl("lbt_delete"); foreach (News.Bloc b in news.GetListBlocs()) { if (b.id == lbt_delete.CommandArgument) { theBloc = b; } } if (!DataMapping.DeleteNewsBloc(theBloc)) { throw new Exception("Error deleting"); } string url = Functions.UrlAddParam(Globals.NavigateURL(), "newsid", Request.QueryString["newsid"]); Response.Redirect(url); } #region Type if (e.CommandSource == e.Item.FindControl("btn_type")) { RadioButtonList rbl = (RadioButtonList)e.Item.FindControl("rbl_type"); foreach (ListItem li in rbl.Items) { if (li.Selected) { bloc.type = "Bloc" + li.Value; } } List <News.Bloc> blocs = new List <News.Bloc>(); blocs.Add(bloc); LI_Blocs.DataSource = blocs; LI_Blocs.DataBind(); } #endregion Type #region Validate if (e.CommandSource == e.Item.FindControl("btn_validate")) { Button btn = (Button)e.Item.FindControl("btn_validate"); TextBox tbx_title = (TextBox)e.Item.FindControl("tbx_titre"); if (tbx_title.Text != null) { bloc.title = tbx_title.Text; } else { bloc.title = ""; } Panel pnl_links = (Panel)e.Item.FindControl("pnl_links"); Panel pnl_files = (Panel)e.Item.FindControl("pnl_files"); Panel pnl_video = (Panel)e.Item.FindControl("pnl_video"); #region General if (!pnl_links.Visible && !pnl_files.Visible && !pnl_video.Visible) { TextBox tbx_content = (TextBox)e.Item.FindControl("tbx_contenu"); if (tbx_content.Text != null && tbx_content.Visible) { bloc.content = tbx_content.Text; } else { bloc.content = ""; } Image img = (Image)e.Item.FindControl("Image2"); if (img.ImageUrl != null && img.Visible) { bloc.photo = img.ImageUrl; } else { bloc.photo = ""; } if (bloc.content_type == null || bloc.content_type == "") { bloc.content_type = "text"; } } #endregion General #region Links else if (pnl_links.Visible) { TextBox tbx_link1 = (TextBox)e.Item.FindControl("tbx_link1"); TextBox tbx_link2 = (TextBox)e.Item.FindControl("tbx_link2"); TextBox tbx_link3 = (TextBox)e.Item.FindControl("tbx_link3"); TextBox tbx_link4 = (TextBox)e.Item.FindControl("tbx_link4"); TextBox tbx_text1 = (TextBox)e.Item.FindControl("tbx_text1"); TextBox tbx_text2 = (TextBox)e.Item.FindControl("tbx_text2"); TextBox tbx_text3 = (TextBox)e.Item.FindControl("tbx_text3"); TextBox tbx_text4 = (TextBox)e.Item.FindControl("tbx_text4"); DropDownList ddl_target1 = (DropDownList)e.Item.FindControl("ddl_target1"); DropDownList ddl_target2 = (DropDownList)e.Item.FindControl("ddl_target2"); DropDownList ddl_target3 = (DropDownList)e.Item.FindControl("ddl_target3"); DropDownList ddl_target4 = (DropDownList)e.Item.FindControl("ddl_target4"); List <Link> links = new List <Link>(); if (tbx_link1.Text != "") { Link link1 = new Link(); link1.Url = tbx_link1.Text; link1.Texte = tbx_text1.Text; link1.Target = (ddl_target1.SelectedIndex == 1 ? "_blank" : ""); links.Add(link1); } if (tbx_link2.Text != "") { Link link2 = new Link(); link2.Url = tbx_link2.Text; link2.Texte = tbx_text2.Text; link2.Target = (ddl_target2.SelectedIndex == 1 ? "_blank" : ""); links.Add(link2); } if (tbx_link3.Text != "") { Link link3 = new Link(); link3.Url = tbx_link3.Text; link3.Texte = tbx_text3.Text; link3.Target = (ddl_target3.SelectedIndex == 1 ? "_blank" : ""); links.Add(link3); } if (tbx_link4.Text != "") { Link link4 = new Link(); link4.Url = tbx_link4.Text; link4.Texte = tbx_text4.Text; link4.Target = (ddl_target4.SelectedIndex == 1 ? "_blank" : ""); links.Add(link4); } bloc.content = Functions.Serialize(links); bloc.content_type = "links"; bloc.photo = ""; } #endregion Links #region Video else if (pnl_video.Visible) { TextBox tbx_urlYT = (TextBox)e.Item.FindControl("tbx_urlYT"); Video video = new Video(); video.Url = tbx_urlYT.Text; if (video.Url.Contains("youtube")) { video.Type = "youtube"; } else if (video.Url.Contains("vimeo")) { video.Type = "vimeo"; } else { video.Type = "daily"; } bloc.content = Functions.Serialize(video); bloc.photo = ""; bloc.content_type = "video/" + video.Type; } #endregion Video #region Files else { List <AIS_File> files = new List <AIS_File>(); if (bloc.content != null && bloc.content != "") { files = (List <AIS_File>)Functions.Deserialize(bloc.content, files.GetType()); } if (hfd_files.Value != "") { files = (List <AIS_File>)Functions.Deserialize(hfd_files.Value, files.GetType()); } hfd_filesToDelete.Value = ""; bloc.content = Functions.Serialize(files); bloc.photo = ""; bloc.content_type = "files"; } #endregion Files bloc.visible = "O"; RadioButtonList rbl = (RadioButtonList)e.Item.FindControl("rbl_type"); foreach (ListItem li in rbl.Items) { if (li.Selected) { bloc.type = "Bloc" + li.Value; } } if (bloc.ord == 0) { bloc.ord = (news.GetListBlocs().Count + 1) * 10; } if (!DataMapping.UpdateNewsBloc(bloc, Request.QueryString["newsid"])) { throw new Exception("Error during update"); } string url = Functions.UrlAddParam(Globals.NavigateURL(), "newsid", Request.QueryString["newsid"]); Response.Redirect(url); } #endregion Validate #region Upload Image if (e.CommandSource == e.Item.FindControl("btn_upload")) { FileUpload ful = (FileUpload)e.Item.FindControl("ful_img"); if (ful.HasFile) { ///////////////////////////////////////////////////////*Changer ici l'image*////////////////////////////////// string fileName = Path.GetFileName(Guid.NewGuid().ToString() + "-" + ful.PostedFile.FileName); string path = PortalSettings.HomeDirectory + accessPath + "/" + news.tag1 + "/Images/2015-2016/"; if (accessPath == "") { path = PortalSettings.HomeDirectory + "District/Courrier du District/" + news.tag1 + "/Images/2015-2016/"; } DirectoryInfo d = new DirectoryInfo(Server.MapPath(path)); if (!d.Exists) { d.Create(); } ful.PostedFile.SaveAs(Server.MapPath(path) + fileName); TextBox tbx_title = (TextBox)e.Item.FindControl("tbx_titre"); if (tbx_title.Text != null) { bloc.title = tbx_title.Text; } else { bloc.title = ""; } TextBox tbx_content = (TextBox)e.Item.FindControl("tbx_contenu"); if (tbx_content.Text != null) { bloc.content = tbx_content.Text; } else { bloc.content = ""; } RadioButtonList rbl_type = (RadioButtonList)e.Item.FindControl("rbl_type"); foreach (ListItem li in rbl_type.Items) { if (li.Selected) { bloc.type = "Bloc" + li.Value; } } bloc.photo = path + fileName; List <News.Bloc> blocs = new List <News.Bloc>(); blocs.Add(bloc); LI_Blocs.DataSource = blocs; LI_Blocs.DataBind(); Button btn_upload = (Button)e.Item.FindControl("btn_upload"); btn_upload.Text = "Changer l'image"; } } #endregion Upload Image #region Upload Files if (e.CommandSource == e.Item.FindControl("btn_uploadFiles")) { FileUpload ful = (FileUpload)e.Item.FindControl("ful_files"); if (ful.HasFile) { string fileName = Path.GetFileName(Guid.NewGuid().ToString() + "-" + ful.PostedFile.FileName); string path = PortalSettings.HomeDirectory + accessPath + "/" + news.tag1 + "/Documents/2015-2016/"; if (accessPath == "") { path = PortalSettings.HomeDirectory + "District/Courrier du District/" + news.tag1 + "/Documents/2015-2016/"; } DirectoryInfo d = new DirectoryInfo(Server.MapPath(path)); if (!d.Exists) { d.Create(); } ful.PostedFile.SaveAs(Server.MapPath(path) + fileName); TextBox tbx_title = (TextBox)e.Item.FindControl("tbx_titre"); if (tbx_title.Text != null) { bloc.title = tbx_title.Text; } else { bloc.title = ""; } RadioButtonList rbl_type = (RadioButtonList)e.Item.FindControl("rbl_type"); foreach (ListItem li in rbl_type.Items) { if (li.Selected) { bloc.type = "Bloc" + li.Value; } } bloc.visible = "O"; List <AIS_File> files = new List <AIS_File>(); if (bloc.content != null && bloc.content != "") { files = (List <AIS_File>)Functions.Deserialize(bloc.content, files.GetType()); } else if (Request.QueryString["add"] != null && Request.QueryString["add"] != "" && Request.QueryString["add"] == "true") { files = hfd_filesToDelete.Value == "" ? new List <AIS_File>() : (List <AIS_File>)Functions.Deserialize(hfd_filesToDelete.Value, files.GetType()); } AIS_File file = new AIS_File(); file.Name = ful.PostedFile.FileName; file.Url = path + fileName; files.Add(file); bloc.content = Functions.Serialize(files); bloc.content_type = "files"; bloc.photo = ""; hfd_files.Value = Functions.Serialize(files); List <AIS_File> filesToDelete = new List <AIS_File>(); if (hfd_filesToDelete.Value != "") { filesToDelete = (List <AIS_File>)Functions.Deserialize(hfd_filesToDelete.Value, files.GetType()); } filesToDelete.Add(file); hfd_filesToDelete.Value = Functions.Serialize(filesToDelete); List <News.Bloc> blocs = new List <News.Bloc>(); blocs.Add(bloc); if (bloc.id != null && Request.QueryString["newsid"] != null && Request.QueryString["newsid"] != "") { if (!DataMapping.UpdateNewsBloc(bloc, Request.QueryString["newsid"])) { throw new Exception("Error during update"); } } LI_Blocs.DataSource = blocs; LI_Blocs.DataBind(); /*blocs = DataMapping.GetNews_EN(news.id).GetListBlocs(); * * foreach(News.Bloc b in blocs) * { * if (b.content == bloc.content) * bloc = b; * } * String url = Functions.UrlAddParam(Globals.NavigateURL(), "newsid", news.id); * url = Functions.UrlAddParam(Globals.NavigateURL(), "blocid", bloc.id); * if(Request.QueryString["add"]!= null && Request.QueryString["add"]!="" && Request.QueryString["add"] =="true") * url = Functions.UrlAddParam(Globals.NavigateURL(), "add", "true"); * else if (Request.QueryString["edit"] != null && Request.QueryString["edit"] != "" && Request.QueryString["edit"] == "true") * url = Functions.UrlAddParam(Globals.NavigateURL(), "edit", "true"); * * Response.Redirect(url);*/ } } #endregion Upload Files #region Up/Down if (e.CommandSource == e.Item.FindControl("ibt_up")) { foreach (News.Bloc b in news.GetListBlocs()) { if (b.id == e.CommandName) { bloc = b; } } if (bloc.ord > 10) { News.Bloc blocOnTop = null; foreach (News.Bloc b in news.GetListBlocs()) { if (b.ord == bloc.ord - 10) { blocOnTop = b; } } if (blocOnTop == null) { throw new Exception("Error bloc on top"); } int tempOrd = bloc.ord; bloc.ord = blocOnTop.ord; blocOnTop.ord = tempOrd; if (!DataMapping.UpdateNewsBloc(bloc)) { throw new Exception("Error update bloc"); } if (!DataMapping.UpdateNewsBloc(blocOnTop)) { throw new Exception("Error update bloc on top"); } } news = DataMapping.GetNews_EN(Request.QueryString["newsid"]); LI_Blocs.DataSource = news.GetListBlocs(); LI_Blocs.DataBind(); } if (e.CommandSource == e.Item.FindControl("ibt_down")) { foreach (News.Bloc b in news.GetListBlocs()) { if (b.id == e.CommandName) { bloc = b; } } if (bloc.ord < 10 * (news.GetListBlocs().Count)) { News.Bloc blocOnBot = null; foreach (News.Bloc b in news.GetListBlocs()) { if (b.ord == bloc.ord + 10) { blocOnBot = b; } } if (blocOnBot == null) { throw new Exception("Error bloc on top"); } int tempOrd = bloc.ord; bloc.ord = blocOnBot.ord; blocOnBot.ord = tempOrd; if (!DataMapping.UpdateNewsBloc(bloc)) { throw new Exception("Error update bloc"); } if (!DataMapping.UpdateNewsBloc(blocOnBot)) { throw new Exception("Error update bloc on bottom"); } } news = DataMapping.GetNews_EN(Request.QueryString["newsid"]); LI_Blocs.DataSource = news.GetListBlocs(); LI_Blocs.DataBind(); } #endregion Up/Down #region cancel if (e.CommandSource == e.Item.FindControl("btn_cancel")) { if (bloc.content != "" && bloc.type == "BlocFiles") { List <AIS_File> files = new List <AIS_File>(); if (bloc.content != null && bloc.content != "") { files = (List <AIS_File>)Functions.Deserialize(bloc.content, files.GetType()); } if (hfd_files.Value != "") { files = (List <AIS_File>)Functions.Deserialize(hfd_files.Value, files.GetType()); } List <AIS_File> filesToDelete = new List <AIS_File>(); if (hfd_filesToDelete.Value != "") { filesToDelete = (List <AIS_File>)Functions.Deserialize(hfd_filesToDelete.Value, filesToDelete.GetType()); if (filesToDelete.Count == 0) { throw new Exception("Zero files"); } foreach (AIS_File fi in files) { bool breaker = false; foreach (AIS_File f in filesToDelete) { if (fi.Url == f.Url) { files.Remove(fi); breaker = true; break; } } if (breaker) { break; } } } bloc.content = Functions.Serialize(files); bloc.photo = ""; bloc.content_type = "files"; bloc.visible = "O"; RadioButtonList rbl = (RadioButtonList)e.Item.FindControl("rbl_type"); foreach (ListItem li in rbl.Items) { if (li.Selected) { bloc.type = "Bloc" + li.Value; } } if (bloc.ord == 0) { bloc.ord = (news.GetListBlocs().Count + 1) * 10; } if (!DataMapping.UpdateNewsBloc(bloc, Request.QueryString["newsid"])) { throw new Exception("Error during update"); } } String url = Functions.UrlAddParam(Globals.NavigateURL(), "newsid", Request.QueryString["newsid"]); Response.Redirect(url); } #endregion cancel } catch (Exception ee) { Functions.Error(ee); } }
protected void repeat_bloc_ItemCommand(object source, RepeaterCommandEventArgs e) { string seo = "" + Request.QueryString["sn"]; Club club = DataMapping.GetClubBySeo(seo); #region editBloc if (e.CommandSource == (LinkButton)e.Item.FindControl("btn_editBloc")) { LinkButton btn_editBloc = (LinkButton)e.Item.FindControl("btn_editBloc"); btn_validate.CommandArgument = btn_editBloc.CommandArgument; pnl_add.Visible = true; btn_addBloc.Visible = false; repeat_bloc.Visible = false; News.Bloc bloc = DataMapping.GetNews_EN(DataMapping.ListNews(cric: club.cric, category: "accueilclub").FirstOrDefault().id).GetListBlocs().Where(x => x.id == btn_editBloc.CommandArgument).First(); switch (bloc.type) { case "BlocNoPhoto": tbx_contenu.Text = bloc.content; break; case "BlocVideo": Video vid = new Video(); vid = (Video)Functions.Deserialize(bloc.content, vid.GetType()); tbx_url.Text = vid.Url; break; default: img.ImageUrl = bloc.photo; break; } foreach (ListItem li in rbl_type.Items) { if ("Bloc" + li.Value == bloc.type) { li.Selected = true; } } tbx_titre.Text = bloc.title; } #endregion editBloc else if (e.CommandSource == (LinkButton)e.Item.FindControl("btn_delete")) { LinkButton btn_delete = (LinkButton)e.Item.FindControl("btn_delete"); News.Bloc bloc = DataMapping.GetNews_EN(DataMapping.ListNews(cric: club.cric, category: "accueilclub").FirstOrDefault().id).GetListBlocs().Where(x => x.id == btn_delete.CommandArgument).FirstOrDefault(); if (bloc == null) { throw new Exception("bloc null"); } if (!DataMapping.DeleteNewsBloc(bloc)) { throw new Exception("An error occured while deleting the bloc"); } Response.Redirect("~/" + club.seo + "/"); } else if (e.CommandSource == (LinkButton)e.Item.FindControl("lbt_up")) { int cric = club.cric; LinkButton lbt_up = (LinkButton)e.Item.FindControl("lbt_up"); News news = DataMapping.ListNews(cric: cric, category: "accueilclub").FirstOrDefault(); News.Bloc bloc = DataMapping.GetNews_EN(DataMapping.ListNews(cric: club.cric, category: "accueilclub").FirstOrDefault().id).GetListBlocs().Where(x => x.id == lbt_up.CommandArgument).FirstOrDefault();; News.Bloc bloc_up = null; foreach (News.Bloc b in DataMapping.GetNews_EN(DataMapping.ListNews(cric: club.cric, category: "accueilclub").FirstOrDefault().id).GetListBlocs()) { if (bloc != null && b.ord == bloc.ord - 10) { bloc_up = b; } } if (bloc == null || bloc_up == null) { throw new Exception("Error can't find blocs"); } int tempord = bloc.ord; bloc.ord = bloc_up.ord; bloc_up.ord = tempord; DataMapping.UpdateNewsBloc(bloc, news.id); DataMapping.UpdateNewsBloc(bloc_up, news.id); Response.Redirect("~/" + club.seo + "/"); } else if (e.CommandSource == (LinkButton)e.Item.FindControl("lbt_down")) { int cric = club.cric; LinkButton lbt_down = (LinkButton)e.Item.FindControl("lbt_down"); News news = DataMapping.ListNews(cric: cric, category: "accueilclub").FirstOrDefault(); News.Bloc bloc = DataMapping.GetNews_EN(DataMapping.ListNews(cric: club.cric, category: "accueilclub").FirstOrDefault().id).GetListBlocs().Where(x => x.id == lbt_down.CommandArgument).FirstOrDefault();; News.Bloc bloc_up = null; foreach (News.Bloc b in DataMapping.GetNews_EN(DataMapping.ListNews(cric: club.cric, category: "accueilclub").FirstOrDefault().id).GetListBlocs()) { if (bloc != null && b.ord == bloc.ord + 10) { bloc_up = b; } } if (bloc == null || bloc_up == null) { throw new Exception("Error can't find blocs"); } int tempord = bloc.ord; bloc.ord = bloc_up.ord; bloc_up.ord = tempord; DataMapping.UpdateNewsBloc(bloc, news.id); DataMapping.UpdateNewsBloc(bloc_up, news.id); Response.Redirect("~/" + club.seo + "/"); } }