Click here to Skip to main content
12,291,499 members (56,967 online)
Click here to Skip to main content

Stats

38.5K views
3.9K downloads
56 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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using BSE.Platten.BO;
using BSE.Platten.Common;
using BSE.Configuration;
using BSE.Platten.Audio;
using System.Globalization;
using BSE.Windows.Forms;
using BSE.Platten.Tunes.Properties;
using System.IO;
using System.Windows.Interop;

namespace BSE.Platten.Tunes
{
    public partial class CTunes : BaseForm, IConfigurationSettings
    {
        #region Constants

        private const string m_strSettingsFileNameSettingsPart = ".Settings";

        #endregion

        #region Enumeratoren

        public enum EPlayerApp
        {
            Radio,
            Lied,
            CD
        }

        public enum PlayButtonMode
        {
            Start,
            Pause,
            Stop
        }

        #endregion

        #region Delegates

        private delegate void DelegateRefreshControls();
        private delegate void DelegateStopRadio();

        #endregion

        #region FieldsPrivate

        private CAlbum m_currentAlbum;
        private CTrackCollection m_trackCollectionByFilterSettings;
        private CEnvironment m_environment;
        private string m_strAudioHomeDirectory;
        private string m_strConnection;
        private Image m_imgSong;
        private System.Threading.Thread m_threadControlRefresh;

        #endregion

        #region Properties

        #region IConfigurationSettings

        public string ConfigurationFolder
        {
            get { return this.GetType().Namespace; }
        }

        public string ConfigurationFileName
        {
            get { return this.GetType().Namespace; }
        }

        public string SettingsFileName
        {
            get { return this.GetType().Namespace + m_strSettingsFileNameSettingsPart; }
        }
        #endregion

        internal string AudioHomeDirectory
        {
            get { return this.m_strAudioHomeDirectory; }
            set { this.m_strAudioHomeDirectory = value; }
        }
        
        internal string ConnectionString
        {
            get { return this.m_strConnection; }
            set { this.m_strConnection = value; }
        }

        internal CEnvironment Environment
        {
            get { return this.m_environment; }
            set { this.m_environment = value; }
        }

        internal CAlbum CurrentAlbum
        {
            get { return this.m_currentAlbum; }
            set { this.m_currentAlbum = value; }
        }

        internal CTrackCollection TrackCollectionByFilterSettings
        {
            get { return this.m_trackCollectionByFilterSettings; }
            set { this.m_trackCollectionByFilterSettings = value; }
        }

        #endregion

        #region MethodsPublic

        public CTunes() : base()
        {
            InitializeComponent();
            
            this.m_configuration.ApplicationSubDirectory = this.ConfigurationFolder;
            this.m_configuration.ConfigFileName = this.ConfigurationFileName;

            this.m_environment = new CEnvironment(this.m_configuration);

            this.m_settings.ApplicationSubDirectory = this.ConfigurationFolder;
            this.m_settings.ConfigFileName = this.SettingsFileName;

            this.m_imgSong = Properties.Resources.song;

            this.AllowDrop = true;
            this.KeyPreview = true;

            this.m_tsAudioPlayer.Stretch = true;
            this.m_tsAudioPlayer.GripStyle = ToolStripGripStyle.Hidden;
            ToolStripManager.Merge(this.m_tsSearch, this.m_tsMusic);
            ToolStripManager.Merge(this.m_tsMusic, this.m_tsAudioPlayer);

            this.m_pnlSearch.Tag = this.m_mnuView_Search;
            this.m_pnlPlayList.Tag = this.m_mnuView_PlaylistEditor;

            this.m_playList.PlayerManager = this.m_playerManager;
            this.m_albumProperties.PlayerManager = this.m_playerManager;
            this.m_clipBoard.PlayerManager = this.m_playerManager;

        }

        #endregion

        #region MethodsPrivate

