Hé les gars j’ai besoin d’aide ! J’ai sur mon IHM plusieurs combobox dont les données proviennent de chacune des différentes tables via PhpMyAdmin. J’aimerais que lorsque j’appuie sur le bouton "rechercher", le programme prenne en compte les valeurs des combobox saisies préalablement par l’utilisateur pour aller les récupérer dans la DATABASE les données souhaitées et ainsi les afficher dans ma ListView. J’ai décidé de créer un tableau avec 2D. La première porte le nom du combobox et la seconde, le contenu. Et je ne sais pas si c’est la meilleure solution.

Le but et que quand l'utilisateur sélectionne tout ses critères de sélection à l'aide des 7 combobox, le programme retourne uniquement les infos adéquates à la recherche . Voir Image pour spé.

Mais je suis complètement perdu sur la façons de faire , je suis bloqué.
J'ai essayer quelque chose sur le dernier if également..

Voici l'actuel code en lien avec le form joint en image.

Nom : gH4Da.png
Affichages : 449
Taille : 43,5 Ko




CODE :

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
 
 
namespace PROJET_FINDER
{
    public partial class Recherche : DevExpress.XtraEditors.XtraForm
    {
        public Recherche()
        {
            InitializeComponent();
        }
 
        MySqlConnection connection = new MySqlConnection("Datasource = localhost;port=3306;username=root;password=");
 
