Пример #1
0
        public static void AjoutCritere(Critere unCritere, Associer uneAssociation, int unIdOffre)
        {
            using (var conn = new NpgsqlConnection(Connexion.Connecter()))
            {
                conn.Open();
                // Insert some data
                using (var cmd = new NpgsqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "INSERT INTO critere (id_critere, libelle_critere) VALUES (DEFAULT, '" + unCritere.GetLibelle() + "')";
                    cmd.ExecuteNonQuery();
                }

                int id = -1;
                using (var cmd2 = new NpgsqlCommand("SELECT id_critere FROM critere ORDER BY id_critere", conn))
                    using (var reader = cmd2.ExecuteReader())
                        while (reader.Read())
                        {
                            id = reader.GetInt32(0);
                        }
                using (var cmd3 = new NpgsqlCommand())
                {
                    cmd3.Connection  = conn;
                    cmd3.CommandText = "INSERT INTO associer (id_critere, id_offre, coefficient) VALUES (" + id + ", " + unIdOffre + "," + uneAssociation.GetCoeff() + ")";
                    cmd3.ExecuteNonQuery();
                }
                conn.Close();
            }
        }
Пример #2
0
        public static List <Critere> GetLesCriteresByOffre(int unIdOffre)
        {
            //permet d'associer une offre à un ou plusieurs critères dans le form offre
            List <Critere> listCritere = new List <Critere>();

            using (var conn = new NpgsqlConnection(Connexion.Connecter()))
            {
                conn.Open();

                using (var cmd = new NpgsqlCommand("SELECT libelle_critere FROM critere c INNER JOIN associer a ON a.id_critere = c.id_critere  WHERE id_offre= " + unIdOffre, conn))
                    using (var reader = cmd.ExecuteReader())
                        while (reader.Read())
                        {
                            Critere unCritere = new Critere(reader.GetString(0));
                            listCritere.Add(unCritere);
                        }
                conn.Close();
            }
            return(listCritere);
        }
Пример #3
0
        private void buttonAjouter_Click(object sender, EventArgs e)
        {
            string libelle   = txtNom.Text;
            string coeffText = txtCoeff.Text;
            int    coeff;

            if (coeffText != "" && libelle != "")
            {
                coeff = int.Parse(coeffText);
                Critere  unCritere      = new Critere(libelle);
                Associer uneAssociation = new Associer(coeff);
                DAOCritere.AjoutCritere(unCritere, uneAssociation, idOffre);
                Valider.Visible = true;
                Valider.Text    = "Envoyé !";
            }
            else
            {
                MessageBox.Show("Vous devez completer tout les champs !");
            }
            this.Close();
        }