Example #1
0
        }// fin CreerTableProfil

        /*public String SelectIdProduittest()
         * {
         *  this.ConnexionOpen();
         *  string sql = "select * from historique; ";
         *  SqliteCommand commanda = new SqliteCommand(sql, connexion);
         *  SqliteDataReader result = commanda.ExecuteReader();
         *  result.Read();
         *
         *  return result.GetString(0).ToString();
         * }*/

        //chargement du produit
        public Produits SelectIdProduit(String p, string IDTP)
        {
            /*-------------------------------------------------------*/
            /*---Petit code qui prend en compte PERS ET FAML si on clique sur INVT Etc...---*/
            /*-------------------------------------------------------*/
            String IdTpA = "";
            String IdTpN = "";

            if (IDTP == "PERS")
            {
                IdTpA = "'PERS'";
            }
            if (IDTP == "FAML")
            {
                IdTpA = "'FAML' " +
                        "OR PU.ID_critere = CA.ID_allergene " +
                        "AND CA.id_produit = '" + p + "'  " +
                        " AND PU.ID_typeProfil='PERS' " +
                        "GROUP BY PU.ID_critere";
            }
            if (IDTP == "INVT")
            {
                IdTpA = "'INVT'" +
                        "OR PU.ID_critere = CA.ID_allergene " +
                        "AND CA.id_produit = '" + p + "'  " +
                        " AND PU.ID_typeProfil='FAML' " +

                        "OR PU.ID_critere = CA.ID_allergene " +
                        "AND CA.id_produit = '" + p + "'  " +
                        " AND PU.ID_typeProfil='PERS' " +
                        "GROUP BY PU.ID_critere";
            }

            if (IDTP == "PERS")
            {
                IdTpN = "'PERS'";
            }
            if (IDTP == "FAML")
            {
                IdTpN = "'FAML' " +
                        "OR PU.ID_critere = CN.ID_nutriment " +
                        "AND CN.id_produit = '" + p + "'  " +
                        " AND PU.ID_typeProfil='PERS' " +

                        "GROUP BY PU.ID_critere";
            }
            if (IDTP == "INVT")
            {
                IdTpN = "'INVT' " +
                        "OR PU.ID_critere = CN.ID_nutriment " +
                        "AND CN.id_produit = '" + p + "'  " +
                        " AND PU.ID_typeProfil='PERS' " +

                        "OR PU.ID_critere = CN.ID_nutriment " +
                        "AND CN.id_produit = '" + p + "'  " +
                        " AND PU.ID_typeProfil='FAML' " +
                        "GROUP BY PU.ID_critere";
            }
            /*-------------------------------------------------------*/

            //  if (IdTp == "INVT") { IdTp = "FAML' AND PU.ID_typeProfil='PERS' AND PU.ID_typeProfil='INVT"; }
            try
            {
                this.ConnexionOpen();
                //Selection du produit
                string           sql      = "select id_produit, product_name, generic_name, image_small_url from produit where id_produit = " + p + "; ";
                SqliteCommand    commanda = new SqliteCommand(sql, connexion);
                SqliteDataReader result   = commanda.ExecuteReader();
                result.Read();
                Produits produits = new Produits();
                produits.SetProduits(result.GetString(0), result.GetString(1), result.GetString(2));
                produits.SetUrl(result.GetString(3));
                result.Close();

                //recherche de tous les allergenes qui composent le produit
                string           sql_allergene     = "select id_allergene from compo_allergene where id_produit  = '" + p + "'; ";
                SqliteCommand    command_allergene = new SqliteCommand(sql_allergene, connexion);
                SqliteDataReader result_allergene  = command_allergene.ExecuteReader();
                while (result_allergene.Read())
                {
                    produits.AddAllergene(result_allergene.GetInt32(0).ToString());
                    //produits.AddAllergene("100");
                }
                result_allergene.Close();

                //recherche de tous les nutriments qui composent le produit
                string           sql_nutriment     = "select id_nutriment from compo_nutriment where id_produit  = '" + p + "'; ";
                SqliteCommand    command_nutriment = new SqliteCommand(sql_nutriment, connexion);
                SqliteDataReader result_nutriment  = command_nutriment.ExecuteReader();
                while (result_nutriment.Read())
                {
                    produits.AddNutriment(result_nutriment.GetString(0));
                }
                result_nutriment.Close();

                /* MATCH ALLERGENE */



                //Recherche d'allergène qui matchent avec les critères du profil
                string sql_recherche_allergene =
                    " select PU.ID_typeProfil, PU.ID_profil, CAT.ID_allergene " +
                    " from profil_utilisateur PU, compo_allergene CA,   allergene_par_cat CAT " +
                    " where CAT.ID_allergene = CA.ID_allergene " +
                    " AND CAT.ID_allergene = PU.ID_critere " +
                    " AND CA.id_produit = '" + p + "' AND PU.ID_typeProfil='PERS' " +
                    " or " +
                    " CA.id_produit = '" + p + "' AND PU.ID_typeProfil = 'PERS'" +
                    " AND CAT.ID_cat_allergene = PU.ID_critere" +
                    " AND CA.ID_allergene = CAT.ID_allergene ";

                if (IDTP == "FAML")
                {
                    sql_recherche_allergene += " UNION " +
                                               " select PU.ID_typeProfil, PU.ID_profil, CAT.ID_allergene " +
                                               " from profil_utilisateur PU, compo_allergene CA,   allergene_par_cat CAT " +
                                               " where CAT.ID_allergene = CA.ID_allergene " +
                                               " AND CAT.ID_allergene = PU.ID_critere " +
                                               " AND CA.id_produit = '" + p + "' AND PU.ID_typeProfil='FAML' " +
                                               " or " +
                                               " CA.id_produit = '" + p + "' AND PU.ID_typeProfil = 'FAML'" +
                                               " AND CAT.ID_cat_allergene = PU.ID_critere" +
                                               " AND CA.ID_allergene = CAT.ID_allergene ";
                }

                if (IDTP == "INVT")
                {
                    sql_recherche_allergene += " UNION " +
                                               " select PU.ID_typeProfil, PU.ID_profil, CAT.ID_allergene " +
                                               " from profil_utilisateur PU, compo_allergene CA,   allergene_par_cat CAT " +
                                               " where CAT.ID_allergene = CA.ID_allergene " +
                                               " AND CAT.ID_allergene = PU.ID_critere " +
                                               " AND CA.id_produit = '" + p + "' AND PU.ID_typeProfil='FAML' " +
                                               " or " +
                                               " CA.id_produit = '" + p + "' AND PU.ID_typeProfil = 'FAML'" +
                                               " AND CAT.ID_cat_allergene = PU.ID_critere" +
                                               " AND CA.ID_allergene = CAT.ID_allergene ";
                    sql_recherche_allergene += " UNION " +
                                               " select PU.ID_typeProfil, PU.ID_profil, CAT.ID_allergene " +
                                               " from profil_utilisateur PU, compo_allergene CA,   allergene_par_cat CAT " +
                                               " where CAT.ID_allergene = CA.ID_allergene " +
                                               " AND CAT.ID_allergene = PU.ID_critere " +
                                               " AND CA.id_produit = '" + p + "' AND PU.ID_typeProfil='INVT' " +
                                               " or " +
                                               " CA.id_produit = '" + p + "' AND PU.ID_typeProfil = 'INVT'" +
                                               " AND CAT.ID_cat_allergene = PU.ID_critere" +
                                               " AND CA.ID_allergene = CAT.ID_allergene ";
                }


                SqliteCommand    command_recherche_allergene = new SqliteCommand(sql_recherche_allergene, connexion);
                SqliteDataReader result_recherche_allergene  = command_recherche_allergene.ExecuteReader();
                while (result_recherche_allergene.Read())
                {
                    produits.AddCheckAllergene(result_recherche_allergene.GetInt32(2).ToString(),
                                               result_recherche_allergene.GetString(0).ToString(),
                                               result_recherche_allergene.GetString(1).ToString());
                }
                //recherches d'allergenes par catégorie
                string sqlAllergeneParCat = "";


                //Fin recherche d'allergene
                result_recherche_allergene.Close();
                /* FIN MATCH ALLERGENE */

                /* MATCH NUTRIMENT */
                //Recherche de NUTRIMENTS qui matchent avec les critères du profil
                string sql_recherche_nutriment =
                    " select id_typeProfil, id_profil, id_nutriment, PU.valeur, CN.valeur, seuil_vert, seuil_orange " +
                    "   from profil_utilisateur PU, compo_nutriment CN " +
                    "  where id_produit = '" + p + "' AND  ID_critere = id_nutriment AND PU.ID_typeProfil=" + IdTpN + " ;";
                SqliteCommand    command_recherche_nutriment = new SqliteCommand(sql_recherche_nutriment, connexion);
                SqliteDataReader result_recherche_nutriment  = command_recherche_nutriment.ExecuteReader();
                while (result_recherche_nutriment.Read())
                {
                    String id_typeProfil = result_recherche_nutriment.GetString(0);
                    String id_profil     = result_recherche_nutriment.GetString(1);
                    String id_nutriment  = result_recherche_nutriment.GetString(2);
                    //decimal valeur_profil = 10;
                    decimal valeur_profil = result_recherche_nutriment.GetDecimal(3);
                    //String ValInter = result_recherche_nutriment.GetString(4).Replace('.', ',');
                    // decimal valeur_produit = decimal.Parse(ValInter);
                    decimal valeur_produit = result_recherche_nutriment.GetDecimal(4);

                    //decimal valeur_produit = 10;
                    decimal vert = result_recherche_nutriment.GetDecimal(5);
                    //decimal vert = 10;

                    //  decimal vert = result_recherche_nutriment.GetDecimal(5);
                    decimal orange = result_recherche_nutriment.GetDecimal(6);
                    //decimal orange = 10;

                    /*
                     * decimal valeur_profil = result_recherche_nutriment.GetDecimal(3);
                     * decimal valeur_produit = decimal.Parse(result_recherche_nutriment.GetString(4));
                     * decimal vert = result_recherche_nutriment.GetDecimal(5);
                     * decimal orange = result_recherche_nutriment.GetDecimal(6);
                     * decimal rouge = result_recherche_nutriment.GetDecimal(7);
                     */

                    produits.AddCheckNutriment(id_typeProfil, id_profil, id_nutriment, valeur_profil, valeur_produit, vert, orange);
                }
                //Fin recherche d'allergene
                result_recherche_nutriment.Close();
                /* FIN MATCH NUTRIMENT */



                //on retourne le produit en entier
                return(produits);
            }
            //Retourne le message d'erreur SQL
            catch (SqliteException ex)
            {
                String t = ex.Message;
                //pas de résultat, on va donc créer un produit vide qui renvoie l'information "aucun produit"
                Produits produits = new Produits();
                produits.SetProduits("000", "erreur", "erreur");
                return(produits);
            }
            //Fermeture de la connexion
            finally
            {
                this.ConnexionClose();
            }
        }// fin CreerTableProfil
