Click here to Skip to main content
15,885,244 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.6K   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 System.Management;

using BSE.Platten.BO;
using System.Globalization;
using BSE.Platten.Common;
using BSE.Platten.Admin.Properties;

namespace BSE.Platten.Admin
{
    public partial class DiskInfo : BSE.Platten.Admin.BaseForm
    {
        #region Konstanten

        private const long GIGABYTE = 1073741824;
        private Color m_colorUsedSpace = Color.Blue;
        private Color m_colorFreeSpace = Color.Magenta;

        #endregion
        
        #region FieldsPrivate

        BSE.Platten.BO.Environment m_environment;

        #endregion

        #region MethodsPublic
        public DiskInfo()
        {
            InitializeComponent();
            this.m_picUsedSpace.BackColor = m_colorUsedSpace;
            this.m_picFreeSpace.BackColor = m_colorFreeSpace;
            this.m_btnCancel.Left = (this.Width - this.m_btnCancel.Width) / 2;
        }
        public DiskInfo(BSE.Platten.BO.Environment environment) : this()
        {
            this.m_environment = environment;
        }
        #endregion
        
        #region MethodsPrivate
        private void CDiskInfo_Load(object sender, EventArgs e)
        {
            if (this.m_environment != null)
            {
                try
                {
                    string strAudioHomeDirectory = this.m_environment.GetAudioHomeDirectory();
                    this.m_grpDiskInfo.Text += " " + strAudioHomeDirectory;
                    if (strAudioHomeDirectory.StartsWith(System.IO.Path.DirectorySeparatorChar.ToString() +
                        System.IO.Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase) == true)
                    {
                        string strException = String.Format(CultureInfo.CurrentUICulture,Resources.IDS_NetworkShareException);

                        GlobalizedMessageBox.Show(this, strException, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        
                        this.m_lblUsedSpaceBytes.Text = String.Format(CultureInfo.CurrentUICulture,"{0} Bytes", 0);
                        this.m_lblUsedSpaceGBytes.Text = String.Format(CultureInfo.CurrentUICulture, "{0} GB", 0);
                        this.m_lblFreeSpaceBytes.Text = String.Format(CultureInfo.CurrentUICulture, "{0} Bytes", 0);
                        this.m_lblFreeSpaceGBytes.Text = String.Format(CultureInfo.CurrentUICulture, "{0} GB", 0);
                        
                    }
                    else
                    {
                        GetDiskInfo(strAudioHomeDirectory);
                    }
                }
                catch (BSE.Configuration.ConfigurationValueNotFoundException configurationValueNotFoundException)
                {
                    GlobalizedMessageBox.Show(this, configurationValueNotFoundException.Message, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.Close();
                }
                catch (Exception exception)
                {
                    GlobalizedMessageBox.Show(this, exception.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                }
            }
        }

        private void GetDiskInfo(string strDrive)
        {
            if (strDrive.StartsWith(System.IO.Path.DirectorySeparatorChar.ToString() +
                System.IO.Path.DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase) == false)
            {
                strDrive = strDrive.Substring(0, strDrive.IndexOf("\\", StringComparison.OrdinalIgnoreCase));
                using (ManagementObject managementObject = new ManagementObject("Win32_LogicalDisk.DeviceID=\"" + strDrive + "\""))
                {

                    long lFreeSpace = (long)Convert.ToUInt64(managementObject.Properties["FreeSpace"].Value,CultureInfo.InvariantCulture);
                    long lSize = (long)Convert.ToUInt64(managementObject.Properties["Size"].Value,CultureInfo.InvariantCulture);
                    long lUsedSpace = lSize - lFreeSpace;

                    double dUsedSpace = (double)lUsedSpace / GIGABYTE;
                    double dFreeSpace = (double)lFreeSpace / GIGABYTE;

                    Charts.ChartItem itemUsedSpace = new BSE.Charts.ChartItem();
                    itemUsedSpace.Color = m_colorUsedSpace;
                    itemUsedSpace.Value = (float)dUsedSpace;
                    this.m_chrtDiskInfo.ChartItems.Add(itemUsedSpace);

                    Charts.ChartItem itemFreeSpace = new BSE.Charts.ChartItem();
                    itemFreeSpace.Color = m_colorFreeSpace;
                    itemFreeSpace.Value = (float)dFreeSpace;
                    this.m_chrtDiskInfo.ChartItems.Add(itemFreeSpace);

                    this.m_lblUsedSpaceBytes.Text = String.Format(CultureInfo.InvariantCulture, "{0} Bytes", lUsedSpace.ToString("N0",CultureInfo.InvariantCulture));
                    this.m_lblUsedSpaceGBytes.Text = String.Format(CultureInfo.InvariantCulture, "{0} GB", dUsedSpace.ToString("N", CultureInfo.InvariantCulture));
                    this.m_lblFreeSpaceBytes.Text = String.Format(CultureInfo.InvariantCulture, "{0} Bytes", lFreeSpace.ToString("N0", CultureInfo.InvariantCulture));
                    this.m_lblFreeSpaceGBytes.Text = String.Format(CultureInfo.InvariantCulture, "{0} GB", dFreeSpace.ToString("N", CultureInfo.InvariantCulture));
                }
            }
        }
        #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