Exemplo n.º 1
0
        /// <inheritdoc />
        public int Add(VoitureDTO voitureDTO)
        {
            int n = 0;
            try
            {
                connexion.Open();
                command.CommandText = ADD_REQUEST;

                command.Parameters.Add(new MySqlParameter("@marque", voitureDTO.marque));
                command.Parameters.Add(new MySqlParameter("@modele", voitureDTO.modele));
                command.Parameters.Add(new MySqlParameter("@annee", voitureDTO.annee));
                n = command.ExecuteNonQuery();
            }
            catch (MySqlException mySqlException)
            {
                throw mySqlException;
            }
            finally
            {
                connexion.Close();
            }
            return n;
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public List<LocationDTO> GetAll()
        {
            List<LocationDTO> locations = new List<LocationDTO>();

            LocationDTO locationDTO = new LocationDTO();
            try
            {
                connexion.Open();
                command.CommandText = GET_ALL_REQUEST;

                MySqlDataReader dr = command.ExecuteReader();
                while (dr.Read())
                {
                    locationDTO.IdLocation = dr.GetInt32(0);

                    MembreDTO membre = new MembreDTO();
                    locationDTO.IdMembre = dr.GetInt32(1);

                    VoitureDTO voiture = new VoitureDTO();
                    locationDTO.IdVoiture = dr.GetInt32(2);
                    locationDTO.DateLocation = dr.GetDateTime(3).ToString();
                    locationDTO.DateRetour = dr.GetDateTime(4).ToString();
                    locations.Add(locationDTO);
                }
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException);
            }
            finally
            {
                connexion.Close();
            }
            return locations;
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public VoitureDTO Read(int id)
        {
            VoitureDTO voitureDTO = new VoitureDTO();
            try
            {
                connexion.Open();
                command.CommandText = READ_REQUEST;

                command.Parameters.Add(new MySqlParameter("@idVoiture",id));
                MySqlDataReader dr = command.ExecuteReader();

                if(dr.Read()){
                    voitureDTO.idVoiture = dr.GetInt32(0);
                    voitureDTO.marque = dr.GetString(1);
                    voitureDTO.modele = dr.GetString(2);
                    voitureDTO.annee = dr.GetDateTime(3).ToString();
                }
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException);
            }
            finally
            {
                connexion.Close();
            }
            return voitureDTO;
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public int Update(VoitureDTO voitureDTO, int id)
        {
            int n = 0;
            try
            {
                connexion.Open();
                command.CommandText = UPDATE_REQUEST;

                command.Parameters.Add(new MySqlParameter("@marque", voitureDTO.marque));
                command.Parameters.Add(new MySqlParameter("@modele", voitureDTO.modele));
                command.Parameters.Add(new MySqlParameter("@annee", voitureDTO.annee));
                command.Parameters.Add(new MySqlParameter("@idVoiture", id));
                n = command.ExecuteNonQuery();
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException.Message);
            }
            finally
            {
                connexion.Close();
            }
            return n;
        }
Exemplo n.º 5
0
        /// <inheritdoc />
        public List<VoitureDTO> GetAll()
        {
            List<VoitureDTO> voitures = new List<VoitureDTO>();
            VoitureDTO voitureDTO = new VoitureDTO();
            try
            {
                connexion.Open();
                command.CommandText = GET_ALL_REQUEST;

                MySqlDataReader dr = command.ExecuteReader();
                while (dr.Read())
                {
                    Debug.WriteLine(dr);
                    voitureDTO.idVoiture = dr.GetInt32(0);
                    voitureDTO.marque = dr.GetString(1);
                    voitureDTO.modele = dr.GetString(2);
                    voitureDTO.annee = dr.GetDateTime(3).ToString();
                    voitures.Add(voitureDTO);
                }
            }
            catch (MySqlException mySqlException)
            {
                throw new DAOException(mySqlException);
            }
            finally
            {
                connexion.Close();
            }
            return voitures;
        }