Click here to Skip to main content
15,861,168 members
Articles / Desktop Programming / Windows Forms

BSEtunes

Rate me:
Please Sign up or sign in to vote.
4.67/5 (11 votes)
24 Apr 2010CPOL4 min read 64.2K   4.3K   58  
BSEtunes is a MySQL based, full manageable, networkable single or multiuser jukebox application
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;

namespace BSE.Platten.Tunes.Filters
{
    public partial class FilterMain : BaseForm
    {
        #region Events

        public event EventHandler<FilterChangedEventArgs> FilterChanged;

        #endregion

        #region FieldsPrivate

        private CEnvironment m_environment;

        #endregion

        #region Properties

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

        #endregion

        #region MethodsPublic

        public FilterMain()
        {
            InitializeComponent();
        }

        public FilterMain(CEnvironment environment)
            : this()
        {
            this.m_environment = environment;
        }

        public FilterConfiguration GetFilterConfiguration(CEnvironment environment)
        {
            this.m_environment = environment;
            FilterConfiguration filterConfiguration = new FilterConfiguration();
            
            Type typeOfInterface = typeof(IFilterConfiguration);
            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
            Type[] types = assembly.GetTypes();
            foreach (Type type in types)
            {
                if (type.IsClass && typeOfInterface.IsAssignableFrom(type))
                {
                    FilterBase filterBase = Activator.CreateInstance(type) as FilterBase;
                    if (filterBase != null)
                    {
                        FilterConfiguration tmpFilterConfiguration =
                            filterBase.GetFilterConfiguration(environment);
                        if (tmpFilterConfiguration.IsUsed == true)
                        {
                            filterConfiguration = tmpFilterConfiguration;
                        }
                    }
                }
            }

            return filterConfiguration;
        }

        public BSE.Platten.BO.CTrackCollection GetTracksByFilterSettings(CEnvironment environment, FilterSettings filterSettings)
        {
            CTrackCollection trackCollection = null;
            try
            {
                CTunesBusinessObject tunesBusinessObject = new CTunesBusinessObject(environment.GetConnectionString());
                trackCollection = tunesBusinessObject.GetTracksByFilterSettings(filterSettings);
                if (trackCollection.Count > 0)
                {
                    string strAudioHomeDirectory = CAlbum.GetAudioHomeDirectory(this.m_environment);
                    System.Collections.IEnumerator enumerator = trackCollection.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        CTrack track = enumerator.Current as CTrack;
                        if (track != null)
                        {
                            track.FileFullName = strAudioHomeDirectory + track.FileName;
                        }
                    }
                }
            }
            catch (BSE.Configuration.CConfigurationValueNotFoundException)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
            return trackCollection;
        }

        #endregion

        #region MethodsProtected
        #endregion

        #region MethodsPrivate
        
        private void FilterMainLoad(object sender, EventArgs e)
        {
            if (this.m_environment != null)
            {
                TabControl.TabPageCollection tabPageCollection = this.m_tabFilters.TabPages;
                foreach (TabPage tabPage in tabPageCollection)
                {
                    Type typeOfInterface = typeof(IFilterConfiguration);
                    if (typeOfInterface.IsAssignableFrom(tabPage.Controls[0].GetType()))
                    {
                        FilterBase filterBase = tabPage.Controls[0] as FilterBase;
                        if (filterBase != null)
                        {
                            filterBase.SetFilterValues(this.m_environment);
                        }
                    }
                }
            }
        }
        
        private void FilterCheckStateChanged(object sender, FilterCheckStateChangeEventArgs e)
        {
            foreach (Control control in this.m_pnlUsingFilters.Controls)
            {
                CheckBox checkBox = control as CheckBox;
                if (checkBox != null)
                {
                    if (checkBox.Tag == e.CheckBox.Tag)
                    {
                        checkBox.Enabled = e.CheckState;
                        if (!checkBox.Enabled)
                        {
                            checkBox.Checked = checkBox.Enabled;
                        }
                    }
                }
            }
        }
        
        private void FilterAdded(object sender, FilterNotificationEventArgs e)
        {
            bool bCheckBoxAvailable = false;
            int iCheckBoxTop = 10;
            foreach (Control control in this.m_pnlUsingFilters.Controls)
            {
                CheckBox checkBox = control as CheckBox;
                if (checkBox != null)
                {
                    iCheckBoxTop = checkBox.Top + checkBox.Height;
                    if (checkBox.Tag == e.CheckBox.Tag)
                    {
                        bCheckBoxAvailable = false;
                    }
                }
            }
            if (bCheckBoxAvailable == false)
            {
                e.CheckBox.Left = 10;
                e.CheckBox.Top = iCheckBoxTop;
                e.CheckBox.Width = this.m_pnlUsingFilters.Width - e.CheckBox.Left;
                e.CheckBox.CheckedChanged += new System.EventHandler(this.UsingFiltersCheckedChanged);
                this.m_pnlUsingFilters.Controls.Add(e.CheckBox);
            }
        }
        
        private void UsingFiltersCheckedChanged(object sender, System.EventArgs e)
        {
            CheckBox checkBox = sender as CheckBox;
            if (checkBox != null)
            {
                if (checkBox.Checked)
                {
                    foreach (Control control in this.m_pnlUsingFilters.Controls)
                    {
                        CheckBox tmpCheckBox = control as CheckBox;
                        if (tmpCheckBox != null)
                        {
                            if (tmpCheckBox.Tag != checkBox.Tag)
                            {
                                tmpCheckBox.Checked = false;
                            }
                        }
                    }
                }
            }
        }
        
        private void BtnOKClick(object sender, EventArgs e)
        {
            foreach (Control control in this.m_pnlUsingFilters.Controls)
            {
                CheckBox checkBox = control as CheckBox;
                if (checkBox != null)
                {
                    TabControl.TabPageCollection tabPageCollection = this.m_tabFilters.TabPages;
                    foreach (TabPage tabPage in tabPageCollection)
                    {
                        if (tabPage.Controls[0].GetType() == checkBox.Tag)
                        {
                            FilterBase filterBase = tabPage.Controls[0] as FilterBase;
                            if (filterBase != null)
                            {
                                filterBase.SafeFilterConfiguration(this.m_environment, checkBox.Checked);
                            }
                        }
                    }
                }
            }
            if (FilterChanged != null)
            {
                FilterChanged(this,new FilterChangedEventArgs());
            }
        }

        #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)


Written By
Switzerland Switzerland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions