Bonjour, je sollicite votre aide d'urgence car j'ai un problème dans mon code, j'aimerais afficher dans un dataGrid tous les produits associés à un fournisseur, mais le rendu n'est pas celui que je veux, car ça me sort TOUS les produits de TOUS les fournisseurs. Dans ce cas, il faut que je déclare "nomFournisseur" qui correspond à getNomFournisseur, mais lorsque j'essaie d'initialiser ma variable, il y a un conflit avec la ligne qui est dans mon foreachVoici ma fonction en intégralité de ma passerelle :
Code : Sélectionner tout - Visualiser dans une fenêtre à part string nomFournisseur = resLigne["nomFournisseur"].ToString();Et voici le code de mon formulaire affichant le datagrid :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 //fonction permettant de récupérer tous les produits d'un fournisseurs public static List<Produit> getLesProduitsByNom() { List<Produit> maListe = new List<Produit>(); Produit unObjFournisseur = null; if (ClassReq.RetConnOk() == true) { ClassReq afficherClasse = new ClassReq("SELECT * FROM PRODUIT WHERE nomFournisseur = '"+ nomFournisseur +"'"); // creer une nouvelle requete DataTable resultat = new DataTable(); resultat = afficherClasse.ExecuteSelect(); // recupere le resultat de la requete foreach (DataRow resLigne in resultat.Rows) { string referenceProd = resLigne["referenceProd"].ToString(); string libelleProduit = resLigne["libelleProduit"].ToString(); double prixUHT = Double.Parse(resLigne["prixUHT"].ToString()); double tauxTVA = Double.Parse(resLigne["tauxTVA"].ToString()); int seuilReapro = Int32.Parse(resLigne["seuilReapro"].ToString()); int delaiReapro = Int32.Parse(resLigne["delaiReapro"].ToString()); int stockTemp = Int32.Parse(resLigne["stockTemp"].ToString()); string origineProduit = resLigne["origineProduit"].ToString(); string couleurProduit = resLigne["couleurProduit"].ToString(); string tailleProduit = resLigne["tailleProduit"].ToString(); int stockTheorique = Int32.Parse(resLigne["stockTheorique"].ToString()); int numFournisseur = Int32.Parse(resLigne["numFournisseur"].ToString()); int numCategorie = Int32.Parse(resLigne["numCategorie"].ToString()); string numReduction = resLigne["numReduction"].ToString(); string nomFournisseur = resLigne["nomFournisseur"].ToString(); unObjFournisseur = new Produit(referenceProd, libelleProduit, prixUHT, stockTheorique, tauxTVA, stockTemp, couleurProduit, tailleProduit, origineProduit, delaiReapro, seuilReapro, nomFournisseur); maListe.Add(unObjFournisseur); } } return maListe; }Voilà ce que le datagrid me renvoie ( tous les produits de tous les fournisseurs ), à la place de tous les produits du fournisseur selectionné dans le comboBox
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 using ClassLibraryL3B; using les3belges; using System; using System.Collections.Generic; using System.Windows.Forms; using System.Collections; using gestionPriseCommande; using System.Linq; namespace gestionPriseCommande { public partial class FormProduitFournisseur : Form { public FormProduitFournisseur() { InitializeComponent(); } private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void button3_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void FormProduitFournisseur_Load(object sender, EventArgs e) { List<Fournisseur> maListe = Passerelle.getLesFournisseursByNom(); foreach (Fournisseur unFour in maListe) { comboBox2.Items.Add(unFour.getNomFournisseur()); } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { dataGridView1.Visible = true; string unNomFournisseur = comboBox2.Text; List<Produit> lesProduits = Passerelle.getLesProduitsByNom(); foreach (Produit unProd in lesProduits) { string[] ligne = { unProd.getReference(), unProd.getLibelleProduit(), unProd.getPrixUHTProduit().ToString(), unProd.getStockTheorique().ToString(), unProd.getTauxTVA().ToString(), unProd.getStockTemp().ToString(), unProd.getCouleurProduit(),unProd.getTailleProduit(), unProd.getOrigineProduit(), unProd.getDelaiReapro().ToString(),unProd.getSeuilReapro().ToString()}; dataGridView1.Rows.Add(ligne); } } } }
Partager