Skip to content

Commit 2a96c40

Browse files
committed
修改日程bug
1 parent 5fd5e07 commit 2a96c40

File tree

3 files changed

+46
-28
lines changed

3 files changed

+46
-28
lines changed

TimeControl/Data/Task.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,19 @@ public override string ToString()
3030
{
3131
return Name + " (" + Duration.Minutes + "min)";
3232
}
33-
34-
public void RunTask()
33+
/// <summary>
34+
///
35+
/// </summary>
36+
/// <returns>If the task is ended</returns>
37+
public bool RunTask()
3538
{
39+
bool res = false;
3640
startTime = DateTime.Now;
3741
if (IsFocus)
3842
{
3943
LockHelper.StartLock(Password.unlockPasswordHash, (int)Duration.TotalMinutes);
44+
EndTask();
45+
res = true;
4046
}
4147
else if (IsDeepFocus)
4248
{
@@ -45,11 +51,13 @@ public void RunTask()
4551
else
4652
{
4753
MessageBox.Show(
48-
"任务已启动。该日程不需要启动任何计算机操作,请自行完成,预估时间" + Duration + "min");
54+
"任务已启动。该日程不需要启动任何计算机操作,请自行完成,预估时间", "提示"
55+
+ Duration + "min", MessageBoxButtons.OK, MessageBoxIcon.Information);
4956
}
57+
return res;
5058
}
5159

52-
public string EndTask()
60+
private string EndTaskString()
5361
{
5462
if (startTime == new DateTime(0))
5563
{
@@ -58,5 +66,10 @@ public string EndTask()
5866
endTime = DateTime.Now;
5967
return ToString() + "(实际" + (endTime - startTime) + ")";
6068
}
69+
public void EndTask()
70+
{
71+
MessageBox.Show(EndTaskString(),
72+
"任务结束", MessageBoxButtons.OK, MessageBoxIcon.Information);
73+
}
6174
}
6275
}

TimeControl/Tools/LockHelper.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
using System;
22
using System.IO;
33
using System.Windows.Forms;
4+
using TimeControl.Data;
45
using TimeControl.Windows;
56

67
namespace TimeControl.Tools
78
{
89
internal class LockHelper
910
{
11+
public static TimeData TimeData;
1012
public static void StartLock(string unlockPasswordHash, int minutes)
1113
{
1214
IntPtr nowDesktop = Dllimport.GetThreadDesktop(Dllimport.GetCurrentThreadId());
@@ -24,6 +26,7 @@ public static void StartLock(string unlockPasswordHash, int minutes)
2426
}).Wait();
2527
Dllimport.SwitchDesktop(nowDesktop);
2628
Dllimport.CloseDesktop(newDesktop);
29+
ShowAndSave(Lock.TempTimeSpan);
2730
}
2831

2932
public static void Interrupt()
@@ -48,5 +51,12 @@ public static void StartDeepLock(int minutes)
4851
SystemControl.Shutdown();
4952
Application.Exit();
5053
}
54+
public static void ShowAndSave(TimeSpan timeSpan)
55+
{
56+
ResultWindow resultWindow = new(timeSpan);
57+
resultWindow.ShowDialog();
58+
if (ResultWindow.IsSave == true)
59+
TimeData.AddTime(timeSpan);
60+
}
5161
}
5262
}

TimeControl/Windows/ControlPanel.cs

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public partial class ControlPanel : Form
1717
private bool isClosable = false;
1818

