Esempio n. 1
0
        public static List <Commande> readAll()
        {
            List <Commande> res      = new List <Commande>();
            Commande        commande = null;

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = "SELECT * FROM materiels";
            cmd.Connection  = Connexion.getInstance();

            try
            {
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    float   prixTotal    = float.Parse(reader["prixTotal"].ToString());
                    int     effectifMT   = Int32.Parse(reader["effectifMaterielTotal"].ToString());
                    string  typeCommande = reader["typeCommande"].ToString();
                    Clients idCl         = ClientsADO.findById(reader["idCl"].ToString());
                    commande = new Commande(prixTotal, effectifMT, typeCommande, idCl);
                    res.Add(commande);
                }
                cmd = null;
                reader.Close();
                reader = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de dataReader : " + ex.Message);
            }
            return(res);
        }
Esempio n. 2
0
        public static List <Achat> readAll()
        {
            List <Achat> res   = new List <Achat>();
            Achat        achat = null;

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = "SELECT * FROM locations";
            cmd.Connection  = Connexion.getInstance();

            try
            {
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Commande idCo       = CommandeADO.findById(reader["idCo"].ToString());
                    bool     demandeL   = bool.Parse(reader["demandeLivraison"].ToString());
                    float    prixTotal  = float.Parse(reader["prixTotal"].ToString());
                    int      effectifMT = Int32.Parse(reader["effectifMaterielTotal"].ToString());
                    Clients  idCl       = ClientsADO.findById(reader["idCl"].ToString());
                    achat = new Achat(idCo, demandeL, prixTotal, effectifMT, idCl);
                    res.Add(achat);
                }
                cmd = null;
                reader.Close();
                reader = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de dataReader : " + ex.Message);
            }
            return(res);
        }
Esempio n. 3
0
 private void dataClients()
 {
     foreach (Clients cl in ClientsADO.readAll())
     {
         dGVClients.Rows.Add(cl.Nom, cl.Prenom, cl.Adresse, cl.Ville, cl.CodePostal, cl.NumFixe, cl.NumPortable, cl.Mail);
     }
 }
Esempio n. 4
0
        public static Location findById(string id)
        {
            Location loc = null;

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = "SELECT * FROM locations WHERE idCo = @idCo";
            cmd.Parameters.AddWithValue("@idCo", id);

            //Connexion temporaire !
            string          chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8";
            MySqlConnection connexion         = null;

            try
            {
                connexion = new MySqlConnection(chaineDeConnexion);
                connexion.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de connexion : " + ex.Message);
            }
            cmd.Connection = connexion;

            try
            {
                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    Commande idCo       = CommandeADO.findById(reader["idCo"].ToString());
                    DateTime dateD      = DateTime.Parse(reader["dateDebut"].ToString());
                    DateTime dateF      = DateTime.Parse(reader["dateFin"].ToString());
                    bool     demandeI   = bool.Parse(reader["demandeInstallation"].ToString());
                    float    prixTotal  = float.Parse(reader["prixTotal"].ToString());
                    int      effectifMT = Int32.Parse(reader["effectifMaterielTotal"].ToString());
                    Clients  idCl       = ClientsADO.findById(reader["idCl"].ToString());
                    loc = new Location(idCo, dateD, dateF, demandeI, prixTotal, effectifMT, idCl);
                }
                cmd = null;
                reader.Close();
                reader = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de dataReader : " + ex.Message);
            }

            connexion.Close();
            connexion = null;
            return(loc);
        }
Esempio n. 5
0
        // **************************************** RECHERCHE **************************************
        public static List <Achat> findByRecherche(string recherche)
        {
            List <Achat> res   = new List <Achat>();
            Achat        achat = null;

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = "SELECT * FROM achats WHERE idCo LIKE '" + recherche + "%'";

            //Connexion temporaire !
            string          chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8";
            MySqlConnection connexion         = null;

            try
            {
                connexion = new MySqlConnection(chaineDeConnexion);
                connexion.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de connexion : " + ex.Message);
            }
            cmd.Connection = connexion;

            try
            {
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    Commande idCo       = CommandeADO.findById(reader["idCo"].ToString());
                    DateTime dateA      = DateTime.Parse(reader["dateAchat"].ToString());
                    bool     demandeL   = bool.Parse(reader["demandeLivraison"].ToString());
                    float    prixTotal  = float.Parse(reader["prixTotal"].ToString());
                    int      effectifMT = Int32.Parse(reader["effectifMaterielTotal"].ToString());
                    Clients  idCl       = ClientsADO.findById(reader["idCl"].ToString());
                    achat = new Achat(idCo, dateA, demandeL, prixTotal, effectifMT, idCl);
                    res.Add(achat);
                }
                cmd = null;
                reader.Close();
                reader = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de dataReader : " + ex.Message);
            }
            connexion.Close();
            connexion = null;
            return(res);
        }
