Example #1
0
        public void Insert(Eleve eleve)
        {
            string       idAuth     = lastInsert();
            MySqlCommand insertAuth = new MySqlCommand("INSERT INTO aauth_users(email,pass,username,banned,last_login,last_activity,date_created,forgot_exp,remember_time,remember_exp,verification_code,totp_secret,ip_address) " +
                                                       "VALUES(@email,@pass,NULL,0,NULL,NULL,NOW(),NULL,NULL,NULL,NULL,NULL,0)", Connection.GetCnx());

            insertAuth.Parameters.Add(new MySqlParameter("@email", eleve.GetLogin()));
            insertAuth.Parameters.Add(new MySqlParameter("@pass", HashPhp.Salt(eleve.GetPassword(), idAuth + 1)));
            Connection.GetCnx().Open();
            insertAuth.ExecuteNonQuery();
            long lastidAuth = insertAuth.LastInsertedId;

            Connection.GetCnx().Close();

            MySqlCommand insert = new MySqlCommand("INSERT INTO Eleve(idClasse,nom,prenom,login,idAuth) VALUES(@idClasse,@nom,@prenom,@login,@idAuth)", Connection.GetCnx());

            insert.Parameters.Add(new MySqlParameter("@idClasse", eleve.GetIdClasse()));
            insert.Parameters.Add(new MySqlParameter("@nom", eleve.GetNom()));
            insert.Parameters.Add(new MySqlParameter("@prenom", eleve.GetPrenom()));
            insert.Parameters.Add(new MySqlParameter("@login", eleve.GetLogin()));
            insert.Parameters.Add(new MySqlParameter("@idAuth", lastidAuth));

            Connection.GetCnx().Open();
            insert.ExecuteNonQuery();
            Connection.GetCnx().Close();

            MySqlCommand insertAuthToGroup = new MySqlCommand("INSERT INTO  aauth_user_to_group(user_id,group_id)VALUES (@lastidAuth,4) ", Connection.GetCnx());

            insertAuthToGroup.Parameters.Add(new MySqlParameter("@lastidAuth", lastidAuth));
            Connection.GetCnx().Open();
            insertAuthToGroup.ExecuteNonQuery();
            Connection.GetCnx().Close();
        }
        //Méthode permettant de lire un fichier csv contenant la liste des élèves et génère une collection d'élèves avec leur mot de passe
        public List <Eleve> LoadCsv(PassWordType type, long id)
        {
            StreamReader reader = new StreamReader(@"U:\RallyeLecture\maClasseCm2_2018.csv");

            while (!reader.EndOfStream)
            {
                var    ligne  = reader.ReadLine();
                var    values = ligne.Split(';');
                string login;
                login = values[1] + values[0] + "@sio.jjr.fr";
                Eleve unEleve = new Eleve(values[0], values[1], login, type, id);
                lesEleves.Add(unEleve);
            }
            return(lesEleves);
        }
Example #3
0
 public List <Eleve> LoadCsv(PassWordType type, StreamReader fichier)
 {
     fichier.ReadLine();
     while (fichier.EndOfStream == false)
     {
         string   temp = fichier.ReadLine();
         string[] te   = temp.Split(';');
         string   nom;
         string   prenom;
         nom    = te[0];
         prenom = te[1];
         string login = prenom + nom + "@sio.jjr.fr";
         Eleve  s     = new Eleve(nom, prenom, login, type);
         lesEleves.Add(s);
         Console.WriteLine(nom + " " + prenom + "Chargé !");
     }
     return(lesEleves);
 }
Example #4
0
        //Permet de créer un élève dans la table élève
        public void Insert(Eleve eleve, long idClasse)
        {
            //récupère l'id de la classe



            //récupère l'id du aauth_users
            cnx = ConnectionMySql.GetConnection();
            MySqlCommand cmd1 = new MySqlCommand();

            cmd1.Connection = cnx;
            cnx.Open();
            cmd1.CommandText = "select max(id) from aauth_users";
            cmd1.CommandType = CommandType.Text;
            int idAauth = Convert.ToInt32(cmd1.ExecuteScalar());

            cnx.Close();

            Hash pass = new Hash();


            //créer un utilisateur dans la table aauth_users
            cnx = ConnectionMySql.GetConnection();
            MySqlCommand cmd2 = new MySqlCommand();

            cmd2.Connection = cnx;
            cnx.Open();
            cmd2.CommandText = "insert into aauth_users(email,pass,username) values(@email,@passWord,@username) ";
            cmd2.CommandType = CommandType.Text;
            cmd2.Parameters.Add("@email", MySqlDbType.String);
            cmd2.Parameters["@email"].Value = eleve.Prenom + eleve.Nom + "@sio.jjr.fr";
            cmd2.Parameters.Add("@username", MySqlDbType.String);
            cmd2.Parameters["@username"].Value = eleve.Prenom[0] + eleve.Nom;
            cmd2.Parameters.Add("@passWord", MySqlDbType.String);
            cmd2.Parameters["@passWord"].Value = pass.GetHashPassword(eleve.PassWord, idAauth + 1);
            cmd2.ExecuteNonQuery();
            cnx.Close();

            cnx = ConnectionMySql.GetConnection();
            MySqlCommand cmd4 = new MySqlCommand();

            cmd4.Connection = cnx;
            cnx.Open();
            cmd4.CommandText = "insert into aauth_user_to_group(user_id,group_id) values(@idUser,@idGroup)";
            cmd4.CommandType = CommandType.Text;
            cmd4.Parameters.Add("@idUser", MySqlDbType.Int32);
            cmd4.Parameters["@idUser"].Value = idAauth + 1;
            cmd4.Parameters.Add("@idGroup", MySqlDbType.Int32);
            cmd4.Parameters["@idGroup"].Value = 4;
            cmd4.ExecuteNonQuery();
            cnx.Close();

            TableClasse uneTableClasse = new TableClasse();

            idClasse = uneTableClasse.LastId;

            //créer un élève dans la table élève
            cnx = ConnectionMySql.GetConnection();
            MySqlCommand cmd = new MySqlCommand();

            cmd.Connection = cnx;
            cnx.Open();
            cmd.CommandText = "insert into eleve(idClasse,nom,prenom,login,idAuth) values(@idClasse,@nom,@prenom,@login,@idAuth)";
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add("@idClasse", MySqlDbType.Int32);
            cmd.Parameters["@idClasse"].Value = idClasse;
            cmd.Parameters.Add("@nom", MySqlDbType.String);
            cmd.Parameters["@nom"].Value = eleve.Nom;
            cmd.Parameters.Add("@prenom", MySqlDbType.String);
            cmd.Parameters["@prenom"].Value = eleve.Prenom;
            cmd.Parameters.Add("@login", MySqlDbType.String);
            cmd.Parameters["@login"].Value = eleve.Login;
            cmd.Parameters.Add("@idAuth", MySqlDbType.Int32);
            cmd.Parameters["@idAuth"].Value = idAauth + 1;
            cnx.Close();
        }
Example #5
0
        private void tb_annee_TextChanged(object sender, EventArgs e)
        {
            Eleve test = new Eleve("dfe", "dsfds", "dsde", PassWordType.Aleatoire);

            tb_annee.Text = test.GetPswd;
        }