Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
197 lines (161 loc) · 5.61 KB
/
Copy pathProgram.cs
File metadata and controls
197 lines (161 loc) · 5.61 KB
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
using System.Net;
using Microsoft.Data.Sqlite;
public class Program
{
public static void Main(string[] args)
{
DBHelper.InitializeDB();
Program p = new Program();
p.MainMenu();
}
public void MainMenu()
{
int choice;
// int.TryParse(Console.ReadLine(), out choice);
{
while (true)
{
Console.WriteLine("Select an Option:\n");
Console.WriteLine("""
[1] Habits
[2] Occurrences
""");
choice = Utilities.ReadInt(Console.ReadLine());
switch (choice)
{
case 1:
HabitsMenu();
break;
case 2:
OccurrencesMenu();
break;
default:
Console.WriteLine("Please enter a valid option\n");
break;
}
}
}
}
public void HabitsMenu()
{
int choice;
bool running = true;
while (running)
{
Console.WriteLine("""
[1] View Habits
[2] Add Habits
[3] Delete Habits
[0] Return To Main Menu
""");
choice = Utilities.ReadInt(Console.ReadLine());
switch (choice)
{
case 1:
var habitlist = DBHelper.GetHabits();
foreach (Habit habit in habitlist)
{
Console.WriteLine(habit.id + " --- " + habit.name);
}
break;
case 2:
var HabitToAdd = Utilities.ReadString("Enter habit name:");
DBHelper.InsertHabit(HabitToAdd);
break;
case 3:
var HabitToDelete = Utilities.ReadString("Enter habit name:");
DBHelper.DeleteHabit(HabitToDelete);
break;
case 0:
running = false;
break;
}
MainMenu();
}
}
public void OccurrencesMenu()
{
int choice;
bool running = true;
while (running)
{
Console.WriteLine("""
[1] View Today's Occurrences
[2] Add Occurrence
[3] Delete Occurrence
[4] View ALL Occurrences
[0] Return To Main Menu
""");
choice = Utilities.ReadInt(Console.ReadLine());
switch (choice)
{
case 1:
List<Occurrence> occurrences1 = DBHelper.GetOccurrences();
occurrences1 = occurrences1.Where(o => o.Date.Date == DateTime.Today).ToList();
foreach (Occurrence o in occurrences1)
{
Console.WriteLine(o.HabitName + "---" + o.Date);
}
break;
case 2:
List<Habit> habits = DBHelper.GetHabits();
foreach (Habit h in habits)
{
Console.WriteLine(h.id + "---" + h.name);
}
int HabitChoice;
while (true)
{
HabitChoice = Utilities.ReadInt("Enter the ID of the habit that occurred:");
if (!(habits.Any(h => h.id == HabitChoice)))
{
Console.WriteLine("Invalid Option. Please try again:");
continue;
}
else
{
break;
}
}
Console.WriteLine("Enter the date/time this habit occurred: (leave empty for right now)");
var OccurrenceDateTime = Utilities.ReadDate(Console.ReadLine());
DBHelper.AddOccurrence(HabitChoice, OccurrenceDateTime);
break;
case 3:
List<Occurrence> occurrences3 = DBHelper.GetOccurrences();
foreach (Occurrence o in occurrences3)
{
Console.WriteLine(o.id + "---" + o.HabitName + "---" + o.Date);
}
while (true)
{
Console.WriteLine("Enter the ID of the occurrence you would like to delete: ");
int OccurrenceToDelete = Utilities.ReadInt(Console.ReadLine());
if ((occurrences3.Any(o => o.id == OccurrenceToDelete)))
{
DBHelper.DeleteOccurrence(OccurrenceToDelete);
break;
}
else
{
Console.WriteLine("Invalid Option. Please Try Again");
}
}
break;
case 4:
List<Occurrence> occurrences2 = DBHelper.GetOccurrences();
foreach (Occurrence o in occurrences2)
{
Console.WriteLine(o.HabitName + "---" + o.Date);
}
break;
case 0:
running = false;
break;
default:
Console.WriteLine("Invalid Input. Please Try Again:");
break;
}
}
}
}