private void ComboBoxBateau_SelectedIndexChanged(object sender, EventArgs e) { SQLBateau sqlBateau = (SQLBateau)((ComboBox)sender).SelectedItem; foreach (TextBox textBox in dictionary_TextBox_SQLCategorie.Keys) { dictionary_TextBox_SQLCategorie.TryGetValue(textBox, out SQLCategorie sqlCategorie); try { mySqlConnection.Open(); MySqlCommand mySqlCommand = new MySqlCommand("SELECT capacitemax FROM contenir " + "WHERE lettrecategorie = @lettreCategorie AND nobateau = @noBateau", mySqlConnection); mySqlCommand.Parameters.AddWithValue("@noBateau", sqlBateau.GetNobateau()); mySqlCommand.Parameters.AddWithValue("@lettreCategorie", sqlCategorie.GetLettrecategorie()); using (MySqlDataReader reader = mySqlCommand.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { textBox.Text = reader.GetInt16(0).ToString(); } } } mySqlConnection.Close(); } finally { if (mySqlConnection.State.Equals(ConnectionState.Open)) { mySqlConnection.Close(); } } } }
private void ButtonBateau_Click(object sender, EventArgs e) { if (comboBoxBateau.SelectedItem == null) { MessageBox.Show("Vous devez sélectionnez un bateau", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (TextBox textBox in dictionary_TextBox_SQLCategorie.Keys) { if (string.IsNullOrWhiteSpace(textBox.Text)) { MessageBox.Show("Les tarifs ne peuvent être vide", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } try { mySqlConnection.Open(); string message = ""; SQLBateau sqlBateau = (SQLBateau)comboBoxBateau.SelectedItem; foreach (TextBox textBox in dictionary_TextBox_SQLCategorie.Keys) { MySqlCommand mySqlCommand = new MySqlCommand("UPDATE `contenir` SET `capacitemax`= @capaciteMax " + "WHERE `lettrecategorie` = @lettreCategorie AND `nobateau` = @noBateau", mySqlConnection); dictionary_TextBox_SQLCategorie.TryGetValue(textBox, out SQLCategorie sqlCategorie); mySqlCommand.Parameters.AddWithValue("@noBateau", sqlBateau.GetNobateau()); mySqlCommand.Parameters.AddWithValue("@lettreCategorie", sqlCategorie.GetLettrecategorie()); mySqlCommand.Parameters.AddWithValue("@capaciteMax", double.Parse(textBox.Text)); if (mySqlCommand.ExecuteNonQuery() == 1) { message += "Modifcation de la capacité '" + sqlCategorie.ToString() + "' réussi\n"; } else { message += "Modification de la capacité '" + sqlCategorie.ToString() + "' échec\n"; } } MessageBox.Show(message); mySqlConnection.Close(); } finally { if (mySqlConnection.State.Equals(ConnectionState.Open)) { mySqlConnection.Close(); } } }