/// <summary>
        /// Exécution de la requête demandée en paramètre, req, 
        /// et retour du resultat : un DataTable
        /// Si tout se passe bien la connexion est prête à être fermée
        /// par le client qui utilisera cette connexion
        /// </summary>
        /// <param name="req">RequêteMySql à exécuter</param>
        /// <returns></returns>
        public static DataTable Lecture(String req, sErreurs er)
        {
            MySqlConnection cnx = null;
            try
            {
                cnx = Connexion.getInstance().getConnexion();
                MySqlCommand cmd = new MySqlCommand();
                cmd.Connection = cnx;
                cmd.CommandText = req;
                MySqlDataAdapter da = new MySqlDataAdapter();
                da.SelectCommand = cmd;

                // Construire le DataSet
                DataSet ds = new DataSet();
                da.Fill(ds, "resultat");
                cnx.Close();

                // Retourner la table
                return (ds.Tables["resultat"]);
            }
            catch (MonException me)
            {
                throw (me);
            }
            catch (Exception e)
            {

                throw new MonException(er.MessageUtilisateur(), er.MessageApplication(), e.Message);
            }
            finally
            {
                // S'il y a eu un problème, la connexion
                // peut être encore ouverte, dans ce cas
                // il faut la fermer.                 
                if (cnx != null)
                    cnx.Close();
            }
        }
Example #2
0
        /// <summary>
        /// Lire un utilisateur sur son ID
        /// </summary>
        /// <param name="numCli">N° de l'utilisateur à lire</param>
        public Clientel RechercheUnClient(String numCli)
        {

            String mysql;
            DataTable dt;
            sErreurs er = new sErreurs("Erreur sur recherche d'un client.", "Client.RechercheUnClient()");
            try
            {

                mysql = "SELECT SOCIETE, NOM_CL, PRENOM_CL,";
                mysql += "ADRESSE_CL, VILLE_CL, CODE_POST_CL ";
                mysql += "FROM CLIENTEL WHERE NO_CLIENT='" + numCli + "'";
                dt = DbInterface.Lecture(mysql, er);

                if (dt.IsInitialized)
                {
                    DataRow dataRow = dt.Rows[0];
                    this.noClient = numCli;
                    this.nomCl = dataRow[1].ToString();
                    this.societe = dataRow[0].ToString();
                    this.prenomCl = dataRow[2].ToString();
                    this.adresseCl = dataRow[3].ToString();
                    this.villeCl = dataRow[4].ToString();
                    this.codePostCl = dataRow[5].ToString();

                    return this;
                }
                else
                    return null;
            }
            catch (MySqlException e)
            {
                throw new MonException(er.MessageUtilisateur(), er.MessageApplication(), e.Message);
            }

        }
Example #3
0
        /// <summary>
        /// Lister les clients de la base
        /// </summary>
        /// <returns>Liste de numéros de clients</returns>
        public List<String> LectureNoClient()
        {
            List<String> mesNumeros = new List<String>();
            DataTable dt;
            sErreurs er = new sErreurs("Erreur sur lecture du client.", "Clientel.LectureNoClient()");
            try
            {

                String mysql = "SELECT DISTINCT NO_CLIENT FROM CLIENTEL ORDER BY NO_CLIENT";
                dt = DbInterface.Lecture(mysql, er);

                foreach (DataRow dataRow in dt.Rows)
                {
                    mesNumeros.Add((dataRow[0]).ToString());
                }

                return mesNumeros;
            }
            catch (MySqlException e)
            {
                throw new MonException(er.MessageUtilisateur(), er.MessageApplication(), e.Message);
            }
        }
Example #4
0
        /// <summary>
        /// Cherhcer les informations d'un vendeur d'après son numéro
        /// </summary>
        /// <param name="numVen"></param>
        /// <returns></returns>
        public Vendeur RechercheUnVendeur(String numVen)
        {

            String mysql;
            DataTable dt;
            sErreurs er = new sErreurs("Erreur sur recherche d'un vendeur.", "Vendeur.RechercheUnVendeur()");
            try
            {

                mysql = "SELECT NO_VEND_CHEF_EQ, NOM_VEND, PRENOM_VEND,";
                mysql += "DATE_EMBAU, VILLE_VEND, SALAIRE_VEND, COMMISSION ";
                mysql += "FROM VENDEUR WHERE NO_VENDEUR='" + numVen + "'";
                dt = DbInterface.Lecture(mysql, er);

                if (dt.IsInitialized)
                {
                    DataRow dataRow = dt.Rows[0];
                    this.noVendeur = numVen;
                    this.noChef = dataRow[0].ToString();
                    this.nomVend = dataRow[1].ToString();
                    this.prenomVend = dataRow[2].ToString();
                    this.dateEmbau = Fonctions.StringToDate(dataRow[3].ToString());
                    this.villeVend = dataRow[4].ToString();
                    this.salaireVend = double.Parse(dataRow[5].ToString());
                    this.commission = double.Parse(dataRow[6].ToString());

                    return this;
                }
                else
                    return null;
            }
            catch (MySqlException e)
            {
                throw new MonException(er.MessageUtilisateur(), er.MessageApplication(), e.Message);
            }

        }
        /// <summary>
        /// Rechercher un article d'après son numéro
        /// </summary>
        /// <param name="no_cmd">Numéro de l'article</param>
        /// <returns>article courante</returns>
        public Article RechercheArticle(String no_art)
        {

            String mysql;
            DataTable dt;
            sErreurs er = new sErreurs("Erreur sur recherche d'un article.", "Article.RechercheArticle()");
            try
            {

                mysql = "SELECT NO_ARTICLE, LIB_ARTICLE, QTE_DISPO, VILLE_ART, PRIX_ART, INTERROMPU ";
                mysql += "FROM ARTICLES ";
                mysql += "WHERE NO_ARTICLE = '" + no_art + "'";
                dt = DbInterface.Lecture(mysql, er);

                if (dt.IsInitialized)
                {
                    DataRow dataRow = dt.Rows[0];
                   
                    this.no_article = dataRow[0].ToString();
                    this.lib_article = dataRow[1].ToString();
                    this.qte_dispo = dataRow[2].ToString();
                    this.ville_art = dataRow[3].ToString();
                    this.prix_art = dataRow[4].ToString();
                    this.interrompu = dataRow[5].ToString();

                    return this;
                }
                else
                    return null;
            }
            catch (MySqlException e)
            {
                throw new MonException(er.MessageUtilisateur(), er.MessageApplication(), e.Message);
            }

        }