private List <ScheduleEvent> LoadScheduleDataOnly()
        {
            List <ScheduleEvent> cList = new List <ScheduleEvent>();

            char[]   sDelim1 = { '|' };
            char[]   sDelim2 = { ',' };
            string[] sRecs   = m_sScheduleData.Split(sDelim1);
            foreach (string sRec in sRecs)
            {
                string[] sParts = sRec.Split(sDelim2);
                if (sParts.Length.Equals(3))
                {
                    ScheduleEvent cEvent = new ScheduleEvent(int.Parse(sParts[0]), DateTime.Parse(sParts[1]), DateTime.Parse(sParts[2]));
                    cList.Add(cEvent);
                }
            }
            return(cList);
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // build list of all events
            List <ScheduleEvent> cEvents = new List <ScheduleEvent>();

            #region first, get all the new events
            CheckBox[] cCBs = { chkDay0, chkDay1, chkDay2, chkDay3, chkDay4, chkDay5, chkDay6 };
            foreach (CheckBox cCB in cCBs)
            {
                if (!cCB.Checked)
                {
                    continue;
                }
                string        sIndex = cCB.Name.Substring(6, 1);
                int           iIndex = int.Parse(sIndex);
                ScheduleEvent cEvent = new ScheduleEvent(iIndex, dtStart.Value, dtEnd.Value);
                cEvents.Add(cEvent);
            }
            #endregion
            #region add all existing events
            foreach (ListViewItem cItem in lvList.Items)
            {
                ScheduleEvent cEvent = new ScheduleEvent(GetDayIndex(cItem.SubItems[0].Text), DateTime.Parse(cItem.SubItems[1].Text), DateTime.Parse(cItem.SubItems[2].Text));
                cEvents.Add(cEvent);
            }
            #endregion
            #region sort the list
            cEvents.Sort();
            #endregion
            #region re-populate the listview control
            lvList.Items.Clear();
            foreach (ScheduleEvent cEvent in cEvents)
            {
                ListViewItem lvi = new ListViewItem(((DayOfWeek)cEvent.DayOfWeek).ToString());
                lvi.SubItems.Add(cEvent.StartTime.ToShortTimeString());
                lvi.SubItems.Add(cEvent.EndTime.ToShortTimeString());
                lvList.Items.Add(lvi);
            }
            #endregion
        }
        int IComparable.CompareTo(object cObj)
        {
            ScheduleEvent cEvent = (ScheduleEvent)cObj;

            if (cEvent.DayOfWeek > DayOfWeek)
            {
                return(-1);
            }
            if (cEvent.DayOfWeek < DayOfWeek)
            {
                return(1);
            }
            if (cEvent.StartTime > StartTime)
            {
                return(-1);
            }
            if (cEvent.StartTime < StartTime)
            {
                return(1);
            }
            return(0);
        }