示例#1
0
        private void deleteTask(TreeViewItem item, bool deleteFromDatabase = true)
        {
            // Delete the task from the file
            if (deleteFromDatabase)
            {
                UserTask task = item.Header as UserTask;
                TaskDatabase.Delete(task);
                ReminderQueue.RemoveItem(task.ID, task.StartDate, ReminderType.Task);
            }
            // else, we just want to use the animation.

            TreeViewItem parent = item.Parent as TreeViewItem;

            if (parent.Items.Count > 1)
            {
                if (Settings.AnimationsEnabled)
                {
                    AnimationHelpers.DeleteAnimation deleteAnim = new AnimationHelpers.DeleteAnimation(item);
                    deleteAnim.OnAnimationCompletedEvent += deleteAnim_OnAnimationCompletedEvent;
                    deleteAnim.Animate();
                }
                else
                {
                    parent.Items.Remove(item);
                }
            }
            else
            {
                if (Settings.AnimationsEnabled)
                {
                    AnimationHelpers.DeleteAnimation parentDeleteAnim = new AnimationHelpers.DeleteAnimation(parent);
                    parentDeleteAnim.OnAnimationCompletedEvent += parentDeleteAnim_OnAnimationCompletedEvent;
                    parentDeleteAnim.Animate();

                    if (tasksTreeView.Items.Count <= 1)
                    {
                        statusText.Text = "We didn't find anything to show here.";
                        new AnimationHelpers.Fade(statusText, AnimationHelpers.FadeDirection.In);
                    }
                }
                else
                {
                    tasksTreeView.Items.Remove(parent);
                    if (tasksTreeView.Items.Count == 0)
                    {
                        statusText.Text       = "We didn't find anything to show here.";
                        statusText.Visibility = Visibility.Visible;
                        statusText.Opacity    = 1;
                    }
                }
            }
        }
        /// <summary>
        /// Deletes an existing grade.
        /// </summary>
        /// <param name="model">Grade details to delete.</param>
        /// <returns>0 on failure, 1 on success, 2 on unexpected database error.</returns>
        public int Delete(Grade model)
        {
            int result = 0;

            try
            {
                using (TaskDatabase db = new TaskDatabase())
                {
                    result = db.Delete(model);
                }
            }
            catch (Exception)
            {
                result = 2;
            }

            return(result);
        }
示例#3
0
        //#region Task Context Menu

        //private void taskGrid_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        //{
        //	Grid grid = sender as Grid;
        //	TreeViewItem item = (grid.TemplatedParent as ContentPresenter).TemplatedParent as TreeViewItem;
        //	item.IsSelected = true;
        //	Task task = item.Header as Task;

        //	MenuItem menu = grid.ContextMenu.Items[0] as MenuItem;
        //	Image img = new Image();
        //	img.Stretch = Stretch.None;

        //	if (task.Status == Task.StatusPhase.Completed)
        //	{
        //		menu.Header = "_Flag Incomplete";
        //		img.Source = new BitmapImage(new Uri("pack://application:,,,/Daytimer.Images;component/Images/redflag.png", UriKind.Absolute));
        //	}
        //	else
        //	{
        //		menu.Header = "_Mark Complete";
        //		img.Source = new BitmapImage(new Uri("pack://application:,,,/Daytimer.Images;component/Images/greencheck.png", UriKind.Absolute));
        //	}

        //	menu.Icon = img;
        //}

        //private void deleteMenuItem_Click(object sender, RoutedEventArgs e)
        //{
        //	TreeViewItem item = (((sender as MenuItem).Parent as ContextMenu).TemplatedParent as ContentPresenter).TemplatedParent as TreeViewItem;
        //	deleteTask(item);
        //}

        //private void completeMenuItem_Click(object sender, RoutedEventArgs e)
        //{
        //	MarkComplete();
        //}

        //private void collapseAllGroups_Click(object sender, RoutedEventArgs e)
        //{
        //	foreach (TreeViewItem each in tasksTreeView.Items)
        //		each.IsExpanded = false;
        //}

        //private void expandAllGroups_Click(object sender, RoutedEventArgs e)
        //{
        //	foreach (TreeViewItem each in tasksTreeView.Items)
        //		each.IsExpanded = true;
        //}

        //private void deleteGroup_Click(object sender, RoutedEventArgs e)
        //{
        //	TreeViewItem header = (sender as MenuItem).CommandTarget as TreeViewItem;

        //	int count = header.Items.Count;

        //	for (int i = 0; i < count; i++)
        //	{
        //		TreeViewItem item = header.Items[i] as TreeViewItem;

        //		// Delete the task from the file
        //		Task task = item.Header as Task;
        //		TaskDatabase.Delete(task);
        //	}

        //	if (AnimationHelpers.AnimationsEnabled)
        //	{
        //		AnimationHelpers.DeleteAnimation parentDeleteAnim = new AnimationHelpers.DeleteAnimation(header);
        //		parentDeleteAnim.OnAnimationCompletedEvent += parentDeleteAnim_OnAnimationCompletedEvent;
        //		parentDeleteAnim.Animate();

        //		if (tasksTreeView.Items.Count <= 1)
        //		{
        //			statusText.Text = "We didn't find anything to show here.";
        //			AnimationHelpers.Fade fade = new AnimationHelpers.Fade(statusText, AnimationHelpers.FadeDirection.In);
        //		}
        //	}
        //	else
        //	{
        //		tasksTreeView.Items.Remove(header);
        //		if (tasksTreeView.Items.Count == 0)
        //		{
        //			statusText.Text = "We didn't find anything to show here.";
        //			statusText.Visibility = Visibility.Visible;
        //			statusText.Opacity = 1;
        //		}
        //	}
        //}

        //#endregion

        #region Drag-reorder items

        private void tasksTreeView_ItemReorder(object sender, ItemReorderEventArgs e)
        {
            if (!e.OldParent.HasItems)
            {
                tasksTreeView.Items.Remove(e.OldParent);
            }

            int index = e.NewParent.Items.IndexOf(e.Item);

            UserTask task = e.Item.Header as UserTask;

            string header = e.NewParent.Header.ToString();

            // Hardcode "Today" since tasks due in previous days will also be
            // shown under "Today": the user will expect the task dragged in
            // to be changed to DateTime.Now.Date, not some date in the past.
            if (header == "Today")
            {
                task.DueDate = DateTime.Now.Date;
            }
            else
            {
                task.DueDate = e.NewParent.Tag as DateTime?;
            }

            if (task.StartDate > task.DueDate)
            {
                task.StartDate = task.DueDate;
            }

            e.Item.Header = new UserTask(false);
            e.Item.Header = task;

            if (task.IsOverdue && task.Status != UserTask.StatusPhase.Completed)
            {
                e.Item.Foreground = new SolidColorBrush(Color.FromArgb(255, 218, 17, 17));
            }
            else
            {
                e.Item.Foreground = Brushes.Black;
            }

            ItemReorderEventArgs args = new ItemReorderEventArgs(e.Item, e.OldParent, e.NewParent, e.Copied, e.DragDirection);

            if (TasksView.ApplicationTasksView != null)
            {
                TaskReorderCommand.Execute(args, TasksView.ApplicationTasksView);
            }

            TaskReorderCommand.MassExecute(args, LoadedTasksPeekContents, this);

            if (!e.Copied)
            {
                TaskDatabase.Delete(task, false);
            }

            //if (e.OldParent == e.NewParent && e.DragDirection == DragDirection.Up)
            //	TaskDatabase.Insert(index - 1, task);
            //else
            TaskDatabase.Insert(index, task);
        }