Esempio n. 6
0
        public static Commande findById(string id)
        {
            Commande mat = null;

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = "SELECT * FROM commandes WHERE idCo = @idCo";
            cmd.Parameters.AddWithValue("@idCo", id);

            //Connexion temporaire !
            string          chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8";
            MySqlConnection connexion         = null;

            try
            {
                connexion = new MySqlConnection(chaineDeConnexion);
                connexion.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de connexion : " + ex.Message);
            }
            cmd.Connection = connexion;

            try
            {
                MySqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    float   prixTotal    = float.Parse(reader["prixTotal"].ToString());
                    int     effectifMT   = Int32.Parse(reader["effectifMaterielTotal"].ToString());
                    string  typeCommande = reader["typeCommande"].ToString();
                    Clients idCl         = ClientsADO.findById(reader["idCl"].ToString());
                    mat = new Commande(prixTotal, effectifMT, typeCommande, idCl);
                }
                cmd = null;
                reader.Close();
                reader = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de dataReader : " + ex.Message);
            }

            connexion.Close();
            connexion = null;
            return(mat);
        }
Esempio n. 7
0
        // **************************************** RECHERCHE **************************************
        public static List <Commande> findByRecherche(string recherche)
        {
            List <Commande> res      = new List <Commande>();
            Commande        commande = null;

            MySqlCommand cmd = new MySqlCommand();

            cmd.CommandText = "SELECT * FROM commandes WHERE idCo LIKE '" + recherche + "%'";

            //Connexion temporaire !
            string          chaineDeConnexion = "server=localhost; database=projet dj; username=root; Pooling=true; charset=utf8";
            MySqlConnection connexion         = null;

            try
            {
                connexion = new MySqlConnection(chaineDeConnexion);
                connexion.Open();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de connexion : " + ex.Message);
            }
            cmd.Connection = connexion;

            try
            {
                MySqlDataReader reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    float   prixTotal    = float.Parse(reader["prixTotal"].ToString());
                    int     effectifMT   = Int32.Parse(reader["effectifMaterielTotal"].ToString());
                    string  typeCommande = reader["typeCommande"].ToString();
                    Clients idCl         = ClientsADO.findById(reader["idCl"].ToString());
                    commande = new Commande(prixTotal, effectifMT, typeCommande, idCl);
                    res.Add(commande);
                }
                cmd = null;
                reader.Close();
                reader = null;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Erreur de dataReader : " + ex.Message);
            }
            connexion.Close();
            connexion = null;
            return(res);
        }
Esempio n. 8
0
        private void VosCommandes_Load(object sender, EventArgs e)
        {
            try
            {
                connect.Open();
                MessageBox.Show("connecté");
            }
            catch (MySqlException co)
            {
                MessageBox.Show(" non connecté");
                MessageBox.Show(co.ToString());
            }

            foreach (Clients cl in ClientsADO.readAll())
            {
                if (cl.Id == this.idCl)
                {
                    lblNom.Text    = cl.Nom;
                    lblPrenom.Text = cl.Prenom;
                }
            }
        }
Esempio n. 9
0
        private void BtnConnexion_Click(object sender, EventArgs e)
        {
            bool logCl = false;
            bool mdpCl = false;
            bool logAd = false;
            bool mdpAd = false;
            bool check = chkAdmin.ThreeState;


            //Si admin
            if (chkAdmin.Checked == true)
            {
                //Parcours des administrateurs
                foreach (Administrateur ad in AdministrateurADO.readAll())
                {
                    if (ad.Mail.Equals(txtLogin.Text) && ad.Motdepasse.Equals(txtMDP.Text))
                    {
                        logAd = true;
                        mdpAd = true;
                    }
                    else if (ad.Mail.Equals(txtLogin.Text) && !ad.Motdepasse.Equals(txtMDP.Text))
                    {
                        logAd = true;
                    }

                    else if (!ad.Mail.Equals(txtLogin.Text) && ad.Motdepasse.Equals(txtMDP.Text))
                    {
                        mdpAd = true;
                    }
                }

                if (logAd && !mdpAd)
                {
                    MessageBox.Show("mot de passe incorrect");
                }
                else if (!logAd && mdpAd)
                {
                    MessageBox.Show("login incorrect");
                }

                else if (logAd && mdpAd)
                {
                    admin.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("mail ou mot de passe incorrect");
                }
            }

            //Si pas admin
            else
            {
                // Parcours des clients
                foreach (Clients cl in ClientsADO.readAll())
                {
                    // Si les informations sont bonnes
                    if (cl.Mail.Equals(txtLogin.Text) && cl.Motdepasse.Equals(txtMDP.Text))
                    {
                        logCl     = true;
                        mdpCl     = true;
                        this.idCl = cl.Id;
                    }
                    else if (cl.Mail.Equals(txtLogin.Text) && !cl.Motdepasse.Equals(txtMDP.Text))
                    {
                        logCl = true;
                    }

                    else if (!cl.Mail.Equals(txtLogin.Text) && cl.Motdepasse.Equals(txtMDP.Text))
                    {
                        mdpCl = true;
                    }
                }

                if (logCl && !mdpCl)
                {
                    MessageBox.Show("mot de passe incorrect");
                }
                else if (!logCl && mdpCl)
                {
                    MessageBox.Show("login incorrect");
                }

                else if (logCl && mdpCl)
                {
                    locAchat = new LocAchat(this.idCl);
                    locAchat.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("mail ou mot de passe incorrect");
                }
            }
        }