Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version
Go to top

BSEtunes

, 24 Apr 2010
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
BSE.Platten.zip
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
Settings.settings
vssver2.scc
Resources
vssver2.scc
BSE.Platten.Admin
BSE.Platten.Admin.csproj.vspscc
mssccprj.scc
vssver2.scc
Properties
Settings.settings
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
Settings.settings
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
Settings.settings
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
Settings.settings
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.Platten_en.zip
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
Settings.settings
vssver2.scc
vssver2.scc
BSE.Platten.Admin.csproj.user
Settings.settings
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
Settings.settings
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
Settings.settings
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
Settings.settings
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.zip
MySQL.chm
MySqlCreateDataBase5x.sql.zip
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

using BSE.Platten.BO;
using BSE.Platten.Audio;
using BSE.Platten.Common;
using System.Globalization;
using BSE.Platten.Tunes.Properties;

namespace BSE.Platten.Tunes
{
    public partial class PlayList : UserControl
    {
        #region Constants

        private const string m_strParentControlCaption = "Wiedergabeliste: ";
        private const string m_strEmptyPlayList = "keine Playliste ausgew�hlt";

        #endregion

        #region Enums

        public enum PlayListDragDropMode
        {
            Albums,
            PlayList
        }

        #endregion

        #region EventsPublic

        public event EventHandler<PlayListEventArgs> PlayListInserted;
        public event EventHandler<PlayListEventArgs> PlayListChanged;
        public event EventHandler<PlayListEventArgs> PlayListDeleted;
        public event EventHandler<AlbumSelectEventArgs> AlbumSelecting;

        #endregion
        
        #region FieldsPrivate

        private BSE.Platten.BO.Environment m_environment;
        private CPlaylist m_currentPlayList;
        private CTrack m_selectedTrack;
        private ToolStripMenuItem m_parentToolStripMenuItem;
        private Control m_parentControl;
        private bool m_bPlayListHasChanged;

        #endregion
        
        #region Properties

        public CPlayerManager PlayerManager
        {
            get { return this.m_playerManager; }
            set
            {
                this.m_playerManager = value;
                this.m_lstvPlayList.PlayerManager = this.m_playerManager;
            }
        }

        public BSE.Configuration.Configuration Settings
        {
            get { return this.m_settings; }
            set { this.m_settings = value; }
        }

        public BSE.Platten.BO.Environment Environment
        {
            get { return this.m_environment; }
            set { this.m_environment = value; }
        }

        public ToolStripMenuItem ParentToolStripMenuItem
        {
            get { return this.m_parentToolStripMenuItem; }
            set { this.m_parentToolStripMenuItem = value; }
        }

        #endregion

        #region MethodsPublic

        public PlayList()
        {
            InitializeComponent();
            this.m_lstvPlayList.AlternatingBackColor = BSE.Platten.Common.BSEColors.AlternatingBackColor;
            UpdateViewState();
        }

        public void SetPlaylist(int iPlayListId)
        {
            SetCurrentPlayList(iPlayListId);
        }

        public void SetNewPlayList()
        {
            NewPlaylist();
        }

        public void SetDeletePlayList()
        {
            DeletePlaylist();
        }

