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 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363
| 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();
}
readonly MySqlConnection connection = new MySqlConnection("SERVER=localhost; DATABASE=cdh; UID=root; PASSWORD=");
bool Connecté = false;
private void Recherche_Load(object sender, EventArgs e)//Début des appels des ComboBox
{
try //Début Try/Catch pour le ComboBox des catégorie Radiologiqque
{
connection.Open();
CatégorieRadiologique_ComboBox_Home.DropDownStyle = ComboBoxStyle.DropDownList; //ReadOnly sur la comboBox
string selectQuery = "SELECT ID_Rad , Radiologique 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"));
string[,] TableauRad = new string[1, 2]
{
{"ID_Rad","Radiologique"},
};
}
connection.Close();
}
catch (MySqlException cn)
{
MessageBox.Show(cn.Message);
connection.Close();
}
try //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
string selectQuery = "SELECT Code_Etat , Lib_Code_Etat FROM cdh.etat ";
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"));
string[,] TableauEtat = new string[1, 2]
{
{"Code_Etat","Lib_Code_Etat"},
};
}
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 Code_Producteur , Producteur FROM cdh.prod";
MySqlCommand command = new MySqlCommand(selectQuery, connection);
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
Producteur_ComboBox_Home.Items.Add(reader.GetString("Producteur"));
string[,] TableauEtat = new string[1, 2]
{
{"Code_Producteur","Producteur"},
};
}
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"));
string[,] TableauCentre = new string[1, 3]
{
{"Code_Centre","Centre","ID_Prod"},
};
}
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 Code_StationdeDestination , Station_Destination 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"));
string[,] TableauEtat = new string[1, 2]
{
{"Code_StationdeDestination","Station_Destination"},
};
}
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 Code_Conditionnement , Conditionnement 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"));
string[,] TableauEtat = new string[1, 2]
{
{"Code_Conditionnement","Conditionnement"},
};
}
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;
}
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 paramètres de recherches
{
// Réinitialisation des DataTimePicker à leur états initiale (True)
DataTimePicker_Home_1.Enabled = true;
DataTimePicker_Home_2.Enabled = true;
DataTimePicker_Home_3.Enabled = true;
DataTimePicker_Home_4.Enabled = true;
// Réinitialisation des ComboBox et de la TextBox FS à leur états initials (True)
FS_TextBox_Home.Enabled = true;
FS_TextBox_Home.Text = " ";
CatégorieRadiologique_ComboBox_Home.Enabled = true;
CodeEtatFS_ComboBox_Home.Enabled = true;
Producteur_ComboBox_Home.Enabled = true;
Centre_ComboBox_Home.Enabled = true;
StationDestination_ComboBox_Home.Enabled = true;
Conditionnement_ComboBox_Home.Enabled = true;
// Réinitialisation du contenu des ComboBox (Vide = -1)
CatégorieRadiologique_ComboBox_Home.SelectedIndex = -1;
CodeEtatFS_ComboBox_Home.SelectedIndex = -1;
Producteur_ComboBox_Home.SelectedIndex = -1;
Centre_ComboBox_Home.SelectedIndex = -1;
StationDestination_ComboBox_Home.SelectedIndex = -1;
Conditionnement_ComboBox_Home.SelectedIndex = -1;
}
private void Chercher_Button_Click(object sender, EventArgs e) //Déclaration du bouton RECHERCHER
{
try //Le programme essaye de se connecté pour retourner une valeur booléenne à l'état de connection.
{
connection.Open();
Connecté = true;
}
catch (MySqlException co) //Le cas d'un échec de connection
{
connection.Close();
MessageBox.Show(co.ToString());
MessageBox.Show("Connexion échouée");
Connecté = false;
}
if (CatégorieRadiologique_ComboBox_Home.SelectedIndex != -1 | CodeEtatFS_ComboBox_Home.SelectedIndex != -1 | Producteur_ComboBox_Home.SelectedIndex != -1 | Centre_ComboBox_Home.SelectedIndex != -1 | StationDestination_ComboBox_Home.SelectedIndex != -1 | Conditionnement_ComboBox_Home.SelectedIndex != -1)
{
string[] TableauCombo = new string[6];
{
TableauCombo[0] = "ID_Rad=@ID_Rad";
TableauCombo[1] = "Code_Etat=@Code_Etat";
TableauCombo[2] = "Code_Producteur=@Code_Producteur";
TableauCombo[3] = "Code_Centre=@Code_Centre";
TableauCombo[4] = "Code_StationdeDestination=@Code_StationdeDestination";
TableauCombo[5] = "Code_Conditionnement=@Code_Conditionnement";
};
string sqlReq = " SELECT FS FROM cdh.fiche WHERE ";
string requery = string.Join(" AND ", TableauCombo);
sqlReq = sqlReq + requery;
LW_FS_Home.Items.Clear();
MySqlCommand cmd = new MySqlCommand(sqlReq, connection); // Requète SQL SELECT
MessageBox.Show(sqlReq);
cmd.Parameters.AddWithValue("@ID_Rad", CatégorieRadiologique_ComboBox_Home.SelectedIndex.ToString()); //Récupération du ID_Rad souhaité par l'utilisateur
cmd.Parameters.AddWithValue("@Code_Etat", CodeEtatFS_ComboBox_Home.ToString()); //Récupération du Code_Etat souhaité par l'utilisateur
cmd.Parameters.AddWithValue("@Code_Producteur", Producteur_ComboBox_Home.ToString()); //Récupération du Code_Producteur souhaité par l'utilisateur
cmd.Parameters.AddWithValue("@Code_Centre", Centre_ComboBox_Home.ToString()); //Récupération du Code_Centre souhaité par l'utilisateur
cmd.Parameters.AddWithValue("@Code_StationdeDestination", StationDestination_ComboBox_Home.ToString()); //Récupération du Code_StationdeDestination souhaité par l'utilisateur
cmd.Parameters.AddWithValue("@Code_Conditionnement", Conditionnement_ComboBox_Home.Text); //Récupération du Code_Conditionnement souhaité par l'utilisateur
if (Connecté)
{
using (MySqlDataReader Lire = cmd.ExecuteReader())
{
while (Lire.Read()) // Boucle While qui regarde toutes les infos que l'on souhaite voir avec la méthode "lire"
{
string FS = Lire["@FS"].ToString(); // Declaration des colonnes et leurs équivalents (remplacants)
string ID_Rad = Lire["@ID_Rad"].ToString();
string Code_Etat = Lire["@Code_Etat"].ToString();
string Code_Producteur = Lire["@Code_Producteur"].ToString();
string Code_Centre = Lire["@Code_Centre"].ToString();
string Code_StationdeDestination = Lire["@Code_StationdeDestination"].ToString();
string Code_Conditionnement = Lire["@Code_Conditionnement"].ToString();
LW_FS_Home.Items.Add(new ListViewItem(new[] { FS, ID_Rad, Code_Etat, Code_Producteur, Code_Centre, Code_StationdeDestination, Code_Conditionnement }));// Ajout des nouvelles valeurs dans la list view
}
}
connection.Close();
}
else
{
MessageBox.Show("Erreur de connexion");
connection.Close();
}
}
else if (FS_TextBox_Home.Text != "") // Recherche par le numéro FS
{
DataTimePicker_Home_1.Enabled = false; // Changement détat des comboboxs et DataPicker
DataTimePicker_Home_2.Enabled = false;
DataTimePicker_Home_3.Enabled = false;
DataTimePicker_Home_4.Enabled = false;
CodeEtatFS_ComboBox_Home.Enabled = false;
StationDestination_ComboBox_Home.Enabled = false;
CatégorieRadiologique_ComboBox_Home.Enabled = false;
Conditionnement_ComboBox_Home.Enabled = false;
Centre_ComboBox_Home.Enabled = false;
Producteur_ComboBox_Home.Enabled = false;
LW_FS_Home.Items.Clear();
MySqlCommand cmd = new MySqlCommand("SELECT FS , ctg_rad.Radiologique , etat.Lib_Code_Etat , site_centre.Centre , prod.Producteur ,station_destination.Station_Destination , statut_condition.Conditionnement FROM cdh.fiche JOIN ctg_rad , site_centre , etat , prod, station_destination , statut_condition", connection); // Requète SQL SELECT pour selectionner l'élément correspondant au numéro de la FS entré .... NATURAL JOIN ctg_rad
cmd.Parameters.AddWithValue("@FS", FS_TextBox_Home.Text);//Récupération du numéro FS souhaité par l'utilisateur
if (Connecté)
{
using (MySqlDataReader Lire = cmd.ExecuteReader())
{
while (Lire.Read()) // Boucle While qui regarde toutes les infos que l'on souhaite voir avec la méthode "lire"
{
string FS = Lire["FS"].ToString(); // Declaration des colonnes et leurs équivalents (remplacants)
string Radiologique = Lire["Radiologique"].ToString();
string Lib_Code_Etat = Lire["Lib_Code_Etat"].ToString();
string Producteur = Lire["Producteur"].ToString();
string Centre = Lire["Centre"].ToString();
string Station_Destination = Lire["Station_Destination"].ToString();
string Conditionnement = Lire["Conditionnement"].ToString();
LW_FS_Home.Items.Add(new ListViewItem(new[] { FS, Radiologique, Lib_Code_Etat, Producteur, Centre, Station_Destination, Conditionnement }));// Ajout des nouvelles valeurs dans la list view
}
}
connection.Close();
}
else
{
MessageBox.Show("Erreur de connexion");
connection.Close();
}
// Fermeture de la connexion pour pouvoir refaire un recherche
}
else
{
MessageBox.Show("vous n'avez pas sélectionné un seul critère de recherche, veuillez en entrer un pour que ce soit pris en compte");
connection.Close();
}
}
}
} |
Partager