Esempio n. 1
0
        /// <summary>
        /// GetBoekenLijst()
        /// </summary>
        /// <returns></returns>
        public static List<Boeken> GetBoekenLijst()
        {

            List<Boeken> boekenLijst = new List<Boeken>();
            SqlConnection conn = new SqlConnection(BibliotheekDB.GetConnection());
            string selectStatement = "SELECT Titel, Aantal" +
                                     " FROM Boeken" +
                                     " ORDER BY Titel";
            SqlCommand selectCommand = new SqlCommand(selectStatement, conn);

            try
            {
                conn.Open();
                SqlDataReader reader = selectCommand.ExecuteReader();
                while (reader.Read())
                {
                    Boeken boek = new Boeken();
                    boek.Boek_Titel = reader["Titel"].ToString();
                    boek.Boek_Aantal = (int)reader["Aantal"];
                    boekenLijst.Add(boek);
                }
                reader.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return boekenLijst;
        }
 public Boolean setNieuwBoek(Boeken boek)
 {
     return BoekenDB.setNieuwBoek(boek);
 }
Esempio n. 3
0
        /// <summary>
        /// GetBoeken_byAuteurId
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        //public static Boeken GetBoeken_ByAuteurId(int Id)
        //{
        //    SqlConnection conn = null;
        //    Boeken myBoek = new Boeken();

        //    try
        //    {
        //        using (conn = new SqlConnection(BibliotheekDB.GetConnection()))
        //        {
        //            string selectStatement = "SELECT Boeken.Titel " + 
        //                                    "FROM Boeken, Auteurs " +
        //                                    "WHERE Boeken.AuteurId = Auteurs.A_Id";
        //            SqlCommand myCommand = new SqlCommand(selectStatement, conn);
        //            //myCommand.Parameters.AddWithValue("@AlbumId", Id);

        //            conn.Open();

        //            SqlDataReader myReader = myCommand.ExecuteReader();

        //            if (myReader.Read())
        //            {
        //                // Lees genreId
        //                int genreid = (int)myReader[1];
        //                myAlbum.Genre = GenreDB.GetGenreById(genreid);
        //                int artistId = (int)myReader[2];
        //                myAlbum.Artist = ArtistDB.GetArtistById(artistId);

        //                myAlbum.Title = myReader[3].ToString();
        //                myAlbum.Price = (double)myReader.GetDecimal(4);
        //                myAlbum.AlbumArtUrl = myReader[5].ToString();
        //            }
        //        }
        //    }
        //    catch (SqlException ex)
        //    {
        //        throw ex;
        //    }
        //    return myAlbum;
        //}

        public static Boeken getBoekById(int boekId){
            SqlConnection conn = new SqlConnection(BibliotheekDB.GetConnection());
            
            SqlCommand selectCommand = new SqlCommand("spGetBoekById", conn);
            selectCommand.CommandType = CommandType.StoredProcedure;
            selectCommand.Parameters.AddWithValue("@boekId", boekId);
            Boeken boek = null;
            try
            {
                conn.Open();
                SqlDataReader reader = selectCommand.ExecuteReader(CommandBehavior.SingleRow);
                if (reader.Read())
                {
                    boek = new Boeken();
                    boek.Boek_Id = Convert.ToInt32(reader["B_Id"].ToString());
                    boek.Boek_Titel = reader["Titel"].ToString();
                    boek.BoekAuteur_Id = Convert.ToInt32(reader["AuteurId"].ToString());
                    boek.Boek_GenreId = Convert.ToInt32(reader["GenreId"].ToString());
                    boek.Boek_EersteUitgave = Convert.ToInt32(reader["eersteUitgave"].ToString());
                    boek.Boek_Aantal = Convert.ToInt32(reader["Aantal"].ToString());

                }
                reader.Close();
                return boek;
            }
            catch (SqlException ex)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// nieuw boek toevoegen
        /// </summary>
        /// <param name="boek">boek</param>
        /// <returns>boolean (gelukt of niet gelukt)</returns>

        public static Boolean setNieuwBoek(Boeken boek)
        {
            SqlConnection conn = new SqlConnection(BibliotheekDB.GetConnection());
            String insertStatement = "INSERT INTO Boeken(Titel, AuteurId, GenreId, EersteUitgave, Aantal) " +
                                    "VALUES(@titel, @auteurId, @genreId, @eersteUitgave, @aantal)";
            SqlCommand insertCommand = new SqlCommand(insertStatement, conn);
            insertCommand.Parameters.AddWithValue("@titel", boek.Boek_Titel);
            insertCommand.Parameters.AddWithValue("@auteurId", boek.BoekAuteur_Id);
            insertCommand.Parameters.AddWithValue("@genreId", boek.Boek_GenreId);
            insertCommand.Parameters.AddWithValue("@eersteUitgave", boek.Boek_EersteUitgave);
            insertCommand.Parameters.AddWithValue("@aantal", boek.Boek_Aantal);

            try
            {
                conn.Open();
                int uitgevoerd;
                uitgevoerd = insertCommand.ExecuteNonQuery();
                if (uitgevoerd == 1)
                {
                    return true;
                }
                return false;
            }
            catch (SqlException ex)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 5
0
 /// <summary>
 /// maakt een lijst van boeken die nog in voorraad zijn
 /// </summary>
 /// <returns>een lijst met de boeken in voorraad</returns>
 public static List<Boeken> getBoekenInVoorraad()
 {
     SqlConnection conn = new SqlConnection(BibliotheekDB.GetConnection());
     String selectStatement = "SELECT * FROM Boeken ORDER BY Titel";
     SqlCommand selectCommand = new SqlCommand(selectStatement, conn);
     List<Boeken> boekenLijst = null;
     try
     {
         conn.Open();
         SqlDataReader reader = selectCommand.ExecuteReader();
         boekenLijst = new List<Boeken>();
         while (reader.Read())
         {
             
             Boeken boek = new Boeken();
             boek.Boek_Id = Convert.ToInt32(reader["B_Id"].ToString());
             int aantalUitgeleend = UitleningenDB.getAantalUitgeleend(boek.Boek_Id);
             boek.Boek_Titel = reader["Titel"].ToString();
             boek.Boek_Aantal = Convert.ToInt32(reader["Aantal"].ToString());
             if((boek.Boek_Aantal - aantalUitgeleend)>0)
                 boekenLijst.Add(boek);
         }
         reader.Close();
         return boekenLijst;
     }
     catch (SqlException ex)
     {
         throw;
     }
     finally
     {
         conn.Close();
     }
 }