        public void SetPlayTracks()
        {
            if (this.m_lstvPlayList.Items.Count == 0)
            {
                string strMessage = String.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.IDS_PlayListEmptyException,
                    this.m_currentPlayList.Name);
                GlobalizedMessageBox.Show(this, strMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            PlayTracks(BSE.Platten.Audio.PlayMode.Playlist);
        }

        public void SetPlayRandomTracks()
        {
            if (this.m_lstvPlayList.Items.Count == 0)
            {
                string strMessage = String.Format(
                    CultureInfo.CurrentUICulture,
                    Resources.IDS_PlayListEmptyException,
                    this.m_currentPlayList.Name);
                GlobalizedMessageBox.Show(this,strMessage, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            PlayTracks(BSE.Platten.Audio.PlayMode.Random);
        }

        #endregion

        #region MethodsProtected

        protected void OnPlayListInserted(PlayListEventArgs e)
        {
            if (PlayListInserted != null)
            {
                PlayListInserted(this, e);
            }
        }

        protected void OnPlayListDeleted(PlayListEventArgs e)
        {
            if (PlayListDeleted != null)
            {
                PlayListDeleted(this, e);
            }
        }

        protected void OnPlayListChanged(PlayListEventArgs e)
        {
            if (PlayListChanged != null)
            {
                PlayListChanged(this, e);
            }
        }

        protected void OnAlbumSelecting(AlbumSelectEventArgs e)
        {
            if (AlbumSelecting != null)
            {
                AlbumSelecting(this, e);
            }
        }

        #endregion

        #region MethodsPrivate
        
        private void PlayListLoad(object sender, EventArgs e)
        {
            Form parentForm = this.FindForm();
            if (parentForm != null)
            {
                parentForm.FormClosing += new FormClosingEventHandler(PlayListFormClosing);
                LoadSettings();
            }
            this.m_parentControl = this.Parent;
            if (m_parentControl != null)
            {
                m_parentControl.Text = string.Format(CultureInfo.CurrentUICulture,"{0} {1}", Resources.IDS_PlayListCaptionbarText, Resources.IDS_PlayListCaptionbarTextNoPlaylistSelected);
                m_parentControl.VisibleChanged += new EventHandler(PlayListVisibleChanged);
            }
        }

        private void PlayListFormClosing(object sender, FormClosingEventArgs e)
        {
            SaveSettings();
        }
        
        private void PlayListVisibleChanged(object sender, EventArgs e)
        {
            if (this.m_parentToolStripMenuItem != null)
            {
                this.m_parentToolStripMenuItem.Checked = this.Visible;
            }
        }
        
        private void PlayListMouseUp(object sender, MouseEventArgs e)
        {
           if (e.Button == MouseButtons.Right)
            {
                if (this.m_lstvPlayList.SelectedItems.Count > 0)
                {
                    ListViewItem listViewItem = this.m_lstvPlayList.SelectedItems[0];
                    if (listViewItem != null)
                    {
                        this.m_selectedTrack = (CTrack)listViewItem.Tag;
                        this.m_ctxPlayList.Show(this.m_lstvPlayList, new Point(e.X, e.Y));
                    }
                    
                }
            }
        }
        
        private void PlayListKeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                foreach (ListViewItem listViewItem in this.m_lstvPlayList.SelectedItems)
                {
                    this.m_lstvPlayList.Items.Remove(listViewItem);
                    this.m_bPlayListHasChanged = true;
                }
                UpdateViewState();
            }
            if (e.KeyCode == Keys.T && e.Modifiers == Keys.Control)
            {
                if (this.m_lstvPlayList.SelectedItems.Count > 0)
                {
                    ListViewItem listViewItem = this.m_lstvPlayList.SelectedItems[0];
                    if (listViewItem != null)
                    {
                        this.m_selectedTrack = (CTrack)listViewItem.Tag;
                        SelectAlbumClick(sender, e);
                    }
                }
            }
        }
        
        private void NewPlayListClick(object sender, EventArgs e)
        {
            NewPlaylist();
        }
        
        private void SavePlayListClick(object sender, EventArgs e)
        {
            SavePlaylist();
        }

        private void DeletePlayListClick(object sender, EventArgs e)
        {
            DeletePlaylist();
        }
        
        private void PlayTracksClick(object sender, EventArgs e)
        {
            PlayTracks(BSE.Platten.Audio.PlayMode.Playlist);
        }

        private void PlaySelectedTracksClick(object sender, EventArgs e)
        {
            PlaySelectedTracks(BSE.Platten.Audio.PlayMode.Playlist);
        }
        private void PlayRandomClick(object sender, EventArgs e)
        {
            PlayTracks(BSE.Platten.Audio.PlayMode.Random);
        }
        
        private void SelectAlbumClick(object sender, EventArgs e)
        {
            OnAlbumSelecting(new AlbumSelectEventArgs(this.m_selectedTrack.TitelId));
        }

        private void NewPlayListInserted(object sender, PlayListEventArgs e)
        {
            if (e.PlayList != null)
            {
                this.m_lstvPlayList.Items.Clear();
                this.m_currentPlayList = e.PlayList;
                
                if (this.m_parentControl != null)
                {
                    this.m_parentControl.Text = string.Format(
                        CultureInfo.CurrentUICulture,
                        "{0} {1}",
                        Resources.IDS_PlayListCaptionbarText,
                        Resources.IDS_PlayListCaptionbarTextNoPlaylistSelected, this.m_currentPlayList.Name);
                    this.m_parentControl.Refresh();
                }
                UpdateViewState();
                OnPlayListInserted(new PlayListEventArgs(this.m_currentPlayList));
            }
        }

        private void SetCurrentPlayList(int iPlayListId)
        {
            this.m_lstvPlayList.Items.Clear();
            Cursor.Current = Cursors.WaitCursor;
            if (this.m_environment != null)
            {
                CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.m_environment.GetConnectionString());
                try
                {
                    this.m_currentPlayList = tunesBusinessObject.GetPlayListByPlayListId(iPlayListId);
                    if (this.m_currentPlayList != null)
                    {
                        CTrack[] tracks = m_currentPlayList.Tracks;
                        if (tracks != null)
                        {
                            string strAudioHomeDirectory = CAlbum.GetAudioHomeDirectory(this.m_environment);

                            foreach (CTrack track in tracks)
                            {
                                track.FileFullName = strAudioHomeDirectory + track.FileName;
                                ListViewItem listViewItem = CreateListViewItem(track);
                                if (listViewItem != null)
                                {
                                    this.m_lstvPlayList.Items.Add(listViewItem);
                                }
                            }
                        }
                        if (this.m_parentControl != null)
                        {
                            this.m_parentControl.Text = string.Format(
                                CultureInfo.CurrentUICulture,
                                "{0} {1}",
                                Resources.IDS_PlayListCaptionbarText,
                                this.m_currentPlayList.Name);
                        }
                        OnPlayListChanged(new PlayListEventArgs(this.m_currentPlayList));
                    }
                }
                catch (Exception exception)
                {
                    string strMessage = string.Format(
                        CultureInfo.CurrentUICulture,
                        "{0} {1}",
                        Resources.IDS_PlayListLoadException + exception.Message);
                    GlobalizedMessageBox.Show(this,strMessage, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    UpdateViewState();
                }
            }
            Cursor.Current = Cursors.Default;
        }

        private void NewPlaylist()
        {
            if (this.m_environment != null)
            {
                using (NewPlayList newPlaylist = new NewPlayList(this.m_environment))
                {
                    newPlaylist.PlayListInserted -= new EventHandler<PlayListEventArgs>(NewPlayListInserted);
                    newPlaylist.PlayListInserted += new EventHandler<PlayListEventArgs>(NewPlayListInserted);
                    newPlaylist.ShowDialog();
                }
            }
        }

        private void SavePlaylist()
        {
            Cursor.Current = Cursors.WaitCursor;
            if (this.m_bPlayListHasChanged)
            {
                System.Collections.ArrayList aPlaylistEntries = new System.Collections.ArrayList();
                CPlayListEntries[] playListEntries = null;
                foreach (ListViewItem listViewItem in this.m_lstvPlayList.Items)
                {
                    CTrack track = listViewItem.Tag as CTrack;
                    if (track != null)
                    {
                        CPlayListEntries playListEntry = new CPlayListEntries();
                        playListEntry.Guid = System.Guid.NewGuid();
                        playListEntry.EntryId = -1;
                        playListEntry.LiedId = track.LiedId;
                        playListEntry.PlayListId = this.m_currentPlayList.Id;
                        
                        aPlaylistEntries.Add(playListEntry);
                    }

                    CPlayListEntries tmpPlayListEntry = listViewItem.Tag as CPlayListEntries;
                    if (tmpPlayListEntry != null)
                    {
                        aPlaylistEntries.Add(tmpPlayListEntry);
                    }
                    
                }
                playListEntries = new CPlayListEntries[aPlaylistEntries.Count];
                aPlaylistEntries.CopyTo(playListEntries);
                this.m_currentPlayList.PlayListEntries = playListEntries;

                CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.m_environment.GetConnectionString());
                try
                {
                    tunesBusinessObject.SavePlayList(this.m_currentPlayList);
                }
                catch (Exception exception)
                {
                    string strMessage = string.Format(
                        CultureInfo.CurrentUICulture,
                        "{0} {1}",
                        Resources.IDS_PlayListSaveException, exception.Message);
                    GlobalizedMessageBox.Show(this,strMessage, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                finally
                {
                    UpdateViewState();
                    Cursor.Current = Cursors.Default;
                }
            }
        }

        private void DeletePlaylist()
        {
            string strPlaylistName = this.m_currentPlayList.Name;
            string strWarning = string.Format(CultureInfo.CurrentUICulture,Resources.IDS_PlayListDeleteWarningException, strPlaylistName);

            DialogResult dialogResult = GlobalizedMessageBox.Show(
                this,strWarning
                , MessageBoxButtons.YesNo
                , MessageBoxIcon.Warning);

            if (dialogResult == DialogResult.Yes)
            {
                if (this.m_environment != null)
                {
                    CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.m_environment.GetConnectionString());
                    try
                    {
                        tunesBusinessObject.DeletePlayList(this.m_currentPlayList.Id);
                    }
                    catch (Exception exception)
                    {
                        string strMessage = string.Format(
                            CultureInfo.CurrentUICulture,
                            "{0} {1}", Resources.IDS_PlayListDeleteException, exception.Message); 
                        GlobalizedMessageBox.Show(this, strMessage, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    this.m_lstvPlayList.Items.Clear();
                    this.m_currentPlayList = null;
                    if (this.m_parentControl != null)
                    {
                        this.m_parentControl.Text = string.Format(
                            CultureInfo.CurrentUICulture,
                            "{0} {1}",
                            Resources.IDS_PlayListCaptionbarText,
                            Resources.IDS_PlayListCaptionbarTextNoPlaylistSelected);
                        this.m_parentControl.Refresh();
                    }
                    UpdateViewState();
                    this.OnPlayListDeleted(new PlayListEventArgs(this.m_currentPlayList));
                }
            }
        }

        private void PlayListDragDrop(object sender, DragEventArgs e)
        {
            if (e.Data is BSE.Windows.Forms.CDataObject)
            {
                // get the currently hovered row that the items will be dragged to
                Point clientPoint = this.m_lstvPlayList.PointToClient(new Point(e.X, e.Y));
                ListViewItem hoverListViewItem = this.m_lstvPlayList.GetItemAt(clientPoint.X, clientPoint.Y);

                //Get the dataobject
                BSE.Windows.Forms.CDataObject dataObject = (BSE.Windows.Forms.CDataObject)e.Data;

                BSE.Windows.Forms.CDraggedListViewObjects draggedListViewObjects = null;
                //check the overload of the dataobject
                if (dataObject.GetDataPresent(typeof(BSE.Windows.Forms.CDraggedListViewObjects).ToString()))
                {
                    draggedListViewObjects
                        = (BSE.Windows.Forms.CDraggedListViewObjects)dataObject.GetData(
                        typeof(BSE.Windows.Forms.CDraggedListViewObjects).ToString());
                    if (draggedListViewObjects.ParentListView == null)
                    {
                        return;
                    }
                }
                if (dataObject.DragData != null)
                {
                    draggedListViewObjects
                        = (BSE.Windows.Forms.CDraggedListViewObjects)dataObject.DragData;

                    if (draggedListViewObjects.ParentListView == null)
                    {
                        return;
                    }
                }
                if (draggedListViewObjects != null)
                {
                    object dragObject = draggedListViewObjects.DragObjects[0];

                    //Wenn das Object vom Typ ListViewItem ist werden die ListViewItems in die ListView eingef�gt
                    if (dragObject.GetType() == typeof(System.Windows.Forms.ListViewItem))
                    {
                        InsertListViewItems(hoverListViewItem, draggedListViewObjects);
                    }
                    if (dragObject.GetType() == typeof(PlayListDragDropData))
                    {
                        PlayListDragDropData playListDragDropData = (PlayListDragDropData)dragObject;
                        if (playListDragDropData.PlayListDragDropMode == PlayListDragDropMode.Albums)
                        {
                            InsertListViewItemsAlbum(hoverListViewItem, playListDragDropData.Id);
                        }
                    }
                }
                this.m_bPlayListHasChanged = true;
                UpdateViewState();
                
            }
        }
        
        private void PlayTracks(BSE.Platten.Audio.PlayMode eMode)
        {
            CTrackCollection tracksCollection = new CTrackCollection(this.m_lstvPlayList.Items.Count);
            foreach (ListViewItem listViewItem in this.m_lstvPlayList.Items)
            {
                CTrack track = listViewItem.Tag as CTrack;
                if (track != null)
                {
                    tracksCollection.Add(track);
                }
            }
            if (tracksCollection.Count > 0)
            {
                if (this.m_playerManager != null)
                {
                    try
                    {
                        this.m_playerManager.PlayTracks(tracksCollection, eMode);
                    }
                    catch (Exception exception)
                    {
                        GlobalizedMessageBox.Show(this,exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        private void PlaySelectedTracks(BSE.Platten.Audio.PlayMode eMode)
        {
            CTrackCollection tracksCollection = new CTrackCollection(this.m_lstvPlayList.SelectedItems.Count);
            foreach (ListViewItem listViewItem in this.m_lstvPlayList.SelectedItems)
            {
                CTrack track = listViewItem.Tag as CTrack;
                if (track != null)
                {
                    tracksCollection.Add(track);
                }
            }
            if (tracksCollection.Count > 0)
            {
                if (this.m_playerManager != null)
                {
                    try
                    {
                        this.m_playerManager.PlayTracks(tracksCollection, eMode);
                    }
                    catch (Exception exception)
                    {
                        GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }

        private void InsertListViewItems(ListViewItem hoverListViewItem, BSE.Windows.Forms.CDraggedListViewObjects draggedListViewObjects)
        {
            if (hoverListViewItem == null)
            {
                for (int i = 0; i < draggedListViewObjects.DragObjects.Count; i++)
                {
                    if (this.m_lstvPlayList == draggedListViewObjects.ParentListView)
                    {
                        draggedListViewObjects.ParentListView.DragDropEffects = DragDropEffects.Move;
                    }
                    ListViewItem draggedListViewItem = (ListViewItem)draggedListViewObjects.DragObjects[i];
                    if (draggedListViewItem.Tag is CTrack)
                    {
                        CTrack track = draggedListViewItem.Tag as CTrack;
                        if (track != null)
                        {
                            ListViewItem listViewItem = CreateListViewItem(track);
                            if (listViewItem != null)
                            {
                                this.m_lstvPlayList.Items.Add(listViewItem);
                            }
                        }
                    }
                }
            }
            else
            {
                int iHoverIndex = hoverListViewItem.Index;
                if (this.m_lstvPlayList == draggedListViewObjects.ParentListView)
                {
                    draggedListViewObjects.ParentListView.DragDropEffects = DragDropEffects.Move;
                }
                for (int i = draggedListViewObjects.DragObjects.Count - 1; i >= 0; i--)
                {
                    ListViewItem draggedListViewItem = (ListViewItem)draggedListViewObjects.DragObjects[i];
                    if (draggedListViewItem.Tag is CTrack)
                    {
                        CTrack track = draggedListViewItem.Tag as CTrack;
                        if (track != null)
                        {
                            ListViewItem listViewItem = CreateListViewItem(track);
                            if (listViewItem != null)
                            {
                                this.m_lstvPlayList.Items.Insert(iHoverIndex, listViewItem);
                            }
                        }
                    }
                }
            }

            if (draggedListViewObjects.ParentListView != null)
            {
                if (draggedListViewObjects.ParentListView.DragDropEffects == DragDropEffects.Move)
                {
                    foreach (ListViewItem listViewItemToRemove in draggedListViewObjects.ParentListView.SelectedItems)
                    {
                        draggedListViewObjects.ParentListView.Items.Remove(listViewItemToRemove);
                    }
                }
            }
        }

        private void InsertListViewItemsAlbum(ListViewItem hoverListViewItem, int iAlbumId)
        {
            if (this.m_environment != null)
            {
                CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(this.m_environment.GetConnectionString());
                try
                {
                    CTrack[] tracks = tunesBusinessObject.GetAlbumTracksForPlayListByTitelId(iAlbumId);
                    if (tracks != null)
                    {
                        string strAudioHomeDirectory = CAlbum.GetAudioHomeDirectory(this.m_environment);
                        if (hoverListViewItem == null)
                        {
                            foreach (BSE.Platten.BO.CTrack track in tracks)
                            {
                                track.FileFullName = strAudioHomeDirectory + track.FileName;
                                ListViewItem listViewItem = CreateListViewItem(track);
                                if (listViewItem != null)
                                {
                                    this.m_lstvPlayList.Items.Add(listViewItem);
                                }
                            }
                        }
                        else
                        {
                            int iHoverIndex = hoverListViewItem.Index;
                            for (int i = tracks.Length - 1; i >= 0; i--)
                            {
                                CTrack track = tracks[i];
                                if (track != null)
                                {
                                    track.FileFullName = strAudioHomeDirectory + track.FileName;
                                    ListViewItem listViewItem = CreateListViewItem(tracks[i]);
                                    if (listViewItem != null)
                                    {
                                        this.m_lstvPlayList.Items.Insert(iHoverIndex, listViewItem);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this,exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }

        private static ListViewItem CreateListViewItem(CTrack track)
        {
            ListViewItem listViewItem = null;
            if (track != null)
            {
                listViewItem = new ListViewItem();
                listViewItem.Text = track.Title;
                listViewItem.SubItems.Add(track.Album);
                listViewItem.SubItems.Add(track.Interpret);
                listViewItem.SubItems.Add(track.Duration.ToString());
                listViewItem.SubItems.Add(track.Genre);
                listViewItem.SubItems.Add(track.Year.ToString(CultureInfo.InvariantCulture));
                listViewItem.SubItems.Add(track.FileFullName);
                listViewItem.Tag = track;
            }
            return listViewItem;
        }

        private void UpdateViewState()
        {
            if (this.m_currentPlayList != null)
            {
                this.m_btnSave.Enabled = true;
                this.m_btnDelete.Enabled = true;
            }
            else
            {
                this.m_btnSave.Enabled = false;
                this.m_btnDelete.Enabled = false;
            }
            if (this.m_lstvPlayList.Items.Count > 0)
            {
                this.m_btnPlay.Enabled = true;
            }
            else
            {
                this.m_btnPlay.Enabled = false;
            }
        }

        private void LoadSettings()
        {
            if (this.m_settings != null)
            {
                PlayListSettingsData playListSettingsData = new PlayListSettingsData();
                playListSettingsData = playListSettingsData.LoadSettings(this, this.m_settings, playListSettingsData) as PlayListSettingsData;
                if (playListSettingsData != null)
                {
                    //-------------------------------------------------------------------------------
                    // Spaltenbreiten f�r die PlayList ListView neu setzen.
                    //-------------------------------------------------------------------------------
                    int iSizeLvwPlayList = this.m_lstvPlayList.Columns.Count;
                    int[] columnWidthsLvwPlayList = playListSettingsData.ColumnWidthsLvwPlayList;
                    if (columnWidthsLvwPlayList != null)
                    {
                        int iSizeIntArray = columnWidthsLvwPlayList.Length;
                        for (int i = 0; i < iSizeLvwPlayList; ++i)
                        {
                            if (i < iSizeIntArray)
                            {
                                this.m_lstvPlayList.Columns[i].Width = columnWidthsLvwPlayList[i];
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }

        private void SaveSettings()
        {
            if (this.m_settings != null)
            {
                PlayListSettingsData playListSettingsData = new PlayListSettingsData();
                //-------------------------------------------------------------------------------
                // Spaltenbreiten f�r die PlayList ListView speichern.
                //-------------------------------------------------------------------------------
                int iSizeLvwPlayList = this.m_lstvPlayList.Columns.Count;
                int[] columnWidthsLvwPlayList = new int[iSizeLvwPlayList];
                for (int i = 0; i < iSizeLvwPlayList; ++i)
                {
                    columnWidthsLvwPlayList[i] = this.m_lstvPlayList.Columns[i].Width;
                }
                playListSettingsData.ColumnWidthsLvwPlayList = columnWidthsLvwPlayList;
                playListSettingsData.SaveSettings(this, this.m_settings, playListSettingsData);
            }
        }

        #endregion
    }
    
    public class PlayListSettingsData : BaseControlSettingsData
    {
        #region Fields
        /// <summary>
        /// Spaltenbreiten f�r die PlayList ListView
        /// </summary>
        private int[] m_iarColumnWidthsLvwPlayList;
        #endregion

        #region Properties
        /// <summary>
        /// Spaltenbreiten f�r die PlayList ListView
        /// </summary>
        public int[] ColumnWidthsLvwPlayList
        {
            get { return this.m_iarColumnWidthsLvwPlayList; }
            set { this.m_iarColumnWidthsLvwPlayList = value; }
        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Uwe Eichkorn

Switzerland Switzerland
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 24 Apr 2010
Article Copyright 2009 by Uwe Eichkorn
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid