2021-09-11 15:32:30 +08:00
|
|
|
|
using GeekDesk.Constant;
|
|
|
|
|
|
using GeekDesk.Task;
|
2021-06-17 23:06:46 +08:00
|
|
|
|
using GeekDesk.Util;
|
|
|
|
|
|
using GeekDesk.ViewModel;
|
2021-09-11 15:32:30 +08:00
|
|
|
|
using HandyControl.Controls;
|
|
|
|
|
|
using Quartz;
|
2021-06-17 17:28:04 +08:00
|
|
|
|
using System;
|
2021-05-31 17:31:16 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Data;
|
|
|
|
|
|
using System.Windows.Documents;
|
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
|
|
2021-06-17 17:28:04 +08:00
|
|
|
|
namespace GeekDesk.Control.Other
|
2021-05-31 17:31:16 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2021-06-17 17:28:04 +08:00
|
|
|
|
/// BacklogNotificatin.xaml 的交互逻辑
|
2021-05-31 17:31:16 +08:00
|
|
|
|
/// </summary>
|
2021-06-17 17:28:04 +08:00
|
|
|
|
public partial class BacklogNotificatin
|
2021-05-31 17:31:16 +08:00
|
|
|
|
{
|
2021-06-17 23:06:46 +08:00
|
|
|
|
|
|
|
|
|
|
private AppData appData = MainWindow.appData;
|
2021-07-18 20:10:19 +08:00
|
|
|
|
public BacklogNotificatin(ToDoInfo info)
|
2021-05-31 17:31:16 +08:00
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2021-06-17 23:06:46 +08:00
|
|
|
|
this.DataContext = info;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void BacklogDone_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2021-07-18 20:10:19 +08:00
|
|
|
|
ToDoInfo info = this.DataContext as ToDoInfo;
|
2021-06-17 23:06:46 +08:00
|
|
|
|
info.DoneTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
2021-09-11 15:32:30 +08:00
|
|
|
|
if (info.ExecType == TodoTaskExecType.CRON)
|
|
|
|
|
|
{
|
|
|
|
|
|
CronExpression exp = new CronExpression(info.Cron);
|
2022-01-09 16:17:58 +08:00
|
|
|
|
DateTime nowTime = DateTime.Now;
|
2021-09-11 15:32:30 +08:00
|
|
|
|
|
2022-01-09 16:17:58 +08:00
|
|
|
|
//计算下次执行时间
|
|
|
|
|
|
DateTime nextTime = DateTime.SpecifyKind(exp.GetNextValidTimeAfter(nowTime).Value.LocalDateTime, DateTimeKind.Local);
|
|
|
|
|
|
|
|
|
|
|
|
string nextTimeStr = nextTime.ToString("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
info.ExeTime = nextTimeStr;
|
|
|
|
|
|
|
|
|
|
|
|
TimeSpan ts = nextTime.Subtract(nowTime);
|
2021-09-11 15:32:30 +08:00
|
|
|
|
int minutes = (int)Math.Ceiling(ts.TotalMinutes);
|
|
|
|
|
|
if (minutes < 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
minutes = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (minutes > 60)
|
|
|
|
|
|
{
|
|
|
|
|
|
int m = minutes % 60;
|
|
|
|
|
|
int h = minutes / 60;
|
|
|
|
|
|
Growl.SuccessGlobal("下次任务将在 " + h + " 小时零 " + m + " 分钟后提醒您!");
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Growl.SuccessGlobal("下次任务将在 " + minutes + " 分钟后提醒您!");
|
|
|
|
|
|
}
|
2022-01-09 16:17:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2021-09-11 15:32:30 +08:00
|
|
|
|
{
|
|
|
|
|
|
appData.ToDoList.Remove(info); //执行任务删除
|
|
|
|
|
|
appData.HiToDoList.Add(info); //添加历史任务
|
|
|
|
|
|
}
|
2021-07-18 20:10:19 +08:00
|
|
|
|
ToDoTask.activityBacklog[info].Close(); //关闭桌面通知
|
|
|
|
|
|
ToDoTask.activityBacklog.Remove(info);//激活任务删除
|
2021-06-17 23:06:46 +08:00
|
|
|
|
CommonCode.SaveAppData(appData);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 只允许输入数字
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
private void DelayTime_PreviewTextInput(object sender, TextCompositionEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
int textBoxInt;
|
|
|
|
|
|
//转化按下的键为数字,如果不是数字则会抓取到报错信息,不键入,反之则键入
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
textBoxInt = int.Parse($"{e.Text}");
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
|
{
|
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 失去焦点前如果为空
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
private void DelayTime_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
int textBoxInt;
|
|
|
|
|
|
//转化val为数字,如果不是数字则会抓取到报错信息
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
textBoxInt = int.Parse(DelayTime.Text.Trim());
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (FormatException)
|
|
|
|
|
|
{
|
|
|
|
|
|
DelayTime.Text = "10";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 推迟提醒
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
|
private void DelayButton_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
|
{
|
2021-07-18 20:10:19 +08:00
|
|
|
|
ToDoInfo info = this.DataContext as ToDoInfo;
|
2021-06-17 23:06:46 +08:00
|
|
|
|
int time = int.Parse(DelayTime.Text);
|
|
|
|
|
|
string type = DelayType.Text;
|
2022-01-09 16:17:58 +08:00
|
|
|
|
switch (type)
|
2021-06-17 23:06:46 +08:00
|
|
|
|
{
|
|
|
|
|
|
case "分":
|
|
|
|
|
|
info.ExeTime = DateTime.Now.AddMinutes(time).ToString("yyyy-MM-dd HH:mm:ss");
|
2021-09-11 15:32:30 +08:00
|
|
|
|
Growl.SuccessGlobal("将在 " + time + " 分钟后再次提醒您!");
|
2021-06-17 23:06:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
case "时":
|
|
|
|
|
|
info.ExeTime = DateTime.Now.AddHours(time).ToString("yyyy-MM-dd HH:mm:ss");
|
2021-09-11 15:32:30 +08:00
|
|
|
|
Growl.SuccessGlobal("将在 " + time + " 小时后再次提醒您!");
|
2021-06-17 23:06:46 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2021-07-18 20:10:19 +08:00
|
|
|
|
ToDoTask.activityBacklog[info].Close(); //关闭桌面通知
|
|
|
|
|
|
ToDoTask.activityBacklog.Remove(info);//激活任务删除
|
2021-05-31 17:31:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|