        private void CTunes_Load(object sender, EventArgs e)
        {
            int iSplashStep = 0;
            int iSplashStepsTotal = 14;
            CSplashScreen.ShowSplashScreen();
            CSplashScreen.SetStatusMessage("Lade Systemsettings", iSplashStep++, iSplashStepsTotal);
            CTunesSettingsData settingsData = LoadSettings();
            try
            {
                this.m_mnuView.Enabled = false;
                this.m_mnuFilter.Enabled = false;
                this.m_mnuExtras_Statistik.Enabled = false;
                
                //Starte Payer
                CSplashScreen.SetStatusMessage("Starte Player", iSplashStep++, iSplashStepsTotal);
                this.m_playerManager.LoadPlayer(this.m_configuration);
                CSplashScreen.SetStatusMessage("Pr�fe Datenbankverbindung", iSplashStep++, iSplashStepsTotal);
                this.ConnectionString = this.m_environment.GetConnectionString();
                CSplashScreen.SetStatusMessage("Pr�fe Audio Home- Verzeichnis", iSplashStep++, iSplashStepsTotal);
                this.AudioHomeDirectory = this.m_environment.GetAudioHomeDirectory();

                CSplashScreen.SetStatusMessage("Pr�fe Datenbankhost", iSplashStep++, iSplashStepsTotal);
                if (this.m_ssMain.IsHostAvailable(this.m_environment) == true)
                {
                    this.m_mnuView.Enabled = true;
                    this.m_mnuFilter.Enabled = true;
                    this.m_mnuExtras_Statistik.Enabled = true;

                    CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.ConnectionString);

                    //Lade Covers
                    CSplashScreen.SetStatusMessage("Lade Covers", iSplashStep++, iSplashStepsTotal);
                    GetCovers();

                    //l�dt Alben und Genres in den Tree
                    CSplashScreen.SetStatusMessage("Lade Alben", iSplashStep++, iSplashStepsTotal);
                    CInterpretData[] interpretsAndAlbums = tunesBusinessObject.GetInterpretsAndAlbums();
                    this.m_treeInterpretenTitel.SetInterpretsAndAlbums(interpretsAndAlbums);

                    //l�dt den TreeviewGenreInterpretsAndTitles
                    CSplashScreen.SetStatusMessage("Lade Genres", iSplashStep++, iSplashStepsTotal);
                    CGenreData[] genreWithAlbums = tunesBusinessObject.GetGenresWithAlbums();
                    this.m_treeInterpretenTitel.SetGenresWithAlbums(genreWithAlbums);

                    //l�dt den TreeviewYearInterpretsAndTitles
                    CSplashScreen.SetStatusMessage("Lade Jahr", iSplashStep++, iSplashStepsTotal);
                    CYearData[] yearsWithAlbums = tunesBusinessObject.GetYearsWithAlbums();
                    this.m_treeInterpretenTitel.SetYearsWithAlbums(yearsWithAlbums);

                    //l�scht alte Eintr�ge aus der Benutzerhistory
                    CSplashScreen.SetStatusMessage("L�sche History", iSplashStep++, iSplashStepsTotal);
                    tunesBusinessObject.DeleteTracksFromHistory(this.m_environment.UserName);

                    //l�dt die Benutzerhistory
                    CSplashScreen.SetStatusMessage("Lade History", iSplashStep++, iSplashStepsTotal);
                    SortableCollection<CTrack> trackCollection = tunesBusinessObject.GetHistoryTrackCollection(this.m_environment.UserName);
                    this.m_history.UpdateHistory(trackCollection);

                    //Lied Favorites
                    CSplashScreen.SetStatusMessage("Lade Favoriten", iSplashStep++, iSplashStepsTotal);
                    CFavorite[] singleFavorites
                        = tunesBusinessObject.GetFavoritesByFavoritId(10, (int)EPlayerApp.Lied, this.m_environment.UserName);
                    this.m_treeFavorites.SetFavorites(singleFavorites, ListMode.Singlecharts);

                    //CD Favorites
                    CFavorite[] albumFavorites
                        = tunesBusinessObject.GetFavoritesByFavoritId(10, (int)EPlayerApp.CD, this.m_environment.UserName);
                    this.m_treeFavorites.SetFavorites(albumFavorites, ListMode.Albumcharts);

                    //Playlisten
                    CSplashScreen.SetStatusMessage("Lade Wiedergabelisten", iSplashStep++, iSplashStepsTotal);
                    CPlaylist[] playLists = tunesBusinessObject.GetPlaylistsByUserName(this.m_environment.UserName);
                    this.m_treeFavorites.SetPlayLists(playLists);

                    //Filter
                    CSplashScreen.SetStatusMessage("Lade Filter", iSplashStep++, iSplashStepsTotal);
                    BSE.Platten.Tunes.Filters.FilterMain filter
                        = new BSE.Platten.Tunes.Filters.FilterMain();
                    Filters.FilterConfiguration filterConfiguration
                        = filter.GetFilterConfiguration(this.m_environment);
                    this.m_mnuFilter_Properties.Text = filterConfiguration.FilterName;
                    this.TrackCollectionByFilterSettings = filter.GetTracksByFilterSettings(this.m_environment, (FilterSettings)filterConfiguration);
                    if (this.TrackCollectionByFilterSettings.Count > 0)
                    {
                        int iIndex = this.TrackCollectionByFilterSettings.GetRandomIndex();
                        CTrack currentTrack = this.TrackCollectionByFilterSettings[iIndex] as CTrack;
                        if (currentTrack != null)
                        {
                            int iStartTitelId = currentTrack.TitelId;
                            GetSelectedTitle(iStartTitelId, true);
                        }
                    }

                    this.m_search.Environment = this.m_environment;
                    this.m_playList.Environment = this.m_environment;
                    this.m_history.Environment = this.m_environment;
                    this.m_clipBoard.Environment = this.m_environment;
                }
            }
            catch (BSE.Configuration.CConfigurationValueNotFoundException configurationValueNotFoundException)
            {
                if (CSplashScreen.SplashScreen != null)
                {
                    CSplashScreen.CloseSplashScreen(this);
                }
                DialogResult dialogResult = GlobalizedMessageBox.Show(this, configurationValueNotFoundException.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (dialogResult == DialogResult.OK)
                {
                    OpenOptions();
                }
            }
            catch (Exception exception)
            {
                if (CSplashScreen.SplashScreen != null)
                {
                    CSplashScreen.CloseSplashScreen(this);
                }
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.m_ssMain.HostAvailabilityChanged += new EventHandler<HostAvailableEventArgs>(HostAvailable);
                this.m_plstMain.Expand(this.m_pnlHistory);

                RenderStyleConfigurationData formStyleConfigurationData =
                    BSE.Platten.Common.RenderStyleConfigurationControl.GetConfiguration(this.m_configuration) as RenderStyleConfigurationData;
                if (formStyleConfigurationData != null)
                {
                    SetFormStyleSettings(formStyleConfigurationData);
                }

                if (settingsData != null && settingsData.WindowState == FormWindowState.Maximized)
                {
                    this.WindowState = FormWindowState.Maximized;
                }

                if (CSplashScreen.SplashScreen != null)
                {
                    CSplashScreen.CloseSplashScreen(this);
                }
            }
        }
        
