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 FormAjouterUneTraversee_Load(object sender, EventArgs e)
        {
            SQLSecteur.InitializeListBoxAllSQLSecteur(listBoxSecteur, mySqlConnection);
            SQLBateau.InitializeComboBoxAllSQLBateau(comboBoxBateau, mySqlConnection);

            dateTimePickerDepartDate.MinDate  = DateTime.Now;
            dateTimePickerArriveeDate.MinDate = DateTime.Now;

            dateTimePickerDepartTime.MinDate  = DateTime.Now;
            dateTimePickerArriveeTime.MinDate = DateTime.Now;
        }
        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();
                }
            }
        }
        private void ButtonAjouter_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textBoxBateau.Text))
            {
                MessageBox.Show("Le nom du bateau ne peut être vide", "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      = "";
                MySqlCommand mySqlCommand = new MySqlCommand("INSERT INTO `bateau`(`nom`) VALUES (@nomBateau)", mySqlConnection);
                mySqlCommand.Parameters.AddWithValue("@nomBateau", textBoxBateau.Text);
                if (mySqlCommand.ExecuteNonQuery() == 1)
                {
                    message += "Ajout du bateau '" + textBoxBateau.Text + "' : réussi\n";
                    mySqlConnection.Close();
                    mySqlConnection.Open();
                    foreach (TextBox textBox in dictionary_TextBox_SQLCategorie.Keys)
                    {
                        mySqlCommand = new MySqlCommand("INSERT INTO `contenir`(`lettrecategorie`, `nobateau`, `capacitemax`) VALUES " +
                                                        "(@lettreCategorie, @noBateau, @capaciteMax)", mySqlConnection);

                        dictionary_TextBox_SQLCategorie.TryGetValue(textBox, out SQLCategorie sqlCategorie);
                        MessageBox.Show(SQLBateau.GetLastInsertId().ToString());
                        mySqlCommand.Parameters.AddWithValue("@noBateau", SQLBateau.GetLastInsertId());
                        mySqlCommand.Parameters.AddWithValue("@lettreCategorie", sqlCategorie.GetLettrecategorie());
                        mySqlCommand.Parameters.AddWithValue("@capaciteMax", double.Parse(textBox.Text));
                        if (mySqlCommand.ExecuteNonQuery() == 1)
                        {
                            message += "Ajout de la capacité '" + sqlCategorie.ToString() + "' réussi\n";
                        }
                        else
                        {
                            message += "Ajout de la capacité '" + sqlCategorie.ToString() + "' échec\n";
                        }
                    }
                }
                else
                {
                    message += "Ajout du bateau '" + textBoxBateau.Text + "' : échec\n";
                }

                MessageBox.Show(message);
                mySqlConnection.Close();
            }
            finally
            {
                if (mySqlConnection.State.Equals(ConnectionState.Open))
                {
                    mySqlConnection.Close();
                }
            }
        }
 private void FormModifierUnBateau_Load(object sender, EventArgs e)
 {
     SQLBateau.InitializeComboBoxAllSQLBateau(comboBoxBateau, mySqlConnection);
 }