Example #1
0
 private void insert(Lapins lapin)
 {
     using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection())
     {
         cnx.Open();
         if (lapin.GetIdGerant() == 0)
         {
             using (MySqlCommand cmd = new MySqlCommand("insert into Lapin(surnom,age,vitesse,endurance,chance) values(@surnom,@age,@vitesse,@endurance,@chance)", cnx))
             {
                 cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar));
                 cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@vitesse", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@endurance", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@chance", MySqlDbType.Int32));
                 cmd.Parameters["@surnom"].Value    = lapin.GetSurnom();
                 cmd.Parameters["@age"].Value       = lapin.GetAge();
                 cmd.Parameters["@vitesse"].Value   = lapin.Vitesse;
                 cmd.Parameters["@endurance"].Value = lapin.Endurance;
                 cmd.Parameters["@chance"].Value    = lapin.Chance;
                 cmd.ExecuteNonQuery();
             }
         }
         else
         {
             using (MySqlCommand cmd = new MySqlCommand("insert into Lapin(surnom,age,vitesse,endurance,chance,idGerant) values(@surnom,@age,@vitesse,@endurance,@chance,@idGerant)", cnx))
             {
                 cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar));
                 cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@vitesse", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@endurance", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@chance", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@idGerant", MySqlDbType.Int32));
                 cmd.Parameters["@surnom"].Value    = lapin.GetSurnom();
                 cmd.Parameters["@age"].Value       = lapin.GetAge();
                 cmd.Parameters["@vitesse"].Value   = lapin.Vitesse;
                 cmd.Parameters["@endurance"].Value = lapin.Endurance;
                 cmd.Parameters["@chance"].Value    = lapin.Chance;
                 cmd.Parameters["@idGerant"].Value  = lapin.GetIdGerant();
                 cmd.ExecuteNonQuery();
             }
         }
     }
     lapin.SetState(state.unChanged);
 }
Example #2
0
 private void update(Lapins lapin)
 {
     using (MySqlConnection cnx = DaoConnectionSingleton.GetMySqlConnection())
     {
         cnx.Open();
         if (lapin.GetIdGerant() == 0)
         {
             using (MySqlCommand cmd = new MySqlCommand("update Lapin set surnom=@surnom,age=@age, idGerant=NULL where id=@id", cnx))
             {
                 cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar));
                 cmd.Parameters["@id"].Value     = lapin.GetId();
                 cmd.Parameters["@age"].Value    = lapin.GetAge();
                 cmd.Parameters["@surnom"].Value = lapin.GetSurnom();
                 cmd.ExecuteNonQuery();
             }
         }
         else
         {
             using (MySqlCommand cmd = new MySqlCommand("update Lapin set surnom=@surnom,age=@age,idGerant=@idGerant where id=@id", cnx))
             {
                 cmd.Parameters.Add(new MySqlParameter("@id", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@age", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@idGerant", MySqlDbType.Int32));
                 cmd.Parameters.Add(new MySqlParameter("@surnom", MySqlDbType.VarChar));
                 cmd.Parameters["@id"].Value       = lapin.GetId();
                 cmd.Parameters["@age"].Value      = lapin.GetAge();
                 cmd.Parameters["@surnom"].Value   = lapin.GetSurnom();
                 cmd.Parameters["@idGerant"].Value = lapin.GetIdGerant();
                 cmd.ExecuteNonQuery();
             }
         }
     }
     lapin.SetState(state.unChanged);
 }