/*Selectionner l'ensemble des commandes de la base de données * @param addPaiement : True pour insérer les paiements dans l'object commande * @param addArticles : True pour insérer les Articles dans l'objet Commande * @param addClient : True pour insérer les Clients dans l'objet Commande */ public static List <Commande> selectCommandes(Boolean addPaiement, Boolean addArticles, Boolean addClient) { try { List <Commande> retour = new List <Commande>(); //connection à la base de données MySqlCommand cmd = new MySqlCommand(Bdd.selectCommandes, Bdd.connexion()); //Execute la commande MySqlDataReader msdr = cmd.ExecuteReader(); Commande commande; while (msdr.Read()) { commande = new Commande( Int32.Parse(msdr["cmd_id"].ToString()), DateTime.Parse(msdr["cmd_date"].ToString()), Boolean.Parse(msdr["cmd_payee"].ToString()), float.Parse(msdr["cmd_remise"].ToString())); commande.client = new Client(); commande.client.id = Int32.Parse(msdr["cmd_clt_id"].ToString()); retour.Add(commande); } msdr.Dispose(); Bdd.deconnexion(); #region ajout paiement if (addPaiement) { foreach (Commande comm in retour) { comm.listPayements = PayementDAO.selectPayementByCommande(comm.id); } } #endregion #region ajout article if (addArticles) { foreach (Commande comm in retour) { comm.listArticles = ArticleDAO.selectArticleByIdCmd(comm.id); } } #endregion #region ajout client if (addClient) { foreach (Commande comm in retour) { //parametres en false afin de ne pas boucler comm.client = ClientDAO.selectClientById(comm.client.id, false, false, false); } } #endregion return(retour); } catch (Exception Ex) { MessageBox.Show("ERREUR BDD : selectCommandes"); Bdd.deconnexion(); return(null); } }
/*Selectionner une commande à partir de son id * @param addPaiement : True pour insérer les paiements dans l'object commande * @param addArticles : True pour insérer les Articles dans l'objet Commande */ public static Commande selectCommandeById(int id_cmd, Boolean addPaiement, Boolean addArticles, Boolean addClient) { try { Commande retour = new Commande(); //connection à la base de données MySqlCommand cmd = new MySqlCommand(Bdd.selectCommandeById, Bdd.connexion()); //ajout des parametres cmd.Parameters.AddWithValue("cmd_id", id_cmd); //Execute la commande MySqlDataReader msdr = cmd.ExecuteReader(); int id_clt = -1; while (msdr.Read()) { retour = new Commande( Int32.Parse(msdr["cmd_id"].ToString()), DateTime.Parse(msdr["cmd_date"].ToString()), Boolean.Parse(msdr["cmd_payee"].ToString()), float.Parse(msdr["cmd_remise"].ToString()) ); id_clt = Int32.Parse(msdr["cmd_clt_id"].ToString()); } msdr.Dispose(); Bdd.deconnexion(); #region ajout paiement if (addPaiement) { retour.listPayements = PayementDAO.selectPayementByCommande(retour.id); } #endregion #region ajout article if (addArticles) { retour.listArticles = ArticleDAO.selectArticleByIdCmd(retour.id); } #endregion #region ajout du client if (addClient) { if (id_clt > 0) { retour.client = ClientDAO.selectClientById(id_clt, false, false, false); } else if (id_clt == 0) { MessageBox.Show("Erreur (ComomandeDAO.cs:232) : impossible de rechercher un client dont l'id vaut 0"); } } #endregion return(retour); } catch (Exception Ex) { MessageBox.Show("ERREUR BDD : selectCommandeById"); Bdd.deconnexion(); return(null); } }