Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 6da3432

Browse files
committed
Added overdue notification
1 parent 878d701 commit 6da3432

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

AssignmentReminder/AssignmentList.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public AssignmentList()
3131
foreach ( string dates in due )
3232
{
3333
DateTime date = DateTime.FromBinary( long.Parse( dates ) );
34+
TimeSpan daysleft = date.Date - DateTime.Today;
3435
if ( date.Date == DateTime.Today )
3536
{
3637
ListViewItem.ListViewSubItem color = new ListViewItem.ListViewSubItem();
@@ -39,7 +40,7 @@ public AssignmentList()
3940
listView.Items[count].BackColor = Color.Red;
4041
listView.Items[count].SubItems.Add( color );
4142
}
42-
else if ( ( date.Date - DateTime.Today ).TotalDays <= 2 )
43+
else if ( daysleft.TotalDays <= 2 && daysleft.TotalDays > 0 )
4344
{
4445
ListViewItem.ListViewSubItem color = new ListViewItem.ListViewSubItem();
4546
Color lambdaorange = Color.FromArgb( 255, 255, 89, 0 );
@@ -48,6 +49,15 @@ public AssignmentList()
4849
listView.Items[count].BackColor = lambdaorange;
4950
listView.Items[count].SubItems.Add( color );
5051
}
52+
else if ( daysleft.TotalDays < 0 )
53+
{
54+
ListViewItem.ListViewSubItem color = new ListViewItem.ListViewSubItem();
55+
color.BackColor = Color.Red;
56+
color.Text = date.ToString();
57+
listView.Items[count].Text = "!!! " + listView.Items[count].Text + " !!!";
58+
listView.Items[count].BackColor = Color.Red;
59+
listView.Items[count].SubItems.Add( color );
60+
}
5161
else
5262
{
5363
listView.Items[count].SubItems.Add( date.ToString() );
@@ -84,18 +94,29 @@ private void ColumnClick( object sender, ColumnClickEventArgs e )
8494
listView.Sort();
8595
}
8696

97+
private string FormatText( string text )
98+
{
99+
if ( text.StartsWith( "!!!" ) )
100+
{
101+
string trim = text.Trim( new char[] { '!' } );
102+
string nospace = trim.Trim();
103+
return nospace;
104+
}
105+
return text;
106+
}
107+
87108
private void DoubleClicked( object sender, EventArgs e )
88109
{
89110
DialogResult confirm = MessageBox.Show( "Are you sure you want to delete this assignment?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question );
90111
if ( confirm == DialogResult.Yes )
91112
{
92113
foreach ( ListViewItem selected in listView.SelectedItems )
93114
{
94-
selected.Remove();
95115
XDocument settings = XDocument.Load( path );
96-
List<XElement> ancestors = settings.Descendants().Where( x => ( string ) x == selected.Text ).Ancestors().ToList();
116+
List<XElement> ancestors = settings.Descendants().Where( x => ( string ) x == FormatText( selected.Text ) ).Ancestors().ToList();
97117
for ( int i=0; i <= ancestors.Count - 2; i++ )
98118
ancestors[i].Remove();
119+
selected.Remove();
99120
settings.Save( path );
100121
}
101122
}

AssignmentReminder/AssignmentReminder.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,31 @@ private static void DueNotify( NotifyIcon notify )
6060
bool duetoday = false;
6161
int dueamount = 0;
6262
int duesoon = 0;
63+
int overdue = 0;
6364

6465
foreach ( string dates in assignment )
6566
{
6667
DateTime date = DateTime.FromBinary( long.Parse( dates ) );
68+
TimeSpan daysleft = date.Date - DateTime.Today;
6769
if ( date.Date == DateTime.Today )
6870
{
6971
duetoday = true;
7072
dueamount++;
7173
}
72-
if ( ( date.Date - DateTime.Today ).TotalDays <= 2 )
74+
if ( daysleft.TotalDays <= 2 && daysleft.TotalDays > 0 )
7375
duesoon++;
76+
if ( daysleft.TotalDays < 0 )
77+
overdue++;
7478
}
7579

7680
if ( duetoday && dueamount > 0 )
7781
notify.ShowBalloonTip( 1, "Assignments Due", "You have " + dueamount.ToString() + " assignment(s) due today. Click to view them.", ToolTipIcon.Info );
7882
else
7983
{
80-
if ( duesoon > 0 )
81-
notify.ShowBalloonTip( 1, "No Assignments Due", "You have no assignments due today. You have " + duesoon.ToString() + " assignments due soon.", ToolTipIcon.Info );
84+
if ( overdue > 0 )
85+
notify.ShowBalloonTip( 1, "No Assignments Due", "You have no assignments due today. You have " + overdue.ToString() + " overdue assignment(s).", ToolTipIcon.Info );
86+
else if ( duesoon > 0 )
87+
notify.ShowBalloonTip( 1, "No Assignments Due", "You have no assignments due today. You have " + duesoon.ToString() + " assignment(s) due soon.", ToolTipIcon.Info );
8288
else
8389
notify.ShowBalloonTip( 1, "No Assignments Due", "You have no assignments due today.", ToolTipIcon.Info );
8490
}

0 commit comments

Comments
 (0)