1919
private AppController appController;//Controller for list and apps.
20-
private TimeData timeData;//The data of current aim.
2120
private bool isLoaded;//Show the state of initialization.
2221
private bool isChangeable = true;
2322
private List<Data.Task> tasks;
@@ -163,8 +162,7 @@ private void EndTaskButton_Click(object sender, EventArgs e)
163162
{
164163
if (taskListBox.SelectedIndex >= 0)
165164
{
166-
MessageBox.Show(tasks[taskListBox.SelectedIndex].EndTask(),
167-
"任务结束", MessageBoxButtons.OK, MessageBoxIcon.Information);
165+
tasks[taskListBox.SelectedIndex].EndTask();
168166
tasks.RemoveAt(taskListBox.SelectedIndex);
169167
}
170168
RefreshTasks();
@@ -174,7 +172,11 @@ private void TaskStartButton_Click(object sender, EventArgs e)
174172
{
175173
if (taskListBox.SelectedIndex >= 0)
176174
{
177-
tasks[taskListBox.SelectedIndex].RunTask();
175+
if (tasks[taskListBox.SelectedIndex].RunTask())
176+
{
177+
tasks.RemoveAt(taskListBox.SelectedIndex);
178+
}
179+
RefreshTasks();
178180
}
179181
}
180182

@@ -202,18 +204,11 @@ private void StartLock(string unlockPasswordHash, int minutes = 0)
202204
{
203205
LockHelper.StartLock(unlockPasswordHash, minutes);
204206
int index = dataGridView.Rows.Add();
205-
ShowAndSave(Lock.TempTimeSpan);
206-
}
207-
208-
private void ShowAndSave(TimeSpan timeSpan)
209-
{
210-
ResultWindow resultWindow = new(timeSpan);
211-
resultWindow.ShowDialog();
212-
if (ResultWindow.IsSave == true)
213-
timeData.AddTime(timeSpan);
214207
RefreshAndSaveData();
215208
}
216209

210+
211+
217212
private void WhiteProcessBox_TextChanged(object sender, EventArgs e)
218213
{
219214
File.WriteAllText(TCFile.WhiteAppLocation, whiteProcessBox.Text);
@@ -238,7 +233,7 @@ private void InitializeDeepFocus()
238233
else
239234
{
240235
File.Delete(TCFile.DeepTempTimeFile);
241-
ShowAndSave(deepFocusTime);
236+
LockHelper.ShowAndSave(deepFocusTime);
242237
RefreshAndSaveData();
243238
}
244239
}
@@ -541,13 +536,13 @@ private void InitializeData()
541536
{
542537
if (File.Exists(TCFile.SavedData))
543538
{
544-
timeData = TCFile.ReadTimeData();
539+
LockHelper.TimeData = TCFile.ReadTimeData();
545540
RefreshAndSaveData();
546541
}
547542
else
548543
{
549544
Directory.CreateDirectory(TCFile.SavedDataDir);
550-
timeData = new() { GoalName = "FirstGoal" };
545+
LockHelper.TimeData = new() { GoalName = "FirstGoal" };
551546
RefreshAndSaveData();
552547
}
553548
}
@@ -557,23 +552,23 @@ private void RefreshAndSaveData()
557552
//刷新列表
558553
//普通屏保
559554
dataGridView.Rows.Clear();
560-
dataGridView.Rows.Add(timeData.LockTime, "普通屏保");
555+
dataGridView.Rows.Add(LockHelper.TimeData.LockTime, "普通屏保");
561556
//深度专注屏保
562-
dataGridView.Rows.Add(timeData.DeepLockTime, "深度专注屏保");
557+
dataGridView.Rows.Add(LockHelper.TimeData.DeepLockTime, "深度专注屏保");
563558
//更新进度
564-
ShowProgress(timeData);
559+
ShowProgress();
565560
//保存
566-
TCFile.SaveTimeData(timeData);
561+
TCFile.SaveTimeData(LockHelper.TimeData);
567562
}
568563

569564
#endregion DataPage
570565

571566
#region ProgressPage
572567

573-
private void ShowProgress(TimeData timeData)
568+
private void ShowProgress()
574569
{
575-
goalLabel.Text = timeData.GoalName;
576-
TimeSpan timeSpan = timeData.GetTimeSum();
570+
goalLabel.Text = LockHelper.TimeData.GoalName;
571+
TimeSpan timeSpan = LockHelper.TimeData.GetTimeSum();
577572
int level = 1;
578573
TimeSpan targetTimeSpan = new(0, 0, 0);
579574
while (level < 100)
@@ -593,7 +588,7 @@ private void ShowProgress(TimeData timeData)
593588
progressBar.Value = Convert.ToInt32((timeSpan / targetTimeSpan) * 100);
594589
if (level == 100)
595590
{
596-
encourageLabel.Text = "恭喜通关!你可以通过删除TimeControl文件夹里的SavedData.xml来重新开始!";
591+
encourageLabel.Text = "恭喜通关!你可以通过新建目标来重新开始!";
597592
progressLabel.Visible = false;
598593
progressBar.Value = 100;
599594
}

0 commit comments

Comments
 (0)