Ejemplo n.º 1
0
        private void Ajouter()
        {
            Form_Ajouter_Division aDiv = new Form_Ajouter_Division(oracon, connection);

            aDiv.Text = "Ajouter une division";
            if (aDiv.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string sqlAjout = "insert into Division (NomDivision,DateCreation)" +
                                  " VALUES(:NomDivision,:DateCreation)";
                try
                {
                    OracleParameter OraParaNomDiv        = new OracleParameter(":NomDivision", OracleDbType.Varchar2, 40);
                    OracleParameter OraParamDateCreation = new OracleParameter(":DateCreation", OracleDbType.Date);

                    OraParaNomDiv.Value        = aDiv.nomDivision;
                    OraParamDateCreation.Value = DateTime.Parse(aDiv.dateCreation);

                    OracleCommand oraAjout = new OracleCommand(sqlAjout, oracon);

                    oraAjout.Parameters.Add(OraParaNomDiv);
                    oraAjout.Parameters.Add(OraParamDateCreation);

                    oraAjout.ExecuteNonQuery();

                    LoadDGV();
                }
                catch (OracleException ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
            }
        }
Ejemplo n.º 2
0
        private void Modifier()
        {
            Form_Ajouter_Division Modifier = new Form_Ajouter_Division(oracon, connection);

            Modifier.Text = "Modification de la division";

            Modifier.nomDivision  = DGV_Divisions.SelectedRows[0].Cells[0].Value.ToString();
            Modifier.dateCreation = DGV_Divisions.SelectedRows[0].Cells[1].Value.ToString();
            if (Modifier.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    string sqlModif = "Update Division set NomDivision =:NomDivision, DateCreation =:DateCreation " +
                                      "where NomDivision =:NomDivision2";

                    OracleCommand oraUpdate = new OracleCommand(sqlModif, oracon);

                    OracleParameter paramNomDivision  = new OracleParameter(":NomDivision", OracleDbType.Varchar2, 40);
                    OracleParameter paramDateCreation = new OracleParameter(":DateCreation", OracleDbType.Date);
                    OracleParameter paramNomDivision2 = new OracleParameter(":NomDivision2", OracleDbType.Varchar2, 40);

                    paramNomDivision.Value  = Modifier.nomDivision;
                    paramDateCreation.Value = DateTime.Parse(Modifier.dateCreation);
                    paramNomDivision2.Value = DGV_Divisions.SelectedRows[0].Cells[0].Value.ToString();


                    oraUpdate.Parameters.Add(paramNomDivision);
                    oraUpdate.Parameters.Add(paramDateCreation);
                    oraUpdate.Parameters.Add(paramNomDivision2);

                    oraUpdate.ExecuteNonQuery();

                    LoadDGV();
                }

                catch (OracleException ex)
                {
                    if (ex.Number == 2292)
                    {
                        MessageBox.Show("Le nom de la division ne peut etre modifié si elle contient des équipes.", "Erreur 2292", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }