void ajouter() { byte infoEmail = 0; byte infoSMS = 0; if (checkBoxInfoEmail.Checked) { infoEmail = 1; } if (checkBoxInfoSMS.Checked) { infoSMS = 1; } try { if (txtBoxNom.Text == "" || txtBoxPrenom.Text == "" || comboBoxCivilite.SelectedItem == null || txtBoxTel.Text == "" || txtBoxAdress.Text == "" || txtBoxEmail.Text == "" || txtBoxFacebook.Text == "") { MessageBox.Show("Vérifier les champs"); } else { Clients _c = new Clients(txtBoxNom.Text, txtBoxPrenom.Text, comboBoxCivilite.SelectedItem.ToString(), dateTimeDateNaissance.Value, txtBoxTel.Text, txtBoxAdress.Text, txtBoxEmail.Text, txtBoxFacebook.Text, infoSMS, infoEmail); bool test = _imp.ajouterClients(_c); MySqlDataReader _reader = _fc.LireDeBD("SELECT max(codeClient) FROM client;"); int get_Code = 0; while (_reader.Read()) { get_Code = _reader.GetInt16(0); } _reader.Close(); bool _testOccurenceGamme = false; for (int i = 0; i < _listeGamme.Count - 1; i++) { if (_listeGamme[i].Text == _listeAutre[0].Text) { _testOccurenceGamme = true; } } for (int i = 0; i < _listeGamme.Count; i++) { if (_listeGamme[i].Checked) { if (_listeGamme[i].Text == "Autre") { if (_listeAutre[0].TextLength != 0 && !_testOccurenceGamme) { _fc.EcrireDansBD("INSERT INTO `autre_gamme` (`ID_autregamme`, `libelle_autregamme`, `CodeClient`) VALUES(NULL, '" + _listeAutre[0].Text + "', '" + get_Code + "');"); } } else { _fc.EcrireDansBD("INSERT INTO `avoir_gammes` (`CodeClient`, `libelle_gamme`) VALUES ('" + get_Code + "', '" + _listeGamme[i].Text + "');"); } } } // pour interet bool _testOccurenceInteret = false; for (int i = 0; i < _listeInteret.Count - 1; i++) { if (_listeInteret[i].Text == _listeAutre[1].Text) { _testOccurenceInteret = true; } } for (int i = 0; i < _listeInteret.Count; i++) { if (_listeInteret[i].Checked) { if (_listeInteret[i].Text == "Autre") { if (_listeAutre[1].TextLength != 0 && !_testOccurenceInteret) { _fc.EcrireDansBD("INSERT INTO `autre_interet` (`ID_autreinteret`, `libelle_autreinteret`, `CodeClient`) VALUES(NULL, '" + _listeAutre[1].Text.ToString() + "', '" + get_Code + "');"); } } else { _fc.EcrireDansBD("INSERT INTO `avoir_interets` (`CodeClient`, `libelle_interet`) VALUES ('" + get_Code + "', '" + _listeInteret[i].Text + "');"); } } } if (test) { MessageBox.Show("Ajouter avec succées"); txtBoxNom.Text = ""; txtBoxPrenom.Text = ""; comboBoxCivilite.SelectedItem = null; txtBoxTel.Text = ""; txtBoxAdress.Text = ""; txtBoxEmail.Text = ""; txtBoxFacebook.Text = ""; // Affichage Clients dans la DataGrid dataGridViewAfficheClients.DataSource = _imp.recupererTousClients(); } } ActiverModeconsultation(); } catch (MySqlException e1) { MessageBox.Show(e1.Message); } }