Click here to Skip to main content
12,634,712 members (27,389 online)
Click here to Skip to main content

Stats

40.3K views
4K downloads
57 bookmarked
Posted

BSEtunes

, 24 Apr 2010 CPOL
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten
BSE.Platten.vssscc
mssccprj.scc
vssver2.scc
BSE.CoverFlow.WPFLib
BSE.CoverFlow.WPFLib.csproj.user
BSE.CoverFlow.WPFLib.csproj.vspscc
mssccprj.scc
vssver2.scc
Images
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
Properties
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp
BSE.Platten.Admin.WinApp.csproj.user
BSE.Platten.Admin.WinApp.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEadmin.ico
vssver2.scc
BSE.Platten.Audio
bse.ico
BSE.Platten.Audio.csproj.vspscc
mssccprj.scc
vssver2.scc
Options
vssver2.scc
Player
vssver2.scc
Properties
vssver2.scc
Resources
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
WinControls
vssver2.scc
WMFSDK
vssver2.scc
BSE.Platten.BO
BSE.Platten.BO.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Common
BSE.Platten.Common.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers
BSE.Platten.Covers.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.FreeDb
BSE.Platten.FreeDb.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
vssver2.scc
BSE.Platten.Ripper
BSE.Platten.Ripper.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
Resources
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik
BSE.Platten.Statistik.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
vssver2.scc
BSE.Platten.Tunes
BSE.Platten.Tunes.csproj.user
BSE.Platten.Tunes.csproj.vspscc
mssccprj.scc
vssver2.scc
Filters
vssver2.scc
Properties
vssver2.scc
Resources
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup
BSEadminSetup.vdproj
BSEadminSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
BSEtunesSetup
BSEtunesSetup.vdproj
BSEtunesSetup.vdproj.vspscc
mssccprj.scc
vssver2.scc
Debug
Release
dll
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.Windows.Forms.DLL
Lame
lame_enc.dll
vssver2.scc
lame-3.97
BSE.CoverFlow.WPFLib.csproj.user
close.png
exit.png
next.png
next_disabled.png
Note.jpg
pause.png
PlayButton.png
previous.png
previous_disabled.png
stop.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
vssver2.scc
Album16.gif
BSEadmin.ico
cdimport.png
cdrip.png
cd_hoeren.png
clearsearch.png
DataContainer_MoveFirsHS.png
DataContainer_MoveLastHS.png
DataContainer_MoveNextHS.png
DataContainer_MovePreviousHS.png
DataContainer_NewRecordHS.png
diskinfo.png
DRIVEDSC.png
DRIVENET.png
Edit_UndoHS.png
exportimage.png
findfile.png
FindHS.png
freedb.png
Genre16.png
Image.png
InsertPictureHS.png
Interpret16.png
OptionsHS.png
PieChart3DHS.png
PieChartHS.png
ProtectFormHS.png
RefreshDocViewHS.png
saveHS.png
search.png
song.png
system.png
tagger.png
tools_16.png
vssver2.scc
BSE.Platten.Admin.WinApp.csproj.user
vssver2.scc
BSEadmin.ico
vssver2.scc
bse.ico
BSE.Platten.Audio.csproj.user
vssver2.scc
vssver2.scc
vssver2.scc
FillDownHS.png
FillLeftHS.png
Folder256.png
FolderFind.png
FolderOpen256.png
GoLtrHS.png
MoveNext.png
MovePrevious.png
OptionsHS.png
PauseHS.png
PlayHS.png
Slider.gif
Start.png
StopHS.png
vssver2.scc
vssver2.scc
vssver2.scc
BSE.Platten.BO.csproj.user
vssver2.scc
BSE.Platten.Common.csproj.user
vssver2.scc
BSEsplash.png
DRIVEDSC.png
DRIVENET.png
Network.png
splash.png
vssver2.scc
BSE.Platten.Covers.csproj.user
vssver2.scc
BSE.Platten.FreeDb.csproj.user
vssver2.scc
OpenCD.png
vssver2.scc
AudioWriter
vssver2.scc
BSE.Platten.Ripper.csproj.user
Lame
vssver2.scc
vssver2.scc
OpenCD.png
OptionsHS.png
vssver2.scc
BSE.Platten.Statistik.csproj.user
vssver2.scc
BSE.Platten.Tunes.csproj.user
vssver2.scc
vssver2.scc
About.png
Album16.gif
AudioCD.png
AudioFile.png
AutoList.png
broadcast.png
BSE.png
BSEAbout.png
BSEsplash.png
BSEtunes.ico
BSE_16.png
cd_hoeren.png
coverflow.png
DataContainer_MoveNextHS.png
delete.gif
diskinfo.png
Filter2HS.png
FindHS.png
Folder256.png
FolderOpen256.png
Genre16.gif
Interpret16.gif
keinBild.gif
NewPlaylist16.gif
OptionsHS.png
PauseHS.png
RefreshDocViewHS.png
Removabledrive.png
saveHS.png
search.png
shuffle.png
Shuffle_icon.png
song.png
splash1.png
StopHS.png
TaskHS.png
TrackInfo.gif
vssver2.scc
wiedergabe16.gif
BSEadminSetup.vdproj
BSEtunesSetup.vdproj
BSE.CDDrives.DLL
BSE.Charts.DLL
BSE.Configuration.DLL
BSE.RemovableDrives.DLL
BSE.Shell.DLL
BSE.ThreadedShell.DLL
BSE.Windows.Forms.DLL
lame_enc.dll
MySQL.chm
using System;
using System.Data;
using System.Collections.Generic;
using MySql.Data.MySqlClient;
using System.Collections;
using System.Globalization;
using BSE.Platten.BO.Properties;

