Exemple #1
0
        private ICalendarEntry CheckForCalendarEntry(MouseEventArgs e)
        {
            bool           matchFound    = false;
            ICalendarEntry calendarEntry = null;

            if (e.X < EntryOffset ||
                e.X > panelDailyView.ClientRectangle.Size.Width - vScrollBar.Width - EntryOffset)
            {
                // The X co-ordinate is not inside an entry in the calendar, so simply exit
                return(null);
            }
            // Determine the row corresponding to the mouse position
            int row = e.Y / PanelRowHeight + vScrollBar.Value;
            // Look through todays entriess to see if we
            // are positioned on any of them
            IEnumerator <ICalendarEntry> enumerator = _todaysEntries.GetEnumerator();

            while (enumerator.MoveNext() && !matchFound)
            {
                int apptRow    = Utility.ConvertTimeToRow(enumerator.Current.Start);
                int apptLength = Utility.ConvertLengthToRows(enumerator.Current.Length);
                if (row >= apptRow &&
                    row <= apptRow + apptLength - 1)
                {
                    matchFound    = true;
                    calendarEntry = enumerator.Current;
                }
            }
            return(calendarEntry);
        }
        // ShowDialog method that allows the selected calender entrey to be edited.
        public DialogResult ShowDialog(ICalendarEntry single, string dateFromMainForm)
        {
            // set the displayed date as the one that is passed in as the paramter
            date           = Convert.ToDateTime(dateFromMainForm);
            labelDate.Text = dateFromMainForm;

            // populate the form with the data in the passed in calendar event
            char splitter = '\t';

            string[] splittedData = single.SavedData.Split(splitter);
            comboBoxStartTime.SelectedItem = splittedData[1].Remove(0, 11);
            // if statement to determine whether the length is 30, 60 or 90.
            //This is needed to be able to correctly format the currently selected item as the one
            //the user chose when they first created the event
            if (int.Parse(splittedData[2]) == 30 || int.Parse(splittedData[2]) == 60 || int.Parse(splittedData[2]) == 90)
            {
                comboBoxLength.SelectedItem = splittedData[2] + "minutes"; // no space needed as there is already one in because it picks 3 characters including a blank space
            }
            else
            {
                comboBoxLength.SelectedItem = splittedData[2] + " minutes"; // space needed as all 3 characters are full so a space is needed to correctly display it in the combo box.
            }

            // populate the subject and location text boxes with what has been entered in the
            //last field in the array
            char subjectAndLocationSplitter = ',';

            string[] subjectAndLocationSplittedData = splittedData[3].Split(subjectAndLocationSplitter);
            textBoxSubject.Text  = subjectAndLocationSplittedData[0];
            textBoxLocation.Text = subjectAndLocationSplittedData[1];
            this.ShowDialog();    // show the dialog box by calling the standard ShowDialog method
            return(DialogResult); // return the DialogResult. Used by the if statement that contains ShowDialog
        }
Exemple #3
0
        private void panelDailyView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ICalendarEntry calendarEntry = CheckForCalendarEntry(e);

            if (calendarEntry != null)
            {
                // TODO   Add code to edit the current calendar entry (specified in calendarEntry).
            }
        }
Exemple #4
0
        private void panelDailyView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ICalendarEntry calendarEntry = CheckForCalendarEntry(e);

            if (calendarEntry != null)
            {
                editEntry(calendarEntry);
            }
        }
Exemple #5
0
 private void panelDailyView_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Right)
     {
         // See if we are on an appointment. If
         // so, display the context menu.
         ICalendarEntry calendarEntry = CheckForCalendarEntry(e);
         if (calendarEntry != null)
         {
             _selectedCalendarEntry = calendarEntry;
             contextMenuStrip.Show(panelDailyView, new Point(e.X, e.Y));
         }
     }
     else
     {
         // Calculate the new selected row and force
         // a repaint of the panel
         int y = e.Y / PanelRowHeight;
         _selectedRow = y + vScrollBar.Value;
         panelDailyView.Invalidate();
     }
 }
        /// <summary>
        /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </summary>
        /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1" />.</param>
        /// <returns>
        /// true if <paramref name="item" /> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1" />; otherwise, false. This method also returns false if <paramref name="item" /> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1" />.
        /// </returns>
        public bool Remove(ICalendarEntry item)
        {
            load = new StreamReader("appointments.txt");
            string info = "";

            try
            {
                string line = load.ReadLine();
                while (line != null)
                {
                    if (item is Appointment)
                    {
                        Appointment s_appointment = item as Appointment;
                        info = "Appointment\t" + s_appointment.Start.ToLongDateString() + "\t" + s_appointment.Start.ToLongTimeString() + "\t" + s_appointment.Length + "\t" + s_appointment.Subject + "\t" + s_appointment.Location;
                        if (info.CompareTo(line) == 0)
                        {
                            load.Close();
                            load = null;
                            save = new StreamWriter("appointments.txt");
                            line = "";
                            save.WriteLine(line);
                            save.Close();
                            save = null;
                            load = new StreamReader("appointments.txt");
                        }
                    }
                    line = load.ReadLine();
                }
            }
            catch
            {
                load.Close();
                load = null;
            }
            load.Close();
            load = null;
            return(true);
        }
