Exemple #1
0
        private void NewRecurringAppointment()
        {
            RecurringAppointment newRecurring = new RecurringAppointment(Utility.ConvertRowToDateTime(monthCalendar.SelectionRange.Start, _SelectedRow));

            if (AddEdit(newRecurring))
            {
                try
                {
                    _Appointments.Add(newRecurring);
                    //Add Here.
                    foreach (DateTime date in new List <DateTime>(newRecurring.OccuringDates))
                    {
                        try
                        {
                            var _TestApt = new Appointment(date + newRecurring.Start.TimeOfDay);
                            _TestApt.Length = newRecurring.Length;
                            _Appointments.Add(_TestApt);
                            _Appointments.Remove(_TestApt);
                        }
                        catch (ItemsException e)
                        {
                            MessageBox.Show("Recurring Appointment at " + date.ToShortDateString() + " overlaps too many appointments. Still adding the remaining.", "Recurring Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            newRecurring.OccuringDates.Remove(date);
                        }
                    }
                }
                catch (ItemsException e)
                {
                    MessageBox.Show(this, e.Message, "Error adding Item", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            panelDailyView.Invalidate();
            GetAppointmentsOnSelectedDate(monthCalendar.SelectionRange.Start);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RecurringAppointmentFrontEnd"/> class.
 /// Constructor with parameters
 /// </summary>
 /// <param name="day">The day.</param>
 /// <param name="recurringAppointment">The recurring appointment.</param>
 public RecurringAppointmentFrontEnd(DateTime day, RecurringAppointment recurringAppointment)
 {
     InitializeComponent();
     this.day = day;
     this.recurringAppointment = recurringAppointment;
     subjectTextBox.Text       = recurringAppointment.Subject;
     locationTextBox.Text      = recurringAppointment.Location;
     occurenceTextBox.Text     = recurringAppointment.NumberOfRecurrence.ToString();
 }
Exemple #3
0
        /// <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(IAppointment 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");
                        }
                    }
                    if (item is RecurringAppointment)
                    {
                        RecurringAppointment r_appointment = item as RecurringAppointment;
                        info = "RecurringAppointment\t" + r_appointment.Start.ToLongDateString() + "\t" + r_appointment.Start.ToLongTimeString() + "\t" + r_appointment.Length + "\t" + r_appointment.Subject + "\t" + r_appointment.Location + "\t" + r_appointment.NumberOfRecurrence + "\t" + r_appointment.RecurrenceFrequency.ToString();
                        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(list.Remove(item));
        }
Exemple #4
0
 private void RecurringForm_Load(object sender, EventArgs e)
 {
     _Apt = base.Apt as RecurringAppointment;
     type_ComboBox.DataSource = Enum.GetNames(typeof(Type));
     freq_ComboBox.DataSource = Enum.GetNames(typeof(Recurring));
     amount_TextBox.MaxLength = 3;
     if (_Apt != null)
     {
         freq_ComboBox.SelectedIndex = freq_ComboBox.Items.IndexOf(_Apt.Recursion.ToString());
         amount_TextBox.Text         = _Apt.AmountRecurring.ToString();
     }
 }
Exemple #5
0
        /// <summary>
        /// Saves this instance.
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            bool   isSaved = false;
            string info    = "";

            save = new StreamWriter("appointments.txt");
            while (!isSaved)
            {
                foreach (IAppointment app in list)
                {
                    if (app is Appointment)
                    {
                        Appointment s_appointment = app 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;
                        try
                        {
                            save.WriteLine(info);
                            isSaved = true;
                        }
                        catch
                        {
                            save.Close();
                            save    = null;
                            isSaved = false;
                        }
                    }
                    if (app is RecurringAppointment)
                    {
                        RecurringAppointment r_appointment = app as RecurringAppointment;
                        info = "RecurringAppointment\t" + r_appointment.Start.ToLongDateString() + "\t" + r_appointment.Start.ToLongTimeString() + "\t" + r_appointment.Length + "\t" + r_appointment.Subject + "\t" + r_appointment.Location + "\t" + r_appointment.NumberOfRecurrence + "\t" + r_appointment.RecurrenceFrequency.ToString();
                        try
                        {
                            save.WriteLine(info);
                            isSaved = true;
                        }
                        catch
                        {
                            save.Close();
                            save    = null;
                            isSaved = false;
                        }
                    }
                }
            }
            save.Close();
            save = null;
            return(isSaved);
        }
        /// <summary>
        /// Handles the Click event of the saveButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void saveButton_Click(object sender, EventArgs e)
        {
            int numberOfOccurence = 0;

            if (occurenceTextBox.Text.Trim() != "")
            {
                try
                {
                    // Check for occurence
                    // Cant be 1 and more than a specific high number
                    numberOfOccurence = int.Parse(occurenceTextBox.Text);
                    if (numberOfOccurence > 999 || numberOfOccurence < 2)
                    {
                        MessageBox.Show("Please select a number between 2 and 999", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        occurenceTextBox.Text = "";
                        return;
                    }
                }
                catch
                {
                    // Cathing exception of error handling
                    MessageBox.Show("Please select a number between 2 and 999", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    occurenceTextBox.Text = "";
                }
            }
            TimeDuration duration = (TimeDuration)lengthComboBox.Items[lengthComboBox.SelectedIndex];
            int          length   = (duration.Hours * 60) + duration.Minutes;
            TimeSpan     timespan = (TimeSpan)startTimeComboBox.Items[startTimeComboBox.SelectedIndex];

            day = day.AddHours(timespan.TotalHours);
            RecurrenceFrequency type = (RecurrenceFrequency)frequencyComboBox.Items[frequencyComboBox.SelectedIndex];

            if (numberOfOccurence == 0)
            {
                return;
            }
            recurringAppointment = new RecurringAppointment(numberOfOccurence, type, day, length, subjectTextBox.Text, locationTextBox.Text);
            this.Close();
        }
Exemple #7
0
 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_SelectedAppointment.GetType() == typeof(RecurringAppointment))
     {
         DialogResult dialogResult = MessageBox.Show("Delete all recurring appointments?", "Delete Recurring", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.No)
         {
             RecurringAppointment comparison = (RecurringAppointment)_SelectedAppointment;
             comparison.OccuringDates.Remove(monthCalendar.SelectionRange.Start.Date);
         }
         else if (dialogResult == DialogResult.Yes)
         {
             _Appointments.Remove(_SelectedAppointment);
         }
     }
     else
     {
         _Appointments.Remove(_SelectedAppointment);
     }
     _SelectedAppointment = null;
     GetAppointmentsOnSelectedDate(monthCalendar.SelectionRange.Start);
     panelDailyView.Invalidate();
 }
        private void saveButton_Click(object sender, EventArgs e)
        {
            int numberOfOccurence = 0;

            if (occurenceTextBox.Text.Trim() != "")
            {
                try
                {
                    numberOfOccurence = int.Parse(occurenceTextBox.Text);
                    if (numberOfOccurence > 999 || numberOfOccurence < 2)
                    {
                        MessageBox.Show("Please select a number between 2 and 999 to specify the recurring number", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        occurenceTextBox.Text = "";
                    }
                }
                catch
                {
                    MessageBox.Show("Please select a number between 2 and 999 to specify te recurring number", "Invalid input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    occurenceTextBox.Text = "";
                }
            }
            Time     duration = (Time)lengthComboBox.Items[lengthComboBox.SelectedIndex];
            int      length   = (duration.Hours * 60) + duration.Minutes;
            TimeSpan timespan = (TimeSpan)timeComboBox.Items[timeComboBox.SelectedIndex];

            day = day.AddHours(timespan.TotalHours);
            RecurrenceType type = (RecurrenceType)frequencyComboBox.Items[frequencyComboBox.SelectedIndex];

            if (numberOfOccurence == 0)
            {
                MessageBox.Show("Please specify the number of recurrence for this appointment", "Missing input", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            recurringApp = new RecurringAppointment(numberOfOccurence, type, day, length, subjectTextBox.Text, locationTextBox.Text);
            this.Close();
        }
Exemple #9
0
 private void editToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_SelectedAppointment is RecurringAppointment)
     {
         RecurringAppointment     app  = _SelectedAppointment as RecurringAppointment;
         RecurringAppointmentForm form = new RecurringAppointmentForm(monthCalendar.SelectionRange.Start, app);
         form.ShowDialog();
         _Appointments.Remove(app);
         _TodaysAppointments.Remove(app);
         if (form.ReccuringApp == null)
         {
             return;
         }
         if (_Appointments.Count > 0)
         {
             foreach (IAppointment appointment in _Appointments)
             {
                 if (form.ReccuringApp.OccursOnTime(appointment.Start, appointment.Length))
                 {
                     MessageBox.Show("Date and Time already used at" + appointment.Start.ToLongDateString(),
                                     "Cannot add current appointment",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Warning);
                     return;
                 }
             }
         }
         _Appointments.Add(form.ReccuringApp);
         _TodaysAppointments.Add(form.ReccuringApp);
         panelDailyView.Invalidate();
         return;
     }
     if (_SelectedAppointment is Appointment)
     {
         Appointment     app  = _SelectedAppointment as Appointment;
         AppointmentForm form = new AppointmentForm(monthCalendar.SelectionRange.Start, app);
         form.ShowDialog();
         if (form.App == null)
         {
             return;
         }
         if (_Appointments.Count > 0)
         {
             foreach (IAppointment appointment in _Appointments)
             {
                 if (form.App.OccursOnTime(appointment.Start, appointment.Length))
                 {
                     MessageBox.Show("Date and Time already used",
                                     "Cannot add current appointment",
                                     MessageBoxButtons.OK,
                                     MessageBoxIcon.Warning);
                     return;
                 }
             }
         }
         _Appointments.Remove(app);
         _TodaysAppointments.Remove(app);
         _Appointments.Add(form.App);
         _TodaysAppointments.Add(form.App);
         panelDailyView.Invalidate();
         return;
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RecurringAppointmentFrontEnd"/> class.
 /// Constructor
 /// </summary>
 /// <param name="day">The day.</param>
 public RecurringAppointmentFrontEnd(DateTime day)
 {
     InitializeComponent();
     this.day             = day;
     recurringAppointment = null;
 }
Exemple #11
0
        //
        private void panelDailyView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            IAppointment appointment = CheckForAppointment(e);

            if (appointment != null)
            {
                _SelectedAppointment = appointment;
                if (_SelectedAppointment is RecurringAppointment)
                {
                    RecurringAppointment         app  = _SelectedAppointment as RecurringAppointment;
                    RecurringAppointmentFrontEnd form = new RecurringAppointmentFrontEnd(monthCalendar.SelectionRange.Start, app);
                    form.ShowDialog();
                    _Appointments.Remove(_SelectedAppointment);
                    _TodaysAppointments.Remove(_SelectedAppointment);
                    if (form.RecurringAppointment == null || form.RecurringAppointment == app)
                    {
                        return;
                    }
                    if (_Appointments.Count > 0)
                    {
                        foreach (IAppointment otherappointment in _Appointments)
                        {
                            if (form.RecurringAppointment.OccursOnTime(otherappointment.Start, otherappointment.Length))
                            {
                                MessageBox.Show("Date and Time already used at " + app.Start.ToLongDateString(),
                                                "Cannot add current recurring appointment",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Warning);
                                return;
                            }
                        }
                    }
                    _Appointments.Remove(app);
                    _TodaysAppointments.Remove(app);
                    _Appointments.Add(form.RecurringAppointment);
                    if (_Appointments.Save())
                    {
                        _TodaysAppointments.Add(form.RecurringAppointment);
                        panelDailyView.Invalidate();
                    }
                }
                if (_SelectedAppointment is Appointment)
                {
                    Appointment         app  = _SelectedAppointment as Appointment;
                    AppointmentFrontEnd form = new AppointmentFrontEnd(monthCalendar.SelectionRange.Start, app);
                    form.ShowDialog();
                    if (form.Appointment == null || form.Appointment == app)
                    {
                        return;
                    }
                    if (_Appointments.Count > 0)
                    {
                        foreach (IAppointment otherappointment in _Appointments)
                        {
                            if (form.Appointment.TimeConflict(otherappointment.Start, otherappointment.Length))
                            {
                                MessageBox.Show("Date and Time already used",
                                                "Cannot add current appointment",
                                                MessageBoxButtons.OK,
                                                MessageBoxIcon.Warning);
                                return;
                            }
                        }
                    }
                    _Appointments.Remove(app);
                    _TodaysAppointments.Remove(app);
                    _Appointments.Add(form.Appointment);
                    if (_Appointments.Save())
                    {
                        _TodaysAppointments.Add(form.Appointment);
                        panelDailyView.Invalidate();
                    }
                }
            }
        }