Example #2
0
        }// fin CreerTableProfil

        /*public String SelectIdProduittest()
         * {
         *  this.ConnexionOpen();
         *  string sql = "select * from historique; ";
         *  SqliteCommand commanda = new SqliteCommand(sql, connexion);
         *  SqliteDataReader result = commanda.ExecuteReader();
         *  result.Read();
         *
         *  return result.GetString(0).ToString();
         * }*/

        //chargement du produit
        public Produits SelectIdProduit(String p)
        {
            try
            {
                this.ConnexionOpen();
                //Selection du produit
                string           sql      = "select id_produit, product_name, generic_name from produit where id_produit = " + p + "; ";
                SqliteCommand    commanda = new SqliteCommand(sql, connexion);
                SqliteDataReader result   = commanda.ExecuteReader();
                result.Read();
                Produits produits = new Produits();
                produits.SetProduits(result.GetString(0).ToString(), result.GetString(1).ToString(), result.GetString(2).ToString());
                result.Close();

                //recherche de tous les allergenes qui composent le produit
                string           sql_allergene     = "select id_allergene from compo_allergene where id_produit  = '" + p + "'; ";
                SqliteCommand    command_allergene = new SqliteCommand(sql_allergene, connexion);
                SqliteDataReader result_allergene  = command_allergene.ExecuteReader();
                while (result_allergene.Read())
                {
                    produits.AddAllergene(result_allergene.GetInt32(0).ToString());
                    //produits.AddAllergene("100");
                }
                result_allergene.Close();

                //recherche de tous les nutriments qui composent le produit
                string           sql_nutriment     = "select id_nutriment from compo_nutriment where id_produit  = '" + p + "'; ";
                SqliteCommand    command_nutriment = new SqliteCommand(sql_nutriment, connexion);
                SqliteDataReader result_nutriment  = command_nutriment.ExecuteReader();
                while (result_nutriment.Read())
                {
                    produits.AddNutriment(result_nutriment.GetString(0));
                }
                result_nutriment.Close();

                /* MATCH ALLERGENE */
                //Recherche d'allergène qui matchent avec les critères du profil
                string sql_recherche_allergene =
                    " select PU.ID_typeProfil, PU.ID_profil, PU.ID_critere " +
                    " from profil_utilisateur PU, compo_allergene CA " +
                    " where PU.ID_critere = CA.ID_allergene " +
                    " AND CA.id_produit = '" + p + "'; ";
                SqliteCommand    command_recherche_allergene = new SqliteCommand(sql_recherche_allergene, connexion);
                SqliteDataReader result_recherche_allergene  = command_recherche_allergene.ExecuteReader();
                while (result_recherche_allergene.Read())
                {
                    produits.AddCheckAllergene(result_recherche_allergene.GetString(2).ToString(),
                                               result_recherche_allergene.GetString(0).ToString(),
                                               result_recherche_allergene.GetString(1).ToString());
                }
                //Fin recherche d'allergene
                result_recherche_allergene.Close();
                /* FIN MATCH ALLERGENE */

                /* MATCH NUTRIMENT */
                //Recherche de NUTRIMENTS qui matchent avec les critères du profil
                string sql_recherche_nutriment =
                    " select id_typeProfil, id_profil, id_nutriment, PU.valeur, CN.valeur, seuil_vert, seuil_orange, seuil_rouge " +
                    "   from profil_utilisateur PU, compo_nutriment CN " +
                    "  where id_produit = '" + p + "' " +
                    " AND ID_critere = id_nutriment; ";
                SqliteCommand    command_recherche_nutriment = new SqliteCommand(sql_recherche_nutriment, connexion);
                SqliteDataReader result_recherche_nutriment  = command_recherche_nutriment.ExecuteReader();
                while (result_recherche_nutriment.Read())
                {
                    String id_typeProfil = result_recherche_nutriment.GetString(0);
                    String id_profil     = result_recherche_nutriment.GetString(1);
                    String id_nutriment  = result_recherche_nutriment.GetString(2);
                    //decimal valeur_profil = 10;
                    decimal valeur_profil  = result_recherche_nutriment.GetDecimal(3);
                    decimal valeur_produit = decimal.Parse(result_recherche_nutriment.GetString(4));
                    //decimal valeur_produit = 10;
                    // decimal vert = result_recherche_nutriment.GetDecimal(5);
                    decimal vert = 10;

                    //  decimal vert = result_recherche_nutriment.GetDecimal(5);
                    decimal orange = result_recherche_nutriment.GetDecimal(6);
                    //decimal orange = 10;
                    decimal rouge = 10;

                    /*
                     * decimal valeur_profil = result_recherche_nutriment.GetDecimal(3);
                     * decimal valeur_produit = decimal.Parse(result_recherche_nutriment.GetString(4));
                     * decimal vert = result_recherche_nutriment.GetDecimal(5);
                     * decimal orange = result_recherche_nutriment.GetDecimal(6);
                     * decimal rouge = result_recherche_nutriment.GetDecimal(7);
                     */

                    produits.AddCheckNutriment(id_typeProfil, id_profil, id_nutriment, valeur_profil, valeur_produit, vert, orange, rouge);
                }
                //Fin recherche d'allergene
                result_recherche_nutriment.Close();
                /* FIN MATCH NUTRIMENT */



                //on retourne le produit en entier
                return(produits);
            }
            //Retourne le message d'erreur SQL
            catch
            {
                //pas de résultat, on va donc créer un produit vide qui renvoie l'information "aucun produit"
                Produits produits = new Produits();
                produits.SetProduits("000", "erreur", "erreur");
                return(produits);
            }
            //Fermeture de la connexion
            finally
            {
                this.ConnexionClose();
            }
        }// fin CreerTableProfil