        private void Recherche_Load(object sender, EventArgs e)//Début des appels des ComboBox
        {
 
            try
            {
                string selectQuery = "SELECT * FROM cdh.etat";                                                     //Début Try/Catch pour le ComboBox le Code d'Etat
                connection.Open();                                                                                      //Connexion à la base de donnée ouverte
                CodeEtatFS_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList;                                    //ReadOnly sur la comboBox
                MySqlCommand command = new MySqlCommand(selectQuery, connection);                                       //Création de l'objet de la commande SQL
                MySqlDataReader reader = command.ExecuteReader();                                                       //Déclaration de la nouvelle instance
                while (reader.Read())
                {
                    CodeEtatFS_ComboBox_Home.Items.Add(reader.GetString("Lib_Code_Etat"));
                }
                connection.Close();
            }
            catch (MySqlException cn)
            {
                MessageBox.Show(cn.Message);
                connection.Close();
            }
            try                                                                                                         //Début Try/Catch pour le ComboBox du numéro FS 
            {
                connection.Open();
                NuméroFS_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList;                                      //ReadOnly sur la comboBox
                string selectQuery = "SELECT * FROM cdh.fiche";
                MySqlCommand command = new MySqlCommand(selectQuery, connection);
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    NuméroFS_ComboBox_Home.Items.Add(reader.GetString("FS"));
                }
                connection.Close();
            }
            catch (MySqlException cn)
            {
                MessageBox.Show(cn.Message);
                connection.Close();
            }
            try                                                                                                         //Début Try/Catch pour le ComboBox des catégorie Radio
            {
                connection.Open();
                CatégorieRadiologique_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList;                        //ReadOnly sur la comboBox
                string selectQuery = "SELECT * FROM cdh.ctg_rad";
                MySqlCommand command = new MySqlCommand(selectQuery, connection);
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    CatégorieRadiologique_ComboBox_Home.Items.Add(reader.GetString("Radiologique"));
                }
                connection.Close();
            }
            catch (MySqlException cn)
            {
                MessageBox.Show(cn.Message);
                connection.Close();
            }
            try                                                                                                         //Début Try/Catch pour le ComboBox des Centres
            {
                connection.Open();
                Centre_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList;                                        //ReadOnly sur la comboBox
                string selectQuery = "SELECT * FROM cdh.site_centre";
                MySqlCommand command = new MySqlCommand(selectQuery, connection);
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Centre_ComboBox_Home.Items.Add(reader.GetString("Centre"));
                }
                connection.Close();
            }
            catch (MySqlException cn)
            {
                MessageBox.Show(cn.Message);
                connection.Close();
            }
            try                                                                                                         //Début Try/Catch pour le ComboBox des producteurs du déchet
            {
                connection.Open();
                Producteur_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList;                                    //ReadOnly sur la comboBox
                string selectQuery = "SELECT * FROM cdh.prod";
                MySqlCommand command = new MySqlCommand(selectQuery, connection);
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Producteur_ComboBox_Home.Items.Add(reader.GetString("Producteur"));
                }
                connection.Close();
            }
            catch (MySqlException cn)
            {
                MessageBox.Show(cn.Message);
                connection.Close();
            }
            try                                                                                                         //Début Try/Catch pour le ComboBox du conditionnement du déchet
            {
                connection.Open();
                Conditionnement_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList;                               //ReadOnly sur la comboBox
                string selectQuery = "SELECT * FROM cdh.statut_condition";
                MySqlCommand command = new MySqlCommand(selectQuery, connection);
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    Conditionnement_ComboBox_Home.Items.Add(reader.GetString("Conditionnement"));
                }
                connection.Close();
            }
            catch (MySqlException cn)
            {
                MessageBox.Show(cn.Message);
                connection.Close();
            }
            try                                                                                                         //Début Try/Catch pour le ComboBox de la station de destination du déchet
            {
                connection.Open();
                StationDestination_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList;                            //ReadOnly sur la comboBox
                string selectQuery = "SELECT * FROM cdh.station_destination";
                MySqlCommand command = new MySqlCommand(selectQuery, connection);
                MySqlDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    StationDestination_ComboBox_Home.Items.Add(reader.GetString("Station_Destination"));
                }
                connection.Close();
            }
            catch (MySqlException cn)
            {
                MessageBox.Show(cn.Message);
                connection.Close();
            }
        }//Fin des appels des ComboBox
 
        private void DataTimePicker_Home_1_ValueChanged(object sender, EventArgs e)                                     //Lorsque la valeur du DataTimePicker_Home_1 change alors le 3 et le 4 se désactive
        {
            DataTimePicker_Home_3.Enabled = false;
            DataTimePicker_Home_4.Enabled = false;
            if (DataTimePicker_Home_3.Enabled == false)
            {
 
            }
        }
 
        private void DataTimePicker_Home_2_ValueChanged(object sender, EventArgs e)                                     //Lorsque la valeur du DataTimePicker_Home_2 change alors le 3 et le 4 se désactive
        {
            DataTimePicker_Home_3.Enabled = false;
            DataTimePicker_Home_4.Enabled = false;
        }
 
        private void DataTimePicker_Home_3_ValueChanged(object sender, EventArgs e)                                     //Lorsque la valeur du DataTimePicker_Home_3 change alors le 1 et le 2 se désactive
        {
            DataTimePicker_Home_1.Enabled = false;
            DataTimePicker_Home_2.Enabled = false;
        }
 
        private void DataTimePicker_Home_4_ValueChanged(object sender, EventArgs e)                                     //Lorsque la valeur du DataTimePicker_Home_4 change alors le 1 et le 2 se désactive
        {
            DataTimePicker_Home_1.Enabled = false;
            DataTimePicker_Home_2.Enabled = false;
        }
 
        private void Data_Reset_Button_Click(object sender, EventArgs e)                                                //Bouton de réinitiallisation des DataTimePicker
        {
            DataTimePicker_Home_1.Enabled = true;
            DataTimePicker_Home_2.Enabled = true;
            DataTimePicker_Home_3.Enabled = true;
            DataTimePicker_Home_4.Enabled = true;
        }
 
        private void Chercher_Button_Click(object sender, EventArgs e)                                                  //Déclaration du bouton RECHERCHER
        {
            Object selectedItem_Etat = CodeEtatFS_ComboBox_Home.SelectedItem;
            Object selectedItem_Centre = Centre_ComboBox_Home.SelectedItem;
            Object selectedItem_CatRadg = CatégorieRadiologique_ComboBox_Home.SelectedItem;
            Object selectedItem_FS = NuméroFS_ComboBox_Home.SelectedItem;
            Object selectedItem_StationdeDestination = StationDestination_ComboBox_Home.SelectedItem;
            Object selectedItem_Producteur = Producteur_ComboBox_Home.SelectedItem;
            Object selectedItem_Conditionnement = Conditionnement_ComboBox_Home.SelectedItem;
 
            object[,] Tab_ComboBox =
           {
                {selectedItem_Etat, CodeEtatFS_ComboBox_Home},
 
                {selectedItem_Centre, Centre_ComboBox_Home},
 
                {selectedItem_FS, NuméroFS_ComboBox_Home},
 
                {selectedItem_CatRadg, CatégorieRadiologique_ComboBox_Home},
 
                {selectedItem_StationdeDestination, StationDestination_ComboBox_Home},
 
                {selectedItem_Producteur, Producteur_ComboBox_Home},
 
                {selectedItem_Conditionnement, Conditionnement_ComboBox_Home}
            };
 
 
 
            int i = 0;
 
            bool statement = false;
 
 
            while (i == 7)
            {
                connection.Open();
 
                    if (selectedItem_Etat != null)
                    {
                        LW_FS_Home.Items.Clear();
                        MySqlCommand cmd = new MySqlCommand("SELECT * FROM etat WHERE Lib_Code_Etat=@Lib_Code_Etat", connection);
                        cmd.Parameters.AddWithValue("@Lib_Code_Etat", CodeEtatFS_ComboBox_Home.Text);//Récupération de l'age souhaité par l'utilisateur
                        statement = true;
                        i++;
                    }
                    else if (selectedItem_Centre != null)
                    {
                        MySqlCommand cmd = new MySqlCommand("SELECT * FROM cdh.site_centre WHERE Centre=@Centre", connection);
                        cmd.Parameters.AddWithValue("@Lib_Code_Etat", Centre_ComboBox_Home.Text);
                        statement = true;
                        i++;
                    }
                    else if (selectedItem_FS != null)
                    {
                        MySqlCommand cmd = new MySqlCommand("SELECT * FROM cdh.fiche WHERE FS=@NuméroFS_ComboBox_Home", connection);
                        cmd.Parameters.AddWithValue("@Lib_Code_Etat", NuméroFS_ComboBox_Home.Text);
                        statement = true;
                        i++;
                    }
                    else if (selectedItem_CatRadg != null)
                    {
                        MySqlCommand cmd = new MySqlCommand("SELECT * FROM cdh.ctg_rad WHERE Radiologique=@Radiologique", connection);
                        cmd.Parameters.AddWithValue("@Lib_Code_Etat", CatégorieRadiologique_ComboBox_Home.Text);
                        statement = true;
                        i++;
                    }
                    else if (selectedItem_StationdeDestination != null)
                    {
                        MySqlCommand cmd = new MySqlCommand("SELECT * FROM cdh.station_destination WHERE Station_Destination=@Station_Destination", connection);
                        cmd.Parameters.AddWithValue("@Lib_Code_Etat", StationDestination_ComboBox_Home.Text);
                        statement = true;
                        i++;
                    }
                    else if (selectedItem_Producteur != null)
                    {
                        MySqlCommand cmd = new MySqlCommand("SELECT * FROM cdh.prod WHERE Producteur=@Producteur", connection);
                        cmd.Parameters.AddWithValue("@Lib_Code_Etat", Producteur_ComboBox_Home.Text);
                        statement = true;
                        i++;
                    }
                    else if (selectedItem_Conditionnement != null)
                    {
                        MySqlCommand cmd = new MySqlCommand("SELECT * FROM cdh.statut_condition WHERE Conditionnement=@Conditionnement", connection);
                        cmd.Parameters.AddWithValue("@Lib_Code_Etat", Conditionnement_ComboBox_Home.Text);
                        statement = true;
                        MySqlCommand cm = new MySqlCommand();
                        using (MySqlDataReader Lire = cm.ExecuteReader())
 
                        while (Lire.Read())
                        { 
                            string Conditionnement = Lire["@Lib_Code_Etat"].ToString();
                            LW_FS_Home.Items.Add(new ListViewItem(new[] { Conditionnement }));
                            i++;
                        }
 
                    }
                    else
                    {
                        MessageBox.Show("AIE");
 
 
                    }
            }
        }
    }
}



Pouvez vous m'aider s'il vous plaît...?