//création d'un événement selon l'atelier donné
        HtmlGenericControl Create_Event_Item(DonneesAteliers _atelier)
        {
            HtmlGenericControl event_item = new HtmlGenericControl("div");

            event_item.Attributes.Add("class", "event_item");
            HtmlGenericControl ei_Title = new HtmlGenericControl("div");

            ei_Title.Attributes.Add("class", "ei_Title");
            ei_Title.InnerText = _atelier.contentTitle;
            HtmlGenericControl ei_Copy = new HtmlGenericControl("div");

            ei_Copy.Attributes.Add("class", "ei_Copy");
            ei_Copy.InnerText = _atelier.HeureDebut?.ToString("hh\\:mm");

            event_item.Controls.Add(ei_Title);
            event_item.Controls.Add(ei_Copy);

            return(event_item);
        }
        protected void AtelierCreation_Click(object sender, EventArgs e)
        {
            //validation de la page
            if (Page.IsValid)
            {
                bool reussi = true;
                try
                {
                    string sysFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
                    //Cération d'un nouvel atelier
                    var Atelier = new DonneesAteliers();
                    Atelier.contentTitle = txttitre.Text;
                    Atelier.campus       = txt_Campus.Text;
                    Atelier.Salle        = txt_salle.Text;
                    var adsf = DateTime.Now.ToString();
                    Atelier.dateDebut    = DateTime.ParseExact(txt_date.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                    Atelier.HeureDebut   = TimeSpan.Parse(txt_heure.Text);
                    Atelier.HeureFin     = TimeSpan.Parse(txt_heure_fin.Text);
                    Atelier.Max_Eleves   = int.Parse(txt_elevemax.Text);
                    Atelier.Conferencier = txt_conferencier.Text;
                    try
                    {
                        if (ImageUpload.FileName != "")
                        {
                            string folderPath = Server.MapPath("~/Images/");
                            ImageUpload.SaveAs(folderPath + Path.GetFileName(ImageUpload.FileName));

                            Atelier.posterPath = "Images/" + ImageUpload.FileName;
                        }
                        else
                        {
                            Atelier.posterPath = "Images/default-thumb.png";
                        }
                    }
                    catch
                    {
                        throw;
                    }

                    if (AtelierDataContext.DonneesAteliers.Where(a => a.contentTitle == Atelier.contentTitle).Count() > 0)
                    {
                        return;
                    }

                    AtelierDataContext.DonneesAteliers.InsertOnSubmit(Atelier); // un submit un pending
                    AtelierDataContext.SubmitChanges();                         // de dataContext


                    int newAtelierNum = Atelier.NumAtelier;



                    foreach (string tag in activeTags)
                    {
                        Ateliers_Tags newEntry = new Ateliers_Tags()
                        {
                            Description = tag,
                            NumAtelier  = newAtelierNum
                        };

                        AtelierDataContext.Ateliers_Tags.InsertOnSubmit(newEntry);
                        AtelierDataContext.SubmitChanges();
                    }
                }
                catch (Exception)
                {
                    reussi = false;
                    throw;
                }

                if (reussi)
                {
                    hiddenMessage.Attributes.Remove("class");
                    gvbind();
                }
                //lblSuccess.Text = $"L'ajout de l'atelier {txttitre.Text} à réussi!";
                else
                {
                    //lblSuccess.Text = $"L'ajout de l'atelier {txttitre.Text} n'a pas réussi...";
                    hiddenMessage.Attributes.Add("class", "hiddenMessage");
                }
            }
        }
        /// <summary>
        /// Crée un élément HTML qui sert de représentation brève d'un atelier.
        /// </summary>
        /// <param name="row">
        /// Un objet DonneesAtelier qui représente une rangée de la table DonneesAtelier
        /// </param>
        /// <returns>
        /// Un contrôle HTML Div prêt à être affiché.
        /// </returns>
        public static HtmlGenericControl CreateInfoPanel(DonneesAteliers row)
        {
            //Création des éléments HTML qui affichent des données simples.

            HtmlGenericControl panel = new HtmlGenericControl("div");

            panel.Attributes.Add("class", "info-panel");

            HtmlImage img = new HtmlImage
            {
                Src = row.posterPath
            };

            img.Attributes.Add("class", "align-self-start mr-3 img-thumbnail");

            HtmlGenericControl body = new HtmlGenericControl("div");

            body.Attributes.Add("class", "media-body");

            HtmlGenericControl title = new HtmlGenericControl("h4")
            {
                InnerText = row.contentTitle
            };

            title.Attributes.Add("class", "mt-0");

            HtmlGenericControl summary = new HtmlGenericControl("h5")
            {
                InnerText = row.sommaire
            };

            HtmlGenericControl data = new HtmlGenericControl("p")
            {
                InnerText = row.Conferencier + " | " + row.campus + " | " + row.Salle + " | " + row.dateDebut?.ToShortDateString() + " | "
                            + row.HeureDebut?.ToString(@"hh\:mm")
            };



            data.Attributes.Add("class", "mb-0 smallInfo");
            data.Attributes.Add("style", "clear:both");

            data.InnerText = data.InnerText.ToUpper();

            panel.Controls.Add(img);

            body.Controls.Add(title);
            body.Controls.Add(summary);
            body.Controls.Add(data);


            HtmlGenericControl subscriptionLine = new HtmlGenericControl("div");

            subscriptionLine.Attributes.Add("class", "subscriptionLine");
            int numSubs = context.Etudiant_Atelier.Count(sub => sub.NumAtelier == row.NumAtelier);
            int maxSubs = row.Max_Eleves.HasValue? row.Max_Eleves.Value : 0;


            //Création du bouton qui prend en charge la souscription.
            HtmlInputButton btnInscription;

            //Détermine si l'usager est connecté.
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                string username = HttpContext.Current.User.Identity.Name;

                string numUser = context.Etudiant.SingleOrDefault(etudiant => etudiant.username == username)
                                 .username;

                //Si SingleOrDefault ne ramène pas Null, l'étudiant est inscrit
                bool userAlreadySubscribed = context.Etudiant_Atelier.SingleOrDefault(entry => entry.Numero_Etudiant == numUser.ToString() &&
                                                                                      entry.NumAtelier == row.NumAtelier)
                                             != null;


                //Si aucune place restante, et l'utilisateur n'est pas deja inscrit, on crée un bouton
                //"Complet"
                if (numSubs >= maxSubs && !userAlreadySubscribed)
                {
                    btnInscription = new HtmlInputButton()
                    {
                        Value = "Complet"
                    };

                    btnInscription.Attributes.Add("class", "btn btn-secondary");
                }

                //Si l'utilisateur est déjà inscrit à cet atelier, on crée un bouton désinscription.
                //La méthode Unsubscribe est attachée à son événement ServerClick.
                else if (userAlreadySubscribed)
                {
                    btnInscription = new HtmlInputButton()
                    {
                        Value = "Désinscription",
                        ID    = row.NumAtelier.ToString()
                    };
                    btnInscription.ServerClick += Unsubscribe;
                    btnInscription.Attributes.Add("class", "btn btn-danger float-md-left");
                }

                //Sinon, un bouton pour l'inscription est créé. La méthode Subscribe prend en charge son evénement ServerClick.
                else
                {
                    btnInscription = new HtmlInputButton()
                    {
                        Value = "S'inscrire",
                        ID    = row.NumAtelier.ToString()
                    };

                    btnInscription.ServerClick += Subscribe;
                    btnInscription.Attributes.Add("class", "btn btn-success");
                }
                body.Controls.Add(btnInscription);
            }

            //Si l'usager n'est pas connecté, un bouton connexion est créé. Ce bouton reçoit par l'entremise de JQuery
            //une méthode qui affiche le Modal de connexion.
            else
            {
                btnInscription = new HtmlInputButton()
                {
                    Value = "Connexion"
                };

                btnInscription.Attributes.Add("class", "btn btn-secondary btn-login");
            }

            //Affiche le nombre de places restantes et le nombre de places maximum.
            HtmlGenericControl subsDisplay = new HtmlGenericControl("span")
            {
                InnerText = $"\t  {maxSubs - numSubs} / {maxSubs} places disponibles"
            };

            subscriptionLine.Controls.Add(subsDisplay);
            subscriptionLine.Controls.Add(btnInscription);

            body.Controls.Add(subscriptionLine);
            panel.Controls.Add(body);
            return(panel);
        }