public static async void AddTask(string description) { if (App.CurrentUserID != -1) { DateTime currentTime = DateTime.Now; // 上传一个起止时间相同的时间记录,表明有这个任务 TomatoTime time = new TomatoTime() { BeginTime = currentTime.ToString("yyyy-MM-dd HH:mm:ss"), EndTime = currentTime.ToString("yyyy-MM-dd HH:mm:ss"), UserId = App.StaticUser.UserId, Description = description, BeginTimeDate = currentTime.Date.ToShortDateString(), SpanString = currentTime.ToShortTimeString() + " → " + currentTime.ToShortTimeString() }; await App.TomatoTimeManager.AddTomatoTimeTaskAsync(time); await App.UserManager.ModifyUserTaskAsync(App.StaticUser); } TomatoTask tomatoTask = new TomatoTask(); tomatoTask.TaskName = description; tomatoTask.TimeRecords = new List <TomatoTime>(); tomatoTask.TotalTimes = new TimeSpan(); tasks.Insert(0, tomatoTask); RecordCountChanged(); }
public static void RefreshUserTasks() { var records = App.TomatoTimeManager.UserTomatoTimes; tasks.Clear(); foreach (var task in records) { TomatoTask tomatoTask = new TomatoTask(); tomatoTask.TaskName = task.Key; tomatoTask.TimeRecords = task.Value; tomatoTask.TotalTimes = new TimeSpan(); // 去掉占位的时间记录 for (int i = task.Value.Count - 1; i >= 0; i--) { var record = task.Value[i]; if (record.BeginTime == record.EndTime) { tomatoTask.TimeRecords.Remove(record); break; } } foreach (var record in task.Value) { tomatoTask.TotalTimes += Convert.ToDateTime(record.EndTime) - Convert.ToDateTime(record.BeginTime); } tasks.Add(tomatoTask); } RecordCountChanged(); }
public static void DeleteTask(TomatoTask task) { tasks.Remove(task); RecordCountChanged(); }