Exemple #7
0
 private void editEntry(ICalendarEntry entry)
 {
     if (entry.GetType() == typeof(RecurringCalendarEntry))
     {
         using (RecurringAppointmentForm newAppointmentForm = new RecurringAppointmentForm((RecurringCalendarEntry)entry))
         {
             if (newAppointmentForm.ShowDialog() == DialogResult.OK)
             {
                 RefreshDailyView();
             }
         }
     }
     else if (entry.GetType() == typeof(SingleCalendarEntry))
     {
         using (SingleAppointmentForm newAppointmentForm = new SingleAppointmentForm((SingleCalendarEntry)entry))
         {
             if (newAppointmentForm.ShowDialog() == DialogResult.OK)
             {
                 RefreshDailyView();
             }
         }
     }
 }
Exemple #8
0
 // Method responsible for adding an r_appointment
 // to the list as itemList
 public void Add(ICalendarEntry itemList)
 {
     this.list.Add(itemList);
 }
Exemple #9
0
        public DialogResult ShowDialog(ICalendarEntry recurring, string dateFromMainForm)
        {
            // set the displayed date as the one that is passed in as the paramter
            date           = Convert.ToDateTime(dateFromMainForm);
            labelDate.Text = dateFromMainForm;

            // populate the form with the data in the passed in calendar event
            char splitter = '\t';

            string[] splittedData = recurring.SavedData.Split(splitter);
            comboBoxStartTime.SelectedItem = splittedData[1].Remove(0, 11);
            // if statement to determine whether the length is 30, 60 or 90.
            //This is needed to be able to cirrectly format the currently selected item as the one
            //the user chose when they first created the event
            if (int.Parse(splittedData[2]) == 30 || int.Parse(splittedData[2]) == 60 || int.Parse(splittedData[2]) == 90)
            {
                comboBoxLength.SelectedItem = splittedData[2] + "minutes"; // no space needed as there is already one in because it picks 3 characters including a blank space
            }
            else
            {
                comboBoxLength.SelectedItem = splittedData[2] + " minutes"; // space needed as all 3 characters are full so a space is needed to correctly display it in the combo box.
            }

            // populate the subject, location, frequency and how many times fields with what has been entered in the
            // last field in the array
            char subjectLocationFrequencyAndHowManyTimesSplitter = ',';

            string[] subjectLocationFrequencyAndHowManyTimesSplittedData = splittedData[3].Split(subjectLocationFrequencyAndHowManyTimesSplitter);
            textBoxSubject.Text  = subjectLocationFrequencyAndHowManyTimesSplittedData[0];
            textBoxLocation.Text = subjectLocationFrequencyAndHowManyTimesSplittedData[1];



            // Convert the number that is saved in the file to the selected item in the combo box frequency
            string comboBoxFrequencySelectedItem = "";

            switch (int.Parse(subjectLocationFrequencyAndHowManyTimesSplittedData[2].ToString()))
            {
            case 0:     // Daily
                comboBoxFrequencySelectedItem = "Daily";
                break;

            case 1:     // Weekly
                comboBoxFrequencySelectedItem = "Weekly";
                break;

            case 2:     // Fornightly
                comboBoxFrequencySelectedItem = "Fornightly";
                break;

            case 3:     // Monthly
                comboBoxFrequencySelectedItem = "Monthly";
                break;

            case 4:     // Yearly
                comboBoxFrequencySelectedItem = "Yearly";
                break;

            default:
                break;
            }
            comboBoxFrequency.SelectedItem = comboBoxFrequencySelectedItem;
            textBoxHowManyTimes.Text       = subjectLocationFrequencyAndHowManyTimesSplittedData[3];
            this.ShowDialog();    // show the dialog box by calling the standard ShowDialog method
            return(DialogResult); // return the DialogResult. This is used by the if statement that is contains the ShowDialog method
        }
Exemple #10
0
 private void deleteEntry(ICalendarEntry entry)
 {
     _calendarEntries.Remove(entry);
     RefreshDailyView();
 }