Beispiel #1
0
        public List <Album> getAllAlbums()
        {
            SqlConnection connection = Connection.GetConnection();

            List <Album> albums = new List <Album>();

            connection.Open();

            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = connection;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "spSelectAlbums";
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                //Namen in blokhaakjes aanpassen naar namen in je database
                Album album = new Album();
                album.albumNaam       = reader["Title"].ToString();
                album.Artist          = reader["Artist"].ToString();
                album.Biografie       = reader["Autobiography"].ToString();
                album.frontcover      = AlbumImage.Image((byte[])reader["FrontCover"]);
                album.backcover       = AlbumImage.Image((byte[])reader["BackCover"]);
                album.genrealbum.Name = reader["Genre"].ToString();
                if (reader["Year"].ToString() != "")
                {
                    album.Year = Convert.ToInt32(reader["Year"]);
                }
                albums.Add(album);
            }


            return(albums);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static Album InitializeAlbum()
        {
            try
            {
                //Read album from file
                Dictionary <string, byte[]> albumAttributes = FileIO.GetAlbum();

                //store temporarly the tracks from the album
                Dictionary <string, byte[]> songs = new Dictionary <string, byte[]>();
                if (albumAttributes.ContainsKey("autobiography") && albumAttributes.ContainsKey("frontcover") &&
                    albumAttributes.ContainsKey("backcover") && albumAttributes.Count > 3)
                {
                    for (int i = 3; i < albumAttributes.Count; i++)
                    {
                        songs.Add(albumAttributes.Keys.ElementAt(i), albumAttributes.Values.ElementAt(i));
                    }
                }
                else
                {
                    throw new ArgumentException("Error in album storage structure. \r\nRead the manual for storing an album on your hard drive");
                }

                //Initialize the album partly
                Album partlyAlbum = new Album
                {
                    /*
                     *  System.Text.Encoding.UTF8.GetString(byte[], 0, btye[].Length)
                     *  This code converts the autobiography, stored as a byte[],  to a string
                     */
                    Biografie  = System.Text.Encoding.UTF8.GetString(albumAttributes["autobiography"], 0, albumAttributes["autobiography"].Length),
                    Frontcover = AlbumImage.Image(albumAttributes["frontcover"]),
                    Backcover  = AlbumImage.Image(albumAttributes["backcover"]),
                    trackList  = new TrackList(songs)
                };
                return(partlyAlbum);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }