private void detail_OnEndEditEvent(object sender, EventArgs e)
        {
            stackPanel.Margin = new Thickness(0, 5, 0, 5);

            MonthDetail _sender     = (MonthDetail)sender;
            Appointment appointment = _sender.Appointment;

            if (!_forceSave && string.IsNullOrEmpty(appointment.Subject) &&
                !appointment.IsRepeating &&
                !AppointmentDatabase.AppointmentExists(appointment))
            {
                stackPanel.Children.Remove(_sender);
                AppointmentDatabase.Delete(appointment);
                ReminderQueue.RemoveItem(appointment.ID, appointment.IsRepeating ? appointment.RepresentingDate.Add(appointment.StartDate.TimeOfDay) : appointment.StartDate, ReminderType.Appointment);
            }
            else
            {
                Appointment exception = AppointmentDatabase.UpdateAppointment(appointment);

                if (exception != null)
                {
                    _sender.Appointment = exception;
                }

                ReminderQueue.Populate();
            }

            _forceSave = false;

            EndEditEvent(e);

            _activeDetail = null;
        }
        /// <summary>
        /// Add an existing Appointment.
        /// </summary>
        /// <param name="appointment">the Appointment to add</param>
        public void Add(Appointment appointment)
        {
            MonthDetail detail = new MonthDetail(ThreadSafeDate, appointment);

            AddEventHandlers(detail);
            stackPanel.Children.Add(detail);
        }
 /// <summary>
 /// Close and finalize any MonthDetail that may be in edit mode.
 /// </summary>
 public void EndEdit()
 {
     if (_activeDetail != null && !_inDetailEditMode)
     {
         stackPanel.Margin = new Thickness(0, 5, 0, 5);
         _activeDetail.EndEdit();
         _activeDetail = null;
     }
 }
        /// <summary>
        /// Insert an existing Appointment to the stack.
        /// </summary>
        /// <param name="appointment">the Appointment to add</param>
        public MonthDetail Insert(int index, Appointment appointment)
        {
            MonthDetail detail = new MonthDetail(ThreadSafeDate, appointment);

            AddEventHandlers(detail);
            stackPanel.Children.Insert(index, detail);

            return(detail);
        }
 private void RemoveEventHandlers(MonthDetail detail)
 {
     detail.OnBeginEditEvent   -= detail_OnBeginEditEvent;
     detail.OnEndEditEvent     -= detail_OnEndEditEvent;
     detail.OnDeleteStartEvent -= detail_OnDeleteStartEvent;
     detail.OnDeleteEndEvent   -= detail_OnDeleteEndEvent;
     detail.OnDoubleClickEvent -= detail_OnDoubleClickEvent;
     detail.OnExportEvent      -= detail_OnExportEvent;
     detail.Navigate           -= detail_Navigate;
     detail.ShowAsChanged      -= detail_ShowAsChanged;
 }
        /// <summary>
        /// Delete any MonthDetail that is currently in edit mode.
        /// </summary>
        public void DeleteActive()
        {
            if (_activeDetail != null)
            {
                EndEditEvent(EventArgs.Empty);

                stackPanel.Margin = new Thickness(0, 5, 0, 5);

                stackPanel.Children.Remove(_activeDetail);
                AppointmentDatabase.Delete(_activeDetail.Appointment);

                ReminderQueue.RemoveItem(_activeDetail.Appointment.ID, _activeDetail.Appointment.IsRepeating ? _activeDetail.Appointment.RepresentingDate.Add(_activeDetail.Appointment.StartDate.TimeOfDay) : _activeDetail.Appointment.StartDate, ReminderType.Appointment);

                _activeDetail = null;
            }
        }
        private void detail_OnBeginEditEvent(object sender, EventArgs e)
        {
            stackPanel.Margin = new Thickness(0, 0, 0, 5);

            _activeDetail        = (MonthDetail)sender;
            _activeDetail.Height = ActualHeight;

            foreach (MonthDetail detail in stackPanel.Children)
            {
                if (detail != _activeDetail)
                {
                    detail.Visibility = Visibility.Collapsed;
                }
            }

            moreButton.Visibility = Visibility.Collapsed;

            _inDetailEditMode = false;

            BeginEditEvent(e);
        }
        public void Clear()
        {
            if (loadTask != null && !loadTask.IsCompleted)
            {
                tokenSource.Cancel(true);

                try { loadTask.Wait(); }
                catch { }
            }

            int count = stackPanel.Children.Count;

            for (int i = 0; i < count; i++)
            {
                MonthDetail detail = (MonthDetail)stackPanel.Children[i];
                RemoveEventHandlers(detail);
                detail.CloseToolTip();
            }

            stackPanel.Children.Clear();
        }
        /// <summary>
        /// Add an Appointment, optionally with the specified subject.
        /// </summary>
        public void Add(string subject = "", bool openDetailEdit = false)
        {
            if (_activeDetail != null)
            {
                EndEdit();
            }

            MonthDetail detail = new MonthDetail(ThreadSafeDate);

            detail.Appointment.Subject = subject;
            AddEventHandlers(detail);
            stackPanel.Children.Insert(0, detail);

            if (openDetailEdit)
            {
                detail.InvokeDoubleClickEvent();
            }
            else
            {
                detail.BeginEdit();
            }
        }
        private void detail_OnDeleteEndEvent(object sender, EventArgs e)
        {
            MonthDetail _sender = (MonthDetail)sender;

            RemoveEventHandlers(_sender);

            if (_sender == _activeDetail)
            {
                _activeDetail = null;
            }

            if (_activeDetail == null)
            {
                stackPanel.Margin = new Thickness(0, 5, 0, 5);
                EndEditEvent(e);
            }

            stackPanel.Children.Remove(_sender);

            if (_activeDetail != null)
            {
                DeleteEndEvent(sender, e);
            }
        }
 private void detail_OnDoubleClickEvent(object sender, EventArgs e)
 {
     _activeDetail     = (MonthDetail)sender;
     _inDetailEditMode = true;
     DoubleClickEvent(sender, e);
 }