        private void CTunes_FormClosing(object sender, FormClosingEventArgs e)
        {
            SaveSettings();
            if (this.m_playerManager.HasPlayerStarted)
            {
                this.m_playerManager.Close();
            }
            Application.Exit();
        }

        private void CTunes_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.F12:
                    if (this.m_currentAlbum.Tracks != null)
                    {
                        this.m_ctxTunes.Items.Clear();
                        this.m_ctxTunes.Items.AddRange(GetToolStripMenuItemsLieder());
                        this.m_ctxTunes.Show(new Point(Cursor.Position.X, Cursor.Position.Y));
                    }
                    break;
            }
        }

        private void OptionenClick(object sender, EventArgs e)
        {
            OpenOptions();
        }

        private void OpenOptions()
        {
            Application.DoEvents();
            try
            {
                using (Options options = new Options(this.m_configuration))
                {
                    options.ConfigurationChanged += new EventHandler(this.OptionsConfigurationChanged);
                    options.AudioPlayerChanged += new EventHandler(this.AudioPlayerChanged);
                    options.FormStyleChanged += new EventHandler(this.FormStyleChanged);
                    options.ShowDialog(this);
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void OptionsConfigurationChanged(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                //If the AudioHome Directory has changed
                string strAudioHomeDirectory = this.m_environment.GetAudioHomeDirectory();
                int iCompareAudioHomeDirectory = string.Compare(
                    this.AudioHomeDirectory,
                    strAudioHomeDirectory,
                    StringComparison.OrdinalIgnoreCase);

                if (iCompareAudioHomeDirectory.Equals(0) == false)
                {
                    this.AudioHomeDirectory = strAudioHomeDirectory;
                }

                //If the ConnectionString has changed
                string strConnection = this.m_environment.GetConnectionString();
                int iCompareConnectionString = string.Compare(
                    this.ConnectionString,
                    strConnection,
                    StringComparison.OrdinalIgnoreCase);

                if (iCompareConnectionString.Equals(0) == false)
                {
                    this.ConnectionString = strConnection;
                    if (this.m_ssMain.IsHostAvailable(this.m_environment) == true)
                    {
                        StartRefreshControlsThread();

                        this.m_mnuView.Enabled = true;
                        this.m_mnuFilter.Enabled = true;
                        this.m_mnuExtras_Statistik.Enabled = true;

                        this.m_search.Environment = this.m_environment;
                        this.m_playList.Environment = this.m_environment;
                        this.m_history.Environment = this.m_environment;
                        this.m_clipBoard.Environment = this.m_environment;
                    }
                }
            }
            catch (BSE.Configuration.CConfigurationValueNotFoundException configurationValueNotFoundException)
            {
                DialogResult dialogResult = GlobalizedMessageBox.Show(this, configurationValueNotFoundException.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                if (dialogResult == DialogResult.OK)
                {
                    OpenOptions();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void AudioPlayerChanged(object sender, EventArgs e)
        {
            try
            {
                this.m_playerManager.LoadPlayer(this.m_configuration);
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void FormStyleChanged(object sender, EventArgs e)
        {
            RenderStyleConfigurationData formStyleConfigurationData = RenderStyleConfigurationControl.GetConfiguration(
                this.m_configuration) as RenderStyleConfigurationData;
            if (formStyleConfigurationData != null)
            {
                SetFormStyleSettings(formStyleConfigurationData);
            }
        }

        private void SetFormStyleSettings(RenderStyleConfigurationData renderStyleConfigurationData)
        {
            if ((ToolStripManager.VisualStylesEnabled == true) && (renderStyleConfigurationData != null))
            {
                RenderStyle renderStyle = renderStyleConfigurationData.RenderStyle;
                if (renderStyle != null)
                {
                    ToolStripProfessionalRenderer toolStripRenderer = null;
                    BSE.Windows.Forms.ProfessionalColorTable professionalColorTable = null;
                    BSE.Windows.Forms.PanelColors panelColors = null;
                    BSE.Windows.Forms.PanelStyle panelStyle = renderStyle.PanelStyle;

                    if (renderStyle.TypeProfessionalColorTable != null)
                    {
                        professionalColorTable =
                            Activator.CreateInstance(renderStyle.TypeProfessionalColorTable) as BSE.Windows.Forms.ProfessionalColorTable;
                        if (professionalColorTable != null)
                        {
                            panelColors = professionalColorTable.PanelColorTable;
                        }
                    }

                    if (renderStyle.TypeToolStripProfessionalRenderer != null)
                    {
                        if (professionalColorTable != null)
                        {
                            toolStripRenderer = Activator.CreateInstance(renderStyle.TypeToolStripProfessionalRenderer, new object[] { professionalColorTable }) as ToolStripProfessionalRenderer;
                        }
                        else
                        {
                            toolStripRenderer =
                                Activator.CreateInstance(renderStyle.TypeToolStripProfessionalRenderer) as ToolStripProfessionalRenderer;
                        }
                        if (toolStripRenderer != null)
                        {
                            if (professionalColorTable == null)
                            {
                                professionalColorTable = toolStripRenderer.ColorTable as BSE.Windows.Forms.ProfessionalColorTable;
                                if (professionalColorTable != null)
                                {
                                    panelColors = professionalColorTable.PanelColorTable;
                                }
                            }
                        }
                    }
                    if ((panelColors != null)
                        && (professionalColorTable != null)
                        && toolStripRenderer != null)
                    {
                        this.PanelStyle = panelStyle;
                        this.PanelColors = panelColors;
                        this.ProfessionalColorTable = professionalColorTable;
                        toolStripRenderer.RoundedEdges = false;
                        ToolStripManager.Renderer = toolStripRenderer;
                    }
                }
            }
        }

        private void StatistikClick(object sender, EventArgs e)
        {
            Application.DoEvents();
            CTunesBusinessObject tunesBusinessObject
                = new CTunesBusinessObject(this.ConnectionString);
            try
            {
                DataSet dataSet = tunesBusinessObject.GetDataSetStatisticInformation();
                using (Statistics statistik = new Statistics(dataSet))
                {
                    statistik.ProfessionalColorTable = this.ProfessionalColorTable;
                    statistik.ShowDialog();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void HelpAboutClick(object sender, EventArgs e)
        {
            Application.DoEvents();
            BSE.Windows.Forms.About about = new BSE.Windows.Forms.About();
            about.BackgroundImage = BSE.Platten.Tunes.Properties.Resources.BSEAbout;
            about.AlternatingBackColor = BSE.Platten.Common.BSEColors.AlternatingBackColor;
            about.ClientSize = about.BackgroundImage.Size;
            about.ShowInTaskbar = false;
            about.ShowDialog();
        }

        private void HostAvailable(object sender, HostAvailableEventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            try
            {
                DatabaseHostAvailability databaseHostAvailability = e.DatabaseHostAvailability;
                if (databaseHostAvailability != null)
                {
                    if (databaseHostAvailability.IsAvailable == false)
                    {
                        //Alle Controls die Daten manipulieren k�nnen werden disabled
                        foreach (Control control in this.m_tscMain.Controls)
                        {
                            if (control.Contains(this.m_mnuMain) == true)
                            {
                                foreach (Control subControl in control.Controls)
                                {
                                    MenuStrip menuStrip = subControl as MenuStrip;
                                    if (menuStrip != null)
                                    {
                                        foreach (ToolStripItem toolStripItem in menuStrip.Items)
                                        {
                                            toolStripItem.Enabled = false;
                                            if (toolStripItem == this.m_mnuDatei)
                                            {
                                                toolStripItem.Enabled = true;
                                            }
                                            if (toolStripItem == this.m_mnuExtras)
                                            {
                                                toolStripItem.Enabled = true;
                                            }
                                            if (toolStripItem == this.m_mnuHelp)
                                            {
                                                toolStripItem.Enabled = true;
                                            }
                                        }
                                    }
                                }
                            }
                            else if (control.Contains(this.m_ssMain) == true)
                            {
                                foreach (Control subControl in control.Controls)
                                {
                                    StatusStrip statusStrip = subControl as StatusStrip;
                                    if (statusStrip != null)
                                    {
                                        statusStrip.Enabled = true;
                                    }
                                }
                            }
                            else
                            {
                                control.Enabled = false;
                            }
                        }
                        this.m_mnuExtras_Statistik.Enabled = false;
                    }
                    else
                    {
                        foreach (Control control in this.m_tscMain.Controls)
                        {
                            control.Enabled = true;
                            if (control.Contains(this.m_mnuMain) == true)
                            {
                                foreach (Control subControl in control.Controls)
                                {
                                    MenuStrip menuStrip = subControl as MenuStrip;
                                    if (menuStrip != null)
                                    {
                                        foreach (ToolStripItem toolStripItem in menuStrip.Items)
                                        {
                                            toolStripItem.Enabled = true;
                                        }
                                    }
                                }
                            }
                        }
                        StartRefreshControlsThread();
                    }
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
        
        private void BSEAdminClick(object sender, EventArgs e)
        {
            if (this.m_currentAlbum != null)
            {
                Application.DoEvents();
                try
                {
                    using (BSE.Platten.Admin.Admin admin
                        = new BSE.Platten.Admin.Admin(
                        this.m_configuration,
                        this.m_currentAlbum.AlbumId))
                    {
                        if (this.PanelColors != null)
                        {
                            admin.PanelStyle = this.PanelStyle;
                            admin.PanelColors = this.PanelColors;
                        }
                        admin.ProfessionalColorTable = this.ProfessionalColorTable;
                        
                        admin.ShowInTaskbar = false;
                        admin.ShowDialog(this);
                    }
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void m_mnuDatei_Beenden_Click(object sender, EventArgs e)
        {
            Application.DoEvents();
            this.Close();
        }
        
        private void FilterPropertiesClick(object sender, EventArgs e)
        {
            Application.DoEvents();
            try
            {
                using (BSE.Platten.Tunes.Filters.FilterMain filter
                    = new BSE.Platten.Tunes.Filters.FilterMain(this.m_environment))
                {
                    if (this.PanelColors != null)
                    {
                        filter.PanelStyle = this.PanelStyle;
                        filter.PanelColors = this.PanelColors;
                    }
                    filter.ProfessionalColorTable = this.ProfessionalColorTable;
                    
                    filter.FilterChanged -= new EventHandler<BSE.Platten.Tunes.Filters.FilterChangedEventArgs>(FilterChanged);
                    filter.FilterChanged += new EventHandler<BSE.Platten.Tunes.Filters.FilterChangedEventArgs>(FilterChanged);
                    filter.ShowDialog();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void FilterChanged(object sender, Filters.FilterChangedEventArgs e)
        {
            BSE.Platten.Tunes.Filters.FilterMain filter
                                   = new BSE.Platten.Tunes.Filters.FilterMain();
            try
            {
                BSE.Platten.Tunes.Filters.FilterConfiguration filterConfiguration
                    = filter.GetFilterConfiguration(this.m_environment);
                this.m_mnuFilter_Properties.Text = filterConfiguration.FilterName;
                this.TrackCollectionByFilterSettings = filter.GetTracksByFilterSettings(this.m_environment, (FilterSettings)filterConfiguration);

                //Wenn das Radio l�uft und der Filter ge�ndert wurde, werden die neuen Tracks dem PlayerManager �bergeben
                if (this.m_mnuMusik_Radio.Checked == true)
                {
                    this.m_playerManager.SetTracksToPlay(this.TrackCollectionByFilterSettings);
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void PlayListEditorClick(object sender, EventArgs e)
        {
            XPanderPanelList parentList = this.m_pnlPlayList.Parent as XPanderPanelList;
            if (parentList == null)
            {
                this.m_plstMain.XPanderPanels.Add(this.m_pnlPlayList);
                if (this.PanelColors != null)
                {
                    this.m_pnlPlayList.SetPanelProperties(this.PanelColors);
                }
            }
            this.m_mnuView_PlaylistEditor.Checked = false;
            if (this.m_pnlPlayList.Expand == false)
            {
                this.m_plstMain.Expand(this.m_pnlPlayList);
            }
        }
        
        private void SearchClick(object sender, EventArgs e)
        {
            XPanderPanelList parentList = this.m_pnlSearch.Parent as XPanderPanelList;
            if (parentList == null)
            {
                this.m_plstMain.XPanderPanels.Add(this.m_pnlSearch);
                if (this.PanelColors != null)
                {
                    this.m_pnlSearch.SetPanelProperties(this.PanelColors);
                }
            }
            this.m_mnuView_Search.Checked = true;
            if (this.m_pnlSearch.Expand == false)
            {
                this.m_plstMain.Expand(this.m_pnlSearch);
            }
        }
        
        private void ShowListClick(object sender, EventArgs e)
        {
            this.m_pnlRight.Visible = !this.m_pnlRight.Visible;
        }

        private void ListVisibilityChanged(object sender, EventArgs e)
        {
            this.m_mnuView_List.Checked = this.m_pnlRight.Visible;
        }

        private void ListCloseClick(object sender, EventArgs e)
        {
            this.m_pnlRight.Visible = false;
        }

        private void ViewRefreshClick(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                StartRefreshControlsThread();
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }

        private void SearchExecuting(object sender, SearchExecuteEventArgs e)
        {
            this.m_search.SetSearchTerm(e.SearchTerm);
            SearchClick(sender, e);
        }
        
        private void SearchExecuted(object sender, SearchExecuteEventArgs e)
        {
            this.m_tsSearch.SetSearchTerm(e.SearchTerm);
        }

        private void RemovableDriveChanges(object sender, BSE.RemovableDrives.DriveChangeEventArgs e)
        {
            BSE.RemovableDrives.RemovableDrive removableDrive = e.RemovableDrive;
            if (removableDrive != null)
            {
                bool bIsNotInPanelList = true;
                foreach (BSE.Windows.Forms.XPanderPanel xpanderPanel in this.m_plstMain.XPanderPanels)
                {
                    XPanderPanelAudioDrive xPanderPanelAudioDrive = xpanderPanel as XPanderPanelAudioDrive;
                    if (xPanderPanelAudioDrive != null)
                    {
                        if (removableDrive.Equals(xPanderPanelAudioDrive.AudioDrive) == true)
                        {
                            bIsNotInPanelList = false;
                        }
                    }
                }
                if (bIsNotInPanelList == true)
                {
                    XPanderPanelAudioDrive xpanderPanel = new XPanderPanelAudioDrive();
                    xpanderPanel.ToolTipTextCloseIcon = Resources.IDS_TooltipPanelClose;
                    xpanderPanel.ToolTipTextExpandIconPanelCollapsed = Resources.IDS_TooltipPanelMaximize;
                    xpanderPanel.AudioDrive = removableDrive;
                    xpanderPanel.Environment = this.m_environment;
                    xpanderPanel.Settings = this.m_settings;
                    this.m_plstMain.XPanderPanels.Add(xpanderPanel);
                    this.m_plstMain.Expand(xpanderPanel);
                }
            }
        }

        private void RemovableDriveRemoved(object sender, BSE.RemovableDrives.DriveChangeEventArgs e)
        {
            BSE.RemovableDrives.RemovableDrive removableDrive = e.RemovableDrive;
            if (removableDrive != null)
            {
                foreach (BSE.Windows.Forms.XPanderPanel xpanderPanel in this.m_plstMain.XPanderPanels)
                {
                    XPanderPanelAudioDrive xPanderPanelAudioDrive = xpanderPanel as XPanderPanelAudioDrive;
                    if (xPanderPanelAudioDrive != null)
                    {
                        if (removableDrive.Equals(xPanderPanelAudioDrive.AudioDrive) == true)
                        {
                            xPanderPanelAudioDrive.AudioDrive = null;
                        }
                    }
                }
            }
        }

        private void RemovableDriveAdded(object sender, BSE.RemovableDrives.DriveChangeEventArgs e)
        {
            BSE.RemovableDrives.RemovableDrive removableDrive = e.RemovableDrive;
            if (removableDrive != null)
            {
                foreach (BSE.Windows.Forms.XPanderPanel xpanderPanel in this.m_plstMain.XPanderPanels)
                {
                    XPanderPanelAudioDrive xPanderPanelAudioDrive = xpanderPanel as XPanderPanelAudioDrive;
                    if (xPanderPanelAudioDrive != null)
                    {
                        if (xPanderPanelAudioDrive.VolumeName.Equals(removableDrive.VolumeName) == true)
                        {
                            xPanderPanelAudioDrive.AudioDrive = removableDrive;
                        }
                    }
                }
            }
        }

        private void RadioClick(object sender, EventArgs e)
        {
            try
            {
                if (this.m_mnuMusik_Radio.Checked == false)
                {
                    if (this.TrackCollectionByFilterSettings != null)
                    {
                        this.m_playerManager.PlayTracks(this.TrackCollectionByFilterSettings, PlayMode.Random);
                        this.m_mnuMusik_Radio.Checked = this.m_btnMusic_Radio.Checked = true;
                    }
                }
                else
                {
                    StopPlayingRadio();
                }
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                StopPlayingRadio();
            }
        }

        private void StopPlayingRadio()
        {
            this.m_mnuMusik_Radio.Checked = this.m_btnMusic_Radio.Checked = false;
            this.m_btnMusic_CoverFlow.Enabled = this.m_mnuView_Coverflow.Enabled = false;
            this.m_playerManager.Stop();
        }

        private void PlayCDClick(object sender, EventArgs e)
        {
            StopPlayingRadio();
            if (this.m_currentAlbum != null && this.CurrentAlbum.Tracks != null)
            {
                CTrackCollection trackCollection = new CTrackCollection(this.CurrentAlbum.Tracks.Length);
                foreach (CTrack track in this.CurrentAlbum.Tracks)
                {
                    if (String.IsNullOrEmpty(track.FileFullName) == false)
                    {
                        trackCollection.Add(track);
                    }
                }
                if (trackCollection.Count > 0)
                {
                    try
                    {
                        this.m_playerManager.PlayTracks(trackCollection, BSE.Platten.Audio.PlayMode.CD);
                    }
                    catch (Exception exception)
                    {
                        GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        private void PlaySongClick(object sender, EventArgs e)
        {
            StopPlayingRadio();
            ToolStripMenuItem toolStripMenuItem = sender as ToolStripMenuItem;
            if (toolStripMenuItem != null)
            {
                CTrack track = toolStripMenuItem.Tag as CTrack;
                if (track != null)
                {
                    try
                    {
                        this.m_playerManager.PlayTrack(track, BSE.Platten.Audio.PlayMode.Song);
                    }
                    catch (Exception exception)
                    {
                        GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        private void CoverFlowClick(object sender, EventArgs e)
        {
            using (BSE.CoverFlow.WPFLib.WindowCoverFlow windowCoverFlow = new BSE.CoverFlow.WPFLib.WindowCoverFlow())
            {
                WindowInteropHelper windowInteropHelper = new WindowInteropHelper(windowCoverFlow);
                windowInteropHelper.Owner = this.Handle;
                windowCoverFlow.WindowState = System.Windows.WindowState.Maximized;
                windowCoverFlow.WindowStyle = System.Windows.WindowStyle.None;
                windowCoverFlow.ShowInTaskbar = false;
                windowCoverFlow.ConnectionString = this.ConnectionString;
                windowCoverFlow.PlayerManager = this.m_playerManager;

                try
                {
                    windowCoverFlow.LoadCovers();
                    windowCoverFlow.ShowDialog();
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private void GetCovers()
        {
            CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.ConnectionString);
            try
            {
                CAlbum[] albumsWithCovers = tunesBusinessObject.GetNewestAlbumsWithCovers(20);
                this.m_covers.LoadCoverBoxes(albumsWithCovers);
                this.m_covers.Invalidate();
            }
            catch (Exception exception)
            {
                GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void PlayerManagerPlayerPlays(object sender, BSE.Platten.Audio.PlayerManagerStatusChangedEventArgs e)
        {
            this.m_btnMusic_CoverFlow.Enabled = this.m_mnuView_Coverflow.Enabled = false;
            if ((this.m_playerManager.PlayMode == PlayMode.Playlist)
                || (this.m_playerManager.PlayMode == PlayMode.Random))
            {
                this.m_btnMusic_CoverFlow.Enabled = this.m_mnuView_Coverflow.Enabled = true;
            }
        }

        private void PlayerManagerTrackChanged(object sender, BSE.Platten.Audio.PlayerManagerStatusChangedEventArgs e)
        {
            this.m_ssMain.SetTickerText(e.CurrentTrack, e.PlayMode);
            this.m_history.UpdateHistory(e.CurrentTrack, e.