Пример #1
0
        public static IEnumerable <Commandes> getCommandes()
        {
            IEnumerable <Commandes> commandes = new List <Commandes>();
            DataTable dt;
            Commandes commande;
            Serreurs  er = new Serreurs("Erreur sur lecture des commandes.", "CommandesList.getCommandes()");

            try
            {
                string mysql = "SELECT c.NO_COMMAND, c.NO_VENDEUR, c.NO_CLIENT, c.DATE_CDE, ";
                mysql += "c.FACTURE, count(d.NO_COMMAND) NB_ARTICLES ";
                mysql += "FROM commandes c LEFT OUTER JOIN detail_cde d ";
                mysql += "ON c.NO_COMMAND=d.NO_COMMAND GROUP BY c.NO_COMMAND ORDER BY c.NO_COMMAND";

                dt = DBInterface.Lecture(mysql, er);

                foreach (DataRow dataRow in dt.Rows)
                {
                    commande            = new Commandes();
                    commande.NoCommande = dataRow[0].ToString();
                    String noVendeur = dataRow[1].ToString();
                    commande.NoVendeur = Vendeur.getVendeurById(noVendeur);
                    String noClient = dataRow[2].ToString();
                    commande.NoClient = Clientel.getClientById(noClient);
                    Match  match = Regex.Match(dataRow[3].ToString(), pattern);
                    String temp  = match.Groups[3].Value + "-" + match.Groups[2].Value + "-" + match.Groups[1].Value;
                    commande.DateCde   = temp;
                    commande.Facture   = dataRow[4].ToString();
                    commande.NbArticle = dataRow[5].ToString();

                    ((List <Commandes>)commandes).Add(commande);
                }

                return(commandes);
            }
            catch (MonException e)
            {
                throw new MonException(er.MessageUtilisateur(), er.MessageApplication(), e.Message);
            }
            catch (MySqlException e)
            {
                throw new MonException(er.MessageUtilisateur(), er.MessageApplication(), e.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// Lire une commande sur son ID
        /// </summary>
        /// <param name="numCom">N° de la commande à lire</param>
        public static Commandes getCommande(String numCom)
        {
            String    mysql;
            DataTable dt;
            Serreurs  er = new Serreurs("Erreur sur recherche d'une commande.", "Commandes.RechercheUneCommande()");

            try
            {
                mysql  = "SELECT c.NO_VENDEUR, c.NO_CLIENT, c.DATE_CDE, ";
                mysql += "c.FACTURE, count(*) NB_ARTICLES ";
                mysql += "FROM commandes c LEFT OUTER JOIN detail_cde d ON c.NO_COMMAND=d.NO_COMMAND ";
                mysql += "WHERE c.NO_COMMAND='" + numCom + "' GROUP BY c.NO_COMMAND";
                dt     = DBInterface.Lecture(mysql, er);
                System.Console.WriteLine(mysql);
                if (dt.IsInitialized && dt.Rows.Count > 0)
                {
                    Commandes commande = new Commandes();
                    DataRow   dataRow  = dt.Rows[0];
                    commande.NoCommande = numCom;
                    String noVendeur = dataRow[0].ToString();
                    commande.NoVendeur = Vendeur.getVendeurById(noVendeur);
                    String noClient = dataRow[1].ToString();
                    commande.NoClient = Clientel.getClientById(noClient);
                    Match  match = Regex.Match(dataRow[2].ToString(), pattern);
                    String temp  = match.Groups[3].Value + "-" + match.Groups[2].Value + "-" + match.Groups[1].Value;
                    commande.DateCde   = temp;
                    commande.Facture   = dataRow[3].ToString();
                    commande.NbArticle = dataRow[4].ToString();

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