namespace BSE.Platten.BO
{
    public class CTunesModel : ModelSql
    {
        #region MethodsPublic
        #region Albums

        public static CAlbum GetAlbumById(string strConnection, int iTitelId)
        {
            CAlbum album = null;

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                album = GetAlbumDetailByTitelId(iTitelId, mySqlConnection);
                album = GetAlbumTracksByTitelId(album, mySqlConnection);
            }
            return album;
        }

        public static CTrack GetTrackWithThumbNailById(string strConnection, CTrack track)
        {
            if (track == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.IDS_ArgumentException,
                    "track"));
            }
            
            string strSelectSQL = "SELECT t.thumbnail FROM titel t" +
                " WHERE t.titelid = ?TitelId";

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strSelectSQL, mySqlConnection))
                {
                    MySqlParameter mySqlParameter = mySqlCommand.Parameters.Add(new MySqlParameter("TitelId", MySqlDbType.Int32, 0));
                    mySqlParameter.Direction = ParameterDirection.Input;
                    mySqlParameter.SourceColumn = "titelid";
                    mySqlParameter.Value = track.TitelId;

                    using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
                    {
                        if (mySqlDataReader.Read())
                        {
                            track.ThumbNail = CCoverData.GetImageFromDbReader(mySqlDataReader, "thumbnail");
                        }
                    }
                }
            }
            return track;
        }

        #endregion

        #region Trees

        public static CInterpretData[] GetInterpretsAndAlbums(string strConnection)
        {
            string strDataRelationName = "dataRelationInterpretAlbums";
            CInterpretData[] interprets = null;

            DataSet dataSetInterpretsAndAlbums = GetInterpretsAndAlbumsAsDataSet(strDataRelationName, strConnection);
            int iInterpretsCount = dataSetInterpretsAndAlbums.Tables["Interpret"].Rows.Count;
            interprets = new BSE.Platten.BO.CInterpretData[iInterpretsCount];

            for (int i = 0; i < iInterpretsCount; i++)
            {
                DataRow dataRowInterprets = dataSetInterpretsAndAlbums.Tables["Interpret"].Rows[i];
                interprets[i] = new CInterpretData();
                interprets[i].InterpretId = (int)dataRowInterprets["interpretid"];
                interprets[i].Interpret = dataRowInterprets["interpret"].ToString();

                DataRow[] dataRowsAlbums = dataRowInterprets.GetChildRows(strDataRelationName);
                int iAlbumsCount = dataRowsAlbums.Length;
                if (iAlbumsCount > 0)
                {
                    CAlbum[] albums = new CAlbum[iAlbumsCount];
                    for (int j = 0; j < iAlbumsCount; j++)
                    {
                        DataRow dataRowAlbums = dataRowsAlbums[j];
                        albums[j] = new CAlbum();
                        albums[j].AlbumId = (int)dataRowAlbums["titelid"];
                        albums[j].Title = dataRowAlbums["titel"].ToString();
                        albums[j].InterpretId = (int)dataRowAlbums["interpretid"];
                    }
                    interprets[i].Albums = albums;
                }
            }
            return interprets;
        }

        public static BSE.Platten.BO.CGenreData[] GetGenresWithAlbums(string strConnection)
        {
            string strDataRelationName = "dataRelationGenreAlbums";
            BSE.Platten.BO.CGenreData[] genre = null;

            DataSet dataSetGenresWithAlbums = GetGenresWithAlbumsAsDataSet(strDataRelationName, strConnection);
            int iGenresCount = dataSetGenresWithAlbums.Tables["Genre"].Rows.Count;
            genre = new BSE.Platten.BO.CGenreData[iGenresCount];

            for (int i = 0; i < iGenresCount; i++)
            {
                DataRow dataRowGenre = dataSetGenresWithAlbums.Tables["Genre"].Rows[i];
                genre[i] = new CGenreData();
                genre[i].GenreId = Convert.ToInt32(dataRowGenre["genreid"],CultureInfo.InvariantCulture);
                genre[i].Genre = dataRowGenre["genre"].ToString();

                DataRow[] dataRowsAlbums = dataRowGenre.GetChildRows(strDataRelationName);
                int iAlbumsCount = dataRowsAlbums.Length;
                if (iAlbumsCount > 0)
                {
                    CAlbum[] albums = new CAlbum[iAlbumsCount];
                    for (int j = 0; j < iAlbumsCount; j++)
                    {
                        DataRow dataRowAlbums = dataRowsAlbums[j];
                        albums[j] = new CAlbum();
                        albums[j].AlbumId = (int)dataRowAlbums["titelid"];
                        albums[j].Interpret = dataRowAlbums["interpret"].ToString();
                        albums[j].Title = dataRowAlbums["titel"].ToString();
                    }
                    genre[i].Albums = albums;
                }
            }
            return genre;
        }

        public static BSE.Platten.BO.CYearData[] GetYearsWithAlbums(string strConnection)
        {
            string strDataRelationName = "dataRelationYearAlbums";
            BSE.Platten.BO.CYearData[] years = null;

            DataSet dataSetYearsWithAlbums = GetYearsWithAlbumsAsDataSet(strDataRelationName, strConnection);
            int iYearsCount = dataSetYearsWithAlbums.Tables["Year"].Rows.Count;
            years = new BSE.Platten.BO.CYearData[iYearsCount];

            for (int i = 0; i < iYearsCount; i++)
            {
                DataRow dataRowYear = dataSetYearsWithAlbums.Tables["Year"].Rows[i];
                years[i] = new CYearData();
                years[i].Year = Convert.ToInt32(dataRowYear["erschdatum"],CultureInfo.InvariantCulture);

                DataRow[] dataRowsAlbums = dataRowYear.GetChildRows(strDataRelationName);
                int iAlbumsCount = dataRowsAlbums.Length;
                if (iAlbumsCount > 0)
                {
                    CAlbum[] albums = new CAlbum[iAlbumsCount];
                    for (int j = 0; j < iAlbumsCount; j++)
                    {
                        DataRow dataRowAlbums = dataRowsAlbums[j];
                        albums[j] = new CAlbum();
                        albums[j].AlbumId = (int)dataRowAlbums["titelid"];
                        albums[j].Interpret = dataRowAlbums["interpret"].ToString();
                        albums[j].Title = dataRowAlbums["titel"].ToString();
                    }
                    years[i].Albums = albums;
                }
            }
            return years;
        }

        #endregion

        #region Favorites

        public static CFavorite[] GetFavoritesByFavoritId(int iLimit, int iFavoriteId, string strBenutzer, string strConnection)
        {
            CFavorite[] favorites = null;
            ArrayList aFavorites = new ArrayList();
            string strSelectSql = string.Empty;
            switch (iFavoriteId)
            {
                case 1:
                    //Lieder
                    strSelectSql = "SELECT Count(*) AS anzahl,h.titelid,h.liedid,i.interpret,t.titel,l.lied" +
                        " FROM history h" +
                        " JOIN titel t ON h.titelid = t.titelid" +
                        " JOIN interpreten i ON t.interpretid = i.interpretid" +
                        " LEFT JOIN lieder l ON h.liedid = l.liedid" +
                        " WHERE h.appid = ?AppId" +
                        " AND h.benutzer = ?Benutzer" +
                        " GROUP BY h.titelid,h.liedid" +
                        " ORDER BY anzahl desc" +
                        " LIMIT " + iLimit;
                    break;
                case 2:
                    //Alben
                    strSelectSql = "SELECT Count(*) AS anzahl,h.titelid,i.interpret,t.titel,l.lied" +
                        " FROM history h" +
                        " JOIN titel t ON h.titelid = t.titelid" +
                        " JOIN interpreten i ON t.interpretid = i.interpretid" +
                        " LEFT JOIN lieder l ON h.liedid = l.liedid" +
                        " WHERE h.appid = ?AppId" +
                        " AND h.benutzer = ?Benutzer" +
                        " GROUP BY h.titelid" +
                        " ORDER BY anzahl desc" +
                        " LIMIT " + iLimit;
                    break;
            }

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strSelectSql, mySqlConnection))
                {
                    MySqlParameter mySqlParameterPlayerApp = mySqlCommand.Parameters.Add(new MySqlParameter("AppId", MySqlDbType.Int32, 0));
                    mySqlParameterPlayerApp.Direction = ParameterDirection.Input;
                    mySqlParameterPlayerApp.SourceColumn = "AppID";
                    mySqlParameterPlayerApp.Value = iFavoriteId;

                    MySqlParameter mySqlParameterUser = mySqlCommand.Parameters.Add(new MySqlParameter("Benutzer", MySqlDbType.VarChar, 0));
                    mySqlParameterUser.Direction = ParameterDirection.Input;
                    mySqlParameterUser.SourceColumn = "Benutzer";
                    mySqlParameterUser.Value = strBenutzer;

                    using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
                    {
                        while (mySqlDataReader.Read())
                        {
                            CFavorite favorite = new CFavorite();
                            //MySQL returns a count of the number of non-NULL values in the rows retrieved by a SELECT statement.
                            //The result is a BIGINT value. 
                            favorite.Count = Convert.ToInt32(GetInt64(mySqlDataReader, "Anzahl", true, favorite.Count));
                            favorite.TitelId = GetInt32(mySqlDataReader, "TitelId", false, favorite.TitelId);
                            favorite.Interpret = GetString(mySqlDataReader, "Interpret", false, favorite.Interpret);
                            favorite.Album = GetString(mySqlDataReader, "Titel", false, favorite.Album);
                            favorite.Title = GetString(mySqlDataReader, "Lied", true, favorite.Title);
                            aFavorites.Add(favorite);
                        }
                    }
                    favorites = new CFavorite[aFavorites.Count];
                    aFavorites.CopyTo(favorites);
                }
            }
            return favorites;
        }

        #endregion

        #region FullTextSearch

        public static SortableCollection<CTrack> GetFullTextSearchCollection(string strSearchstring, string strConnection)
        {
            SortableCollection<CTrack> trackCollection = null;
            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                trackCollection = new SortableCollection<CTrack>();
                trackCollection = GetFullTextSearchForTitleAndInterpretsCollection(strSearchstring, trackCollection, mySqlConnection);
                trackCollection = GetFullTextSearchForTitlesCollection(strSearchstring, trackCollection, mySqlConnection);
            }
            return trackCollection;
        }

        #endregion

        #region PlayList

        public static BSE.Platten.BO.CTrack[] GetAlbumTracksForPlayListByTitelId(string strConnection, int iTitelId)
        {
            BSE.Platten.BO.CTrack[] tracks = null;
            ArrayList albumTracks = new ArrayList();
            string strSelectSQL = "Select i.interpret,t.titelid,t.titel,t.erschdatum," +
                " g.genre,l.liedid,l.titelid,l.track,l.lied," +
                " l.dauer,l.liedpfad FROM lieder l" +
                " JOIN titel t ON l.titelid = t.titelid AND t.titelid = ?TitelID" +
                " JOIN interpreten i ON t.interpretid = i.interpretid" +
                " LEFT JOIN genre g ON t.genreid = g.genreid" +
                " WHERE l.liedpfad IS NOT NULL" +
                " ORDER BY l.track";

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strSelectSQL, mySqlConnection))
                {
                    MySqlParameter mySqlParameter = mySqlCommand.Parameters.Add(new MySqlParameter("TitelID", MySqlDbType.Int32, 0));
                    mySqlParameter.Direction = ParameterDirection.Input;
                    mySqlParameter.SourceColumn = "TitelID";
                    mySqlParameter.Value = iTitelId;

                    using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
                    {
                        while (mySqlDataReader.Read())
                        {
                            BSE.Platten.BO.CTrack track = new BSE.Platten.BO.CTrack();

                            track.TitelId = GetInt32(mySqlDataReader, "titelid", false, track.TitelId);
                            track.Interpret = GetString(mySqlDataReader, "interpret", false, track.Interpret);
                            track.Album = GetString(mySqlDataReader, "titel", false, track.Album);
                            track.Genre = GetString(mySqlDataReader, "genre", true, track.Genre);
                            track.Year = GetInt32(mySqlDataReader, "erschdatum", true, track.Year);
                            track.LiedId = GetInt32(mySqlDataReader, "liedid", false, track.LiedId);
                            track.TrackNumber = GetInt32(mySqlDataReader, "track", false, track.TrackNumber);
                            track.Title = GetString(mySqlDataReader, "lied", false, track.Title);
                            track.Duration = GetDateTime(mySqlDataReader, "dauer", false, track.Duration);
                            track.FileName = GetString(mySqlDataReader, "liedpfad", false, track.FileName);
                            track.FileFullName = GetString(mySqlDataReader, "liedpfad", false, track.FileName);

                            albumTracks.Add(track);
                        }
                    }
                    tracks = new BSE.Platten.BO.CTrack[albumTracks.Count];
                    albumTracks.CopyTo(tracks);
                }
            }
            return tracks;
        }

        public static BSE.Platten.BO.CTrack GetTrackForPlayListByLiedId(string strConnection, int iLiedId)
        {
            BSE.Platten.BO.CTrack track = null;
            string strSelectSQL = "Select i.interpret,t.titelid,t.titel,t.erschdatum," +
                " g.genre,l.liedid,l.titelid,l.track,l.lied," +
                " l.dauer,l.liedpfad FROM lieder l" +
                " JOIN titel t ON l.titelid = t.titelid" +
                " JOIN interpreten i ON t.interpretid = i.interpretid" +
                " LEFT JOIN genre g ON t.genreid = g.genreid" +
                " WHERE l.liedpfad IS NOT NULL" +
                " AND l.liedid = ?LiedId";

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strSelectSQL, mySqlConnection))
                {
                    MySqlParameter mySqlParameter = mySqlCommand.Parameters.Add(new MySqlParameter("LiedId", MySqlDbType.Int32, 0));
                    mySqlParameter.Direction = ParameterDirection.Input;
                    mySqlParameter.SourceColumn = "LiedId";
                    mySqlParameter.Value = iLiedId;

                    using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
                    {
                        if (mySqlDataReader.Read())
                        {
                            track = new CTrack();
                            track.TitelId = GetInt32(mySqlDataReader, "titelid", false, track.TitelId);
                            track.Interpret = GetString(mySqlDataReader, "interpret", false, track.Interpret);
                            track.Album = GetString(mySqlDataReader, "titel", false, track.Album);
                            track.Genre = GetString(mySqlDataReader, "genre", true, track.Genre);
                            track.Year = GetInt32(mySqlDataReader, "erschdatum", true, track.Year);
                            track.LiedId = GetInt32(mySqlDataReader, "liedid", false, track.LiedId);
                            track.TrackNumber = GetInt32(mySqlDataReader, "track", false, track.TrackNumber);
                            track.Title = GetString(mySqlDataReader, "lied", false, track.Title);
                            track.Duration = GetDateTime(mySqlDataReader, "dauer", false, track.Duration);
                            track.FileName = GetString(mySqlDataReader, "liedpfad", false, track.FileName);
                            track.FileFullName = GetString(mySqlDataReader, "liedpfad", false, track.FileName);
                        }
                    }
                }
            }
            return track;
        }

        public static CPlaylist[] GetPlaylistsByUserName(string strConnection, string userName)
        {
            CPlaylist[] playLists = null;
            string strSqlPlaylists = "SELECT listid,listname FROM playlist" +
                " WHERE user = ?User" +
                " ORDER BY listname";
            ArrayList aPlayLists = new ArrayList();

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strSqlPlaylists, mySqlConnection))
                {
                    MySqlParameter mySqlParameter = mySqlCommand.Parameters.Add(new MySqlParameter("User", MySqlDbType.VarChar, 50));
                    mySqlParameter.Direction = ParameterDirection.Input;
                    mySqlParameter.SourceColumn = "User";
                    mySqlParameter.Value = userName;

                    using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
                    {
                        while (mySqlDataReader.Read())
                        {
                            BSE.Platten.BO.CPlaylist playList = new BSE.Platten.BO.CPlaylist();

                            playList.Id = GetInt32(mySqlDataReader, "ListId", false, playList.Id);
                            playList.Name = GetString(mySqlDataReader, "ListName", false, playList.Name);

                            aPlayLists.Add(playList);
                        }
                    }
                    playLists = new CPlaylist[aPlayLists.Count];
                    aPlayLists.CopyTo(playLists);
                }
            }
            return playLists;
        }

        public static CPlaylist InsertPlaylist(string strConnection, CPlaylist playList)
        {
            if (playList == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.IDS_ArgumentException,
                    "playList"));
            }
            
            string strInsertPlaylistSQL = "INSERT INTO playlist " +
                " (listid,listname,user,Guid)" +
                " VALUES(" +
                " 0,?ListName,?User,?Guid)";

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strInsertPlaylistSQL, mySqlConnection))
                {
                    MySqlParameter mySqlParameterName = mySqlCommand.Parameters.Add(new MySqlParameter("ListName", MySqlDbType.VarChar, 100));
                    mySqlParameterName.Direction = ParameterDirection.Input;
                    mySqlParameterName.SourceColumn = "ListName";
                    mySqlParameterName.Value = playList.Name;

                    MySqlParameter mySqlParameterUser = mySqlCommand.Parameters.Add(new MySqlParameter("User", MySqlDbType.VarChar, 50));
                    mySqlParameterUser.Direction = ParameterDirection.Input;
                    mySqlParameterUser.SourceColumn = "User";
                    mySqlParameterUser.Value = playList.User;

                    MySqlParameter mySqlParameterGuid = mySqlCommand.Parameters.Add(new MySqlParameter("Guid", MySqlDbType.VarChar, 36));
                    mySqlParameterGuid.Direction = ParameterDirection.Input;
                    mySqlParameterGuid.SourceColumn = "guid";
                    mySqlParameterGuid.Value = playList.Guid.ToString();

                    if (mySqlCommand.ExecuteNonQuery() > 0)
                    {
                        playList = GetPlayListByGuid(playList, mySqlConnection);
                    }
                }
            }
            return playList;
        }

        public static void SavePlayList(string strConnection, CPlaylist playList)
        {
            if (playList == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.IDS_ArgumentException,
                    "playList"));
            }
            
            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();
                using (MySqlTransaction mySqlTransaction = mySqlConnection.BeginTransaction())
                {
                    try
                    {
                        if (DeletePlayListEntries(playList.Id, mySqlConnection))
                        {
                            InsertPlayListEntries(playList, mySqlConnection);
                            mySqlTransaction.Commit();
                        }
                    }
                    catch (MySqlException)
                    {
                        mySqlTransaction.Rollback();
                        throw;
                    }
                }
            }
        }

        public static void DeletePlayList(string strConnection, int iPlayListId)
        {
            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();
                try
                {
                    using (MySqlTransaction mySqlTransaction = mySqlConnection.BeginTransaction())
                    {
                        try
                        {
                            if (DeletePlayListEntries(iPlayListId, mySqlConnection))
                            {
                                DeletePlayList(iPlayListId, mySqlConnection);
                                mySqlTransaction.Commit();
                            }
                        }
                        catch (MySqlException)
                        {
                            mySqlTransaction.Rollback();
                            throw;
                        }
                    }
                }
                catch (MySqlException)
                {
                    throw;
                }
            }
        }

        public static CPlaylist GetPlayListByPlayListId(string strConnection, int iPlayListId)
        {
            CPlaylist playList = null;
            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                playList = GetPlayListByPlayListId(iPlayListId, mySqlConnection);
                if (playList != null)
                {
                    playList = GetPlayListEntriesByPlayListId(playList, mySqlConnection);
                }
            }
            return playList;
        }

        #endregion

        #region Filters

        public static CFilter[] GetFilterByFilterMode(string strConnection, FilterSettings.FilterMode filterMode)
        {
            CFilter[] filters = null;

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                switch (filterMode)
                {
                    case FilterSettings.FilterMode.Genre:
                        filters = GetFilterByFilterModeGenre(mySqlConnection);
                        break;
                    case FilterSettings.FilterMode.Year:
                        filters = GetFilterByFilterModeYear(mySqlConnection);
                        break;
                }
            }
            return filters;
        }

        public static CTrackCollection GetTracksByFilterSettings(string strConnection, FilterSettings filterSettings)
        {
            if (filterSettings == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.IDS_ArgumentException,
                    "filterSettings"));
            }
            
            string strSelectSql = string.Empty;
            CTrackCollection trackCollection = new CTrackCollection();
            switch (filterSettings.UsedFilterMode)
            {
                case FilterSettings.FilterMode.None:
                    strSelectSql = "SELECT l.liedid,t.titelid,i.interpret,t.titel,l.lied, l.liedpfad" +
                        " FROM lieder l" +
                        " JOIN titel t ON l.titelid = t.titelid" +
                        " JOIN interpreten i ON t.interpretid = i.interpretid" +
                        " WHERE l.liedpfad IS NOT NULL" +
                        " ORDER BY l.liedid";
                    break;
                case FilterSettings.FilterMode.Year:
                    strSelectSql = "SELECT l.liedId,t.titelid,i.interpret,t.titel,l.lied, l.liedpfad" +
                        " FROM lieder l" +
                        " JOIN titel t ON l.titelid = t.titelid" +
                        " JOIN interpreten i ON t.interpretid = i.interpretid" +
                        " WHERE t.erschdatum IN (" + filterSettings.Value + ")" +
                        " AND l.liedpfad IS NOT NULL";
                    break;
                case FilterSettings.FilterMode.Genre:
                    strSelectSql = "SELECT l.liedId,t.titelid,i.interpret,t.titel,l.lied, l.liedpfad" +
                        " FROM lieder l" +
                        " JOIN titel t ON l.titelid = t.titelid" +
                        " JOIN interpreten i ON t.interpretid = i.interpretid" +
                        " WHERE t.genreid IN (" + filterSettings.Value + ")" +
                        " AND l.liedpfad IS NOT NULL";
                    break;
            }

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strSelectSql, mySqlConnection))
                {
                    using (MySqlDataReader mySqlDataReader = mySqlCommand.ExecuteReader())
                    {
                        while (mySqlDataReader.Read())
                        {
                            CTrack track = new CTrack();

                            track.LiedId = GetInt32(mySqlDataReader,"liedId",false,track.LiedId);
                            track.TitelId = GetInt32(mySqlDataReader, "titelid", false, track.TitelId);
                            track.Interpret = GetString(mySqlDataReader, "interpret", false, track.Interpret);
                            track.Album = GetString(mySqlDataReader, "titel", false, track.Album);
                            track.Title = GetString(mySqlDataReader, "lied", false, track.Title);
                            track.FileName = GetString(mySqlDataReader, "liedpfad", false, track.FileName);

                            trackCollection.Add(track);
                        }
                    }
                }
            }
            return trackCollection;
        }

        public static FilterSettings GetFilterSettings(string strConnection, FilterSettings.FilterMode filterMode, string strBenutzer)
        {
            FilterSettings filterSettings = null;

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                filterSettings = GetFilterSettings(mySqlConnection, filterMode, strBenutzer);
                if (filterSettings == null)
                {
                    InsertFilterSettings(mySqlConnection, filterMode, strBenutzer);
                }
            }
            return filterSettings;
        }

        public static void SaveFilterSettings(string strConnection, FilterSettings filterSettings)
        {
            if (filterSettings == null)
            {
                throw new ArgumentNullException(
                    string.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.IDS_ArgumentException,
                    "filterSettings"));
            }
            
            string strUpdateSql = "UPDATE filtersettings" +
                " SET value = ?Value," +
                " isused = ?IsUsed" +
                " WHERE mode = ?Mode" +
                " AND benutzer = ?Benutzer";

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                using (MySqlCommand mySqlCommand = new MySqlCommand(strUpdateSql, mySqlConnection))
                {
                    MySqlParameter mySqlParameterFilterMode = mySqlCommand.Parameters.Add(new MySqlParameter("Mode", MySqlDbType.Int32));
                    mySqlParameterFilterMode.Direction = ParameterDirection.Input;
                    mySqlParameterFilterMode.SourceColumn = "mode";
                    mySqlParameterFilterMode.Value = filterSettings.UsedFilterMode;

                    MySqlParameter mySqlParameterValue = mySqlCommand.Parameters.Add(new MySqlParameter("Value", MySqlDbType.VarChar, 255));
                    mySqlParameterValue.Direction = ParameterDirection.Input;
                    mySqlParameterValue.SourceColumn = "value";
                    mySqlParameterValue.Value = filterSettings.Value;

                    MySqlParameter mySqlParameterUsed = mySqlCommand.Parameters.Add(new MySqlParameter("IsUsed", MySqlDbType.Bit));
                    mySqlParameterUsed.Direction = ParameterDirection.Input;
                    mySqlParameterUsed.SourceColumn = "isused";
                    mySqlParameterUsed.Value = filterSettings.IsUsed;

                    MySqlParameter mySqlParameterBenutzer = mySqlCommand.Parameters.Add(new MySqlParameter("Benutzer", MySqlDbType.VarChar, 50));
                    mySqlParameterBenutzer.Direction = ParameterDirection.Input;
                    mySqlParameterBenutzer.SourceColumn = "benutzer";
                    mySqlParameterBenutzer.Value = filterSettings.Benutzer;

                    mySqlCommand.ExecuteNonQuery();
                }
            }
        }

        #endregion

        #region History

        public static SortableCollection<CTrack> GetHistoryTrackCollection(string strConnection, string strUser)
        {
            SortableCollection<CTrack> trackCollection = new SortableCollection<CTrack>();

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                trackCollection = GetHistoryTrackCollection(mySqlConnection, trackCollection, strUser);
            }
            return trackCollection;
        }

        public static SortableCollection<CTrack> GetHistoryTrackCollection(string strConnection, HistoryData historyData)
        {
            SortableCollection<CTrack> trackCollection = new SortableCollection<CTrack>();
            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                if (InsertHistoryData(mySqlConnection, historyData))
                {
                    trackCollection = GetHistoryTrackCollection(mySqlConnection, trackCollection, historyData.UserName);
                }
            }
            return trackCollection;
        }

        public static void DeleteTracksFromHistory(string strConnection, string strUser)
        {
            int iAppId = 0; //Radio
            int iCountHistoryTracks = 0;
            int iPlayListLimit = 40;

            using (MySqlConnection mySqlConnection = new MySqlConnection(strConnection))
            {
                mySqlConnection.Open();

                int iLastId = SelectLastIdFromHistory(mySqlConnection, strUser, iPlayListLimit, out iCountHistoryTracks);
                if (iLastId > 0 && iCountHistoryTrack