-
Notifications
You must be signed in to change notification settings - Fork 2
/
Reminder.cs
177 lines (158 loc) · 6.05 KB
/
Reminder.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Reminder_desktop_application
{
public partial class Reminder : MetroFramework.Forms.MetroForm
{
/* TODO:
* Lazy
*/
public TaskControler taskControler = new TaskControler(new FileStreamer(), new NotificationControler());
public List<Task> allDayTaks;
public Dictionary<string, List<Task>> tasksForEeachDay;
public Task taskToNotify;
public Reminder()
{
InitializeComponent();
taskControler.TaskAppeared += SubscribeForNotification;
taskControler.LoadTasks();
PrintDayTasks(DateTime.Now.ToShortDateString());
}
private void addLink_Click(object sender, EventArgs e)
{
Form NewTaskForm = new NewTaskForm(taskControler, reminderDateTime.Value);
NewTaskForm.ShowDialog();
reminderTabControl.SelectedTab = homeTab;
PrintDayTasks(reminderDateTime.Value.ToShortDateString());
}
private void Reminder_FormClosing(object sender, FormClosingEventArgs e)
{
taskControler.Stop();
this.notificationIcon.Dispose();
Application.Exit();
}
private void deleteLink_Click(object sender, EventArgs e)
{
if (reminderTasksView.SelectedItems.Count == 1)
{
DialogResult result = MessageBox.Show("Are you sure?", "Delete", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
try
{
Task temp = (Task)reminderTasksView.SelectedItems[0].Tag;
taskControler.Remove(temp);
PrintDayTasks(temp.StartingDate.ToShortDateString());
}
catch(RemoveTaskException exp)
{
MessageBox.Show(exp.ToString());
}
}
}
}
private void doneLink_Click(object sender, EventArgs e)
{
deleteLink_Click(sender, e);
}
private void Reminder_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
this.Hide();
}
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void ShootOutNotification(object sender, EventArgs e)
{
taskToNotify = (Task)sender;
notificationIcon.BalloonTipTitle = this.Text;
notificationIcon.BalloonTipText = taskToNotify.ReminderText;
notificationIcon.ShowBalloonTip(5000);
}
private void notificationIcon_MouseDoubleClick(object sender, MouseEventArgs e)
{
this.Show();
this.WindowState = FormWindowState.Normal;
}
private void notificationIcon_BalloonTipClicked(object sender, EventArgs e)
{
TaskNotification notificationForm = new TaskNotification(taskToNotify, taskControler);
notificationForm.FormClosing += notificationForm_FormClosing;
notificationForm.Show();
notificationForm.WindowState = FormWindowState.Normal;
}
private void SubscribeForNotification(Task task)
{
task.TaskStarted += ShootOutNotification;
}
private void PrintDayTasks(string date)
{
reminderTasksView.Items.Clear();
if (taskControler.DailyTasks.Count != 0)
{
foreach (Task task in taskControler.DailyTasks)
{
PrintingTheTask(task);
}
}
if (taskControler.AllDays.Contains(date))
{
allDayTaks = taskControler.AllTasks[date];
foreach (Task task in allDayTaks)
{
PrintingTheTask(task);
}
}
}
private void PrintingTheTask(Task task)
{
ListViewItem taskForList = new ListViewItem();
taskForList.Text = task.StartingTime.ToString(@"hh\:mm");
taskForList.SubItems.Add(task.ReminderText);
taskForList.Tag = task;
reminderTasksView.Items.Add(taskForList);
}
private void reminderDateTime_ValueChanged(object sender, EventArgs e)
{
PrintDayTasks(reminderDateTime.Value.ToShortDateString());
}
private void reminderTasksView_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (reminderTasksView.SelectedItems.Count == 1)
{
reminderTabControl.SelectedTab = taskDetailsTab;
Task temp = (Task)reminderTasksView.SelectedItems[0].Tag;
taskDetailsTab.Tag = temp;
taskDetailsTab.Text = detailsLabel.Text;
detailsBox.Text = temp.ReminderText;
timeLabel.Text = temp.StartingDate.ToShortDateString() + " " + reminderTasksView.SelectedItems[0].Text;
}
}
private void notificationForm_FormClosing(object sender, EventArgs e)
{
PrintDayTasks(DateTime.Now.ToShortDateString());
}
private void editButton_Click(object sender, EventArgs e)
{
Form NewTaskForm = new NewTaskForm(taskControler, reminderDateTime.Value, detailsBox.Text);
NewTaskForm.ShowDialog();
taskControler.Remove((Task)taskDetailsTab.Tag);
reminderTabControl.SelectedTab = homeTab;
PrintDayTasks(reminderDateTime.Value.ToShortDateString());
}
private void reminderDateTime_Enter(object sender, EventArgs e)
{
System.Windows.Forms.SendKeys.Send("%{DOWN}");
}
}
}