/// <summary>
        /// Adds a new ChargeList to the storage list. If a ChargeList with the
        /// same date as an existing ChargeList is found the two will be 
        /// merged. 
        /// </summary>
        /// <param name="cl"></param>
        public void AddNewChargeList(ChargeList cl)
        {
            // Look for an existing tune list with the same
            // date as the one being passed in. If one exists
            // we add the data to the existing tune list.
            // !!!! Note that if someone has already marked the list charged and adds new values then they probably won't get charged, human error, blah blah not interested in fixing that right now
            // Could maybe just mark which items have been charged, new ones will show as uncharged, get rid of big label that says charged/not charged?
            for (int i = 0; i < mChargeLists.Count; ++i)
            {
                if (mChargeLists[i].GetDate().Date == cl.GetDate().Date)
                {
                    mChargeLists[i].MergeChargeLists(cl);
                    return;
                }
            }

            mChargeLists.Add(cl);
        }
        /// <summary>
        /// Builds a ChargeList from a collection for data rows from a 
        /// TuneList. 
        /// </summary>
        /// <param name="tl">TuneList to build from</param>
        /// <returns>Newly created ChargeList</returns>
        public ChargeList BuildChargeList(TuneList tl)
        {
            ChargeList cl = new ChargeList();
            DataGridViewRowCollection tuneRows = tl.GetAllTuneRows();

            foreach (DataGridViewRow row in tuneRows)
            {
                string noteCell = row.Cells["colNotes"].Value.ToString();
                if (noteCell != string.Empty)
                {
                    cl.AddTune(row.Cells["colTuneType"].Value.ToString(), row.Cells["colAssetNumber"].Value.ToString() + ": " + noteCell);
                }
                else
                {
                    cl.AddTune(row.Cells["colTuneType"].Value.ToString(), string.Empty);
                }
            }

            return cl;
        }
        /// <summary>
        /// Reads in all stored ChargeLists on disk and stores them in the 
        /// managers internal storage list. 
        /// </summary>
        public void LoadChargeLists()
        {
            try
            {   // Open the text file using a stream reader.
                using (StreamReader sr = new StreamReader("chargelists.txt", false))
                {
                    while (!sr.EndOfStream)
                    {
                        string dateString = sr.ReadLine();
                        DateTime date = DateTime.ParseExact(dateString, CultureHelper.GetInstance().GetDefaultDateFormatString(), null);

                        bool charged = Boolean.Parse(sr.ReadLine());

                        List<ChargeList.TuneRecord> tuneRecords = new List<ChargeList.TuneRecord>();

                        string line;
                        while ((line = sr.ReadLine()) != string.Empty)
                        {
                            string tuneLine = line;
                            string tuneType = tuneLine.Substring(0, tuneLine.LastIndexOf(" "));
                            string tuneCount = tuneLine.Substring(tuneLine.LastIndexOf(" ") + 1, tuneLine.Length - tuneLine.LastIndexOf(" ") - 1);

                            ChargeList.TuneRecord tr = new ChargeList.TuneRecord();
                            tr.mTuneType = tuneType;
                            tr.mCount = Int32.Parse(tuneCount);

                            tuneRecords.Add(tr);
                        }

                        List<string> notes = new List<string>();
                        while ((line = sr.ReadLine()) != string.Empty)
                        {
                            notes.Add(line);
                        }

                        ChargeList cl = new ChargeList(date, charged, tuneRecords, notes);
                        ChargeListManager.GetInstance().AddNewChargeList(cl);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }
        /// <summary>
        /// Merges two charge lists. For each tune type matching in both the
        /// charge lists the number of tunes are summed. For any tune type not
        /// found in both lists a new tune record is added to the one Charge 
        /// List that will be kept. 
        /// </summary>
        /// <param name="other">Other Charge List to merge from</param>
        public void MergeChargeLists(ChargeList other)
        {
            List<TuneRecord> otherTuneRecords = other.GetTuneRecords();

            // Merge notes first
            mNotes.AddRange(other.GetNotes());

            // Merge tune records
            for (int i = 0; i < otherTuneRecords.Count; ++i)
            {
                bool matchFound = false;
                for (int j = 0; j < mTuneRecords.Count; ++j)
                {
                    if (otherTuneRecords[i].mTuneType == mTuneRecords[j].mTuneType)
                    {
                        // There is a matching tune type in both the new and old list, merge the counts
                        mTuneRecords[j].mCount += otherTuneRecords[i].mCount;
                        matchFound = true;
                        break;
                    }
                }

                if (!matchFound)
                {
                    // No match for this record was found so just add it to the existing list
                    TuneRecord tr = new TuneRecord();
                    tr.mTuneType = otherTuneRecords[i].mTuneType;
                    tr.mCount = otherTuneRecords[i].mCount;
                    mTuneRecords.Add(tr);
                }
            }
        }