Exemplo n.º 1
0
 private void RemoveTask()
 {
     using (var db = new OrganizerContext())
     {
         db.Tasks.Remove(db.Tasks.Find(Task.Id));
         db.SaveChanges();
         ParentWindow.ReloadTasks();
     }
 }
Exemplo n.º 2
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new NewTask(Task);

            dialog.Title = "Редактировать задачу";
            if (dialog.ShowDialog() == true)
            {
                using (var db = new OrganizerContext())
                {
                    db.Tasks.AddOrUpdateExtension(Task);
                    db.SaveChanges();
                    ParentWindow.ReloadTasks();
                }
            }
        }
Exemplo n.º 3
0
 public void ReloadTasks()
 {
     separatorAdded = false;
     TaskList.Items.Clear();
     using (var db = new OrganizerContext())
     {
         foreach (var task in db.Tasks.OrderBy(t => t.StartDate).ThenBy(t => t.Hour).ThenBy(t => t.Minute))
         {
             if (task.StartDate > DateTime.Today)
             {
                 AddSeparator();
             }
             var item = new TaskListItem();
             item.Task         = task;
             item.ParentWindow = this;
             item.UpdateGraphics();
             TaskList.Items.Add(item);
         }
     }
 }
Exemplo n.º 4
0
 private void StartMonitor()
 {
     new System.Threading.Tasks.TaskFactory().StartNew(() =>
     {
         while (true)
         {
             using (var db = new OrganizerContext())
             {
                 foreach (var task in db.Tasks.Where(t => t.StartDate == DateTime.Today && t.FixedTime).ToList())
                 {
                     if (DateTime.Now.Minute == task.Minute && DateTime.Now.Hour == task.Hour)
                     {
                         Dispatcher.BeginInvoke(new Action(() =>
                         {
                             ni.ShowBalloonTip(5000, "Напоминание", task.Text, ToolTipIcon.Warning);
                             TaskManager.ExecuteTask(task, this);
                         }));
                     }
                 }
             }
             Thread.Sleep(1000);
         }
     });
 }
Exemplo n.º 5
0
 private void OK_Click(object sender, RoutedEventArgs e)
 {
     if (string.IsNullOrEmpty(TaskText.Text) || TaskStartDate.SelectedDate == null)
     {
         return;
     }
     if (task == null)
     {
         task = new Task
         {
             Text       = TaskText.Text,
             RepeatRule = TaskRepeatRule.Text,
             FixedTime  = TaskFixedTime.IsChecked.Value,
             StartDate  = TaskStartDate.SelectedDate.Value
         };
     }
     else
     {
         task.Text       = TaskText.Text;
         task.RepeatRule = TaskRepeatRule.Text;
         task.FixedTime  = TaskFixedTime.IsChecked.Value;
         task.StartDate  = TaskStartDate.SelectedDate.Value;
     }
     if (TaskFixedTime.IsChecked.Value)
     {
         task.Hour   = GetVal(TaskHour.Text);
         task.Minute = GetVal(TaskMinute.Text);
     }
     using (var db = new OrganizerContext())
     {
         db.Tasks.AddOrUpdateExtension(task);
         db.SaveChanges();
     }
     DialogResult = true;
     Close();
 }
Exemplo n.º 6
0
        public static void ExecuteTask(Task task, MainWindow parentWindow)
        {
            switch (task.RepeatRule)
            {
            case "Открытая задача":
            case "Один раз":
                using (var db = new OrganizerContext())
                {
                    var taskToRemove = db.Tasks.Find(task.Id);
                    if (taskToRemove == null)
                    {
                        return;
                    }
                    db.Tasks.Remove(taskToRemove);
                    db.SaveChanges();
                    parentWindow?.ReloadTasks();
                }
                return;

            case "Каждый день":
                task.StartDate = task.StartDate.AddDays(1);
                break;

            case "Каждую неделю":
                task.StartDate = task.StartDate.AddDays(7);
                break;

            case "Каждый месяц":
                task.StartDate = task.StartDate.AddMonths(1);
                break;

            case "Каждый год":
                task.StartDate = task.StartDate.AddYears(1);
                break;

            case "Будни дни":
                if (DateTime.Today.DayOfWeek != DayOfWeek.Saturday && DateTime.Today.DayOfWeek != DayOfWeek.Sunday)
                {
                    if (DateTime.Today.DayOfWeek == DayOfWeek.Friday)
                    {
                        task.StartDate = task.StartDate.AddDays(3);
                    }
                    else
                    {
                        task.StartDate = task.StartDate.AddDays(1);
                    }
                }
                break;

            case "Выходные":
                if (DateTime.Today.DayOfWeek == DayOfWeek.Saturday)
                {
                    task.StartDate = task.StartDate.AddDays(1);
                }
                else if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday)
                {
                    task.StartDate = task.StartDate.AddDays(6);
                }
                break;
            }
            using (var db = new OrganizerContext())
            {
                db.Tasks.AddOrUpdateExtension(task);
                db.SaveChanges();
                parentWindow?.ReloadTasks();
            }
        }