public static void DeleteBorne(Borne borne)
        {
            FacSecondaireEntities facSecondaireEntity = new FacSecondaireEntities();

            facSecondaireEntity.Borne.Remove(borne);
            facSecondaireEntity.SaveChanges();
        }
        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            if (txtUserID.Text != "")
            {
                string message = "Voulez vous vraiment signaler l'utilisateur " + txtUserID.Text + "?";
                string caption = "Form Closing";
                var    result  = MessageBox.Show(message, caption,
                                                 MessageBoxButtons.YesNo,
                                                 MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    Borne borneDisqualifiant = new Borne();
                    borneDisqualifiant.user_id    = txtUserID.Text;
                    borneDisqualifiant.temps      = DateTime.Now;
                    borneDisqualifiant.nb_passage = -2;
                    BorneClass.setBorne(borneDisqualifiant);
                    lblErreur.Text    = "L'utilisateur " + txtUserID.Text + " est signalé.";
                    lblErreur.Visible = true;
                }
            }
            else
            {
                MessageBox.Show("Aucun utilisateur est sélectionné.");
            }
        }
        public static void setBorne(Borne borne)
        {
            FacSecondaireEntities facSecondaireEntity = new FacSecondaireEntities();

            facSecondaireEntity.Borne.Add(borne);

            facSecondaireEntity.SaveChanges();
        }
        private void btnTour_Click(object sender, EventArgs e)
        {
            lblErreur.Visible = false;

            // Vérifie si il existe bien cet utilisateur
            if (UserClass.getExistUser(txtUserIDmanuel.Text))
            {
                User     user            = UserClass.getUserID(txtUserIDmanuel.Text);
                Borne    lastPassage     = new Borne();
                DateTime lastPassageTime = new DateTime();
                int      nbPassage       = 0;

                // Vérifie si il y a déjà un tour qui a ete effectué par l'utilisateur
                if (BorneClass.getExistBorne(user.user_id))
                {
                    lastPassage = BorneClass.getLastNbPassageByUserID(user.user_id);

                    lastPassageTime = lastPassage.temps;
                    nbPassage       = lastPassage.nb_passage;
                }

                // vérifie si le temps entre deux passages est en dessous de 10 secondes
                int dateCompare = (DateTime.Now.Second + DateTime.Now.Minute * 60 + DateTime.Now.Hour * 3600) - (lastPassageTime.Second + lastPassageTime.Minute * 60 + lastPassageTime.Hour * 3600);
                if (dateCompare > 10)
                {
                    Borne newPassage = new Borne();
                    newPassage.user_id    = user.user_id;
                    newPassage.nb_passage = nbPassage + 1;
                    newPassage.temps      = DateTime.Now;
                    BorneClass.setBorne(newPassage);

                    txtUserID.Text = user.user_id;
                    if (user.nom != null)
                    {
                        txtNom.Text = user.nom;
                    }
                    if (user.prenom != null)
                    {
                        txtPrenom.Text = user.prenom;
                    }
                    txtPassage.Text = newPassage.nb_passage.ToString();
                    txtHeure.Text   = newPassage.temps.ToShortTimeString();
                }
                else
                {
                    lblErreur.Text    = "Probleme : Double passage !";
                    lblErreur.Visible = true;
                }

                // Reinitialise le champ manuel
                txtUserIDmanuel.Text = "";
            }
            else
            {
                lblErreur.Text    = "ID Utilisateur inconnu";
                lblErreur.Visible = true;
            }
        }
        public static Borne getLastNbPassageByUserID(string id)
        {
            Borne borne = new Borne();
            FacSecondaireEntities facSecondaireEntity = new FacSecondaireEntities();
            var borneEntity = from b in facSecondaireEntity.Borne
                              where b.user_id == id
                              select b;

            borne = borneEntity.OrderByDescending(u => u.nb_passage).FirstOrDefault();
            return(borne);
        }
        public static Borne getPassageByNbPassage(string user_id, int nb_passage)
        {
            Borne borne = new Borne();
            FacSecondaireEntities facSecondaireEntity = new FacSecondaireEntities();
            var borneEntity = from b in facSecondaireEntity.Borne
                              where b.user_id == user_id && b.nb_passage == nb_passage
                              select b;

            borne = borneEntity.FirstOrDefault();
            return(borne);
        }
        private void btnDepart_Click(object sender, EventArgs e)
        {
            DateTime datenow = DateTime.Now;

            foreach (User user in UserClass.getAllListUsers())
            {
                Borne borne = new Borne();
                borne.user_id    = user.user_id;
                borne.nb_passage = 0;
                borne.temps      = datenow;
                BorneClass.setBorne(borne);
            }

            lblErreur.Text    = "Départ annoncé à : " + datenow.ToLongTimeString();
            lblErreur.Visible = true;
            btnDepart.Enabled = false;
        }
        public static List <Borne> getNombreTourAllListBorne()
        {
            List <Borne>          listBornes          = new List <Borne>();
            FacSecondaireEntities facSecondaireEntity = new FacSecondaireEntities();
            var borneEntities = facSecondaireEntity.classementNbTours2();

            foreach (classementNbTours2_Result borneResult in borneEntities)
            {
                Borne borne = new Borne();
                borne.borne_id   = 0;
                borne.user_id    = borneResult.user_id;
                borne.nb_passage = Convert.ToInt32(borneResult.nb_passage);
                borne.temps      = new DateTime();
                listBornes.Add(borne);
            }
            return(listBornes);
        }
        public static Boolean getExistBorne(string id)
        {
            Borne borne = new Borne();
            FacSecondaireEntities facSecondaireEntity = new FacSecondaireEntities();
            var borneEntity = from b in facSecondaireEntity.Borne
                              where b.user_id == id
                              select b;

            borne = borneEntity.FirstOrDefault();
            if (borne != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }