Example #1
0
    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);
        }
    }
Example #2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            List <News.Bloc> blocs = new List <News.Bloc>();
            if (!IsPostBack)
            {
                pnl_add.Visible     = HasPermission() && Request.QueryString["edit"] != "true" && Request.QueryString["add"] != "true" && Request.QueryString["delete"] != "true";
                pnl_type.Visible    = Request.QueryString["edit"] == "true" || Request.QueryString["add"] == "true";
                hlk_add.NavigateUrl = Functions.UrlAddParam(Globals.NavigateURL(), "add", "true");
                hlk_add.NavigateUrl = Functions.UrlAddParam(hlk_add.NavigateUrl, "newsid", Request.QueryString["newsid"]);



                string newsid = ("" + Request.QueryString["newsid"]);
                if (newsid == "")
                {
                    Functions.Error(new Exception("Newsid inconnu : " + newsid));
                }

                HL_Print.NavigateUrl = print + "?popUp=true&print=yes&newsid=" + newsid;

                if (("" + Request.QueryString["print"]) != "")
                {
                    Response.Write("<script>window.print();</script>");
                    P_Share.Visible = false;
                }

                News news = DataMapping.GetNews_EN(newsid);
                if (news != null)
                {
                    LBL_Titre.Text = news.title;
                    LBL_Date.Text  = news.dt.ToShortDateString();

                    Club c = DataMapping.GetClub(news.cric);
                    if (c != null)
                    {
                        HLK_Club.Text        = c.name;
                        HLK_Club.NavigateUrl = Request.Url.AbsoluteUri.ToString().Replace(Request.Url.PathAndQuery, "") + "/" + c.seo + "/";
                    }
                    else
                    {
                        HLK_Club.Visible = false;
                    }


                    string blocid = ("" + Request.QueryString["blocid"]);
                    string add    = "" + Request.QueryString["add"];
                    if (blocid != "")
                    {
                        foreach (News.Bloc b in news.GetListBlocs())
                        {
                            if (b.id == blocid)
                            {
                                blocs.Add(b);
                            }
                        }
                    }
                    else
                    {
                        blocs = news.GetListBlocs();
                    }

                    if (add == "true")
                    {
                        blocs = new List <News.Bloc>();
                        News.Bloc bloc = new News.Bloc();
                        bloc.type = "BlocPhotoTop";
                        blocs.Add(bloc);
                    }
                }

                LI_Blocs.DataSource = blocs;
                LI_Blocs.DataBind();
            }
        }
        catch (Exception ee)
        {
            Functions.Error(ee);
        }
    }