-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
139 lines (118 loc) · 4.94 KB
/
Copy pathProgram.cs
File metadata and controls
139 lines (118 loc) · 4.94 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
using System.Reflection.Metadata;
DatabaseManager db = new DatabaseManager();
// Runs on every startup — creates the database and table
// if they don't already exist. Safe to call every time.
db.InitialiseDatabase();
bool isRunning = true;
ShowWelcome();
while (isRunning)
{
Console.Clear();
Console.WriteLine("╔══════════════════════════════╗");
Console.WriteLine("║ HABIT LOGGER ║");
Console.WriteLine("║ 💧 Water Intake Tracker ║");
Console.WriteLine("╠══════════════════════════════╣");
Console.WriteLine("║ 1. Log Water Intake ║");
Console.WriteLine("║ 2. View All Entries ║");
Console.WriteLine("║ 3. Update an Entry ║");
Console.WriteLine("║ 4. Delete an Entry ║");
Console.WriteLine("║ 0. Exit ║");
Console.WriteLine("╚══════════════════════════════╝");
Console.Write("\n Choose an option: ");
string choice = Console.ReadLine()?.Trim();
switch (choice)
{
case "1":
LogEntry(db);
break;
case "2":
ViewEntries(db);
break;
case "3":
UpdateEntry(db);
break;
case "4":
DeleteEntry(db);
break;
case "0":
isRunning = false;
ShowGoodbye();
break;
default:
Console.WriteLine("\n ⚠️ Invalid option. Please choose 0 - 4.");
Thread.Sleep(1500);
break;
}
}
// ============================================================
// WELCOME SCREEN
// ============================================================
void ShowWelcome()
{
Console.Clear();
Console.WriteLine("╔══════════════════════════════╗");
Console.WriteLine("║ WELCOME TO ║");
Console.WriteLine("║ HABIT LOGGER ║");
Console.WriteLine("╠══════════════════════════════╣");
Console.WriteLine("║ Track your daily water ║");
Console.WriteLine("║ intake. Data is stored in ║");
Console.WriteLine("║ a real SQLite database. ║");
Console.WriteLine("╚══════════════════════════════╝");
Console.WriteLine("\n Press any key to start...");
Console.ReadKey();
}
// ============================================================
// GOODBYE SCREEN
// ============================================================
void ShowGoodbye()
{
Console.Clear();
Console.WriteLine("╔══════════════════════════════╗");
Console.WriteLine("║ GOODBYE! ║");
Console.WriteLine("╠══════════════════════════════╣");
Console.WriteLine("║ Your data is safely stored ║");
Console.WriteLine("║ in habitlogger.db ║");
Console.WriteLine("╚══════════════════════════════╝");
Thread.Sleep(2000);
}
// ============================================================
// PLACEHOLDER METHODS — filled in Steps 3 and 4
// ============================================================
void LogEntry(DatabaseManager database)
{
Console.Clear();
Console.WriteLine("╔══════════════════════════════╗");
Console.WriteLine("║ LOG WATER INTAKE ║");
Console.WriteLine("╚══════════════════════════════╝");
UserInterface ui = new UserInterface();
string date = ui.GetDate();
int quantity = ui.GetQuantity();
// Pass the clean values to DatabaseManager to save
database.InsertEntry(date, quantity);
Console.WriteLine("\n Entry saved successfully!");
Console.WriteLine("\n Press any key to return...");
Console.ReadKey();
}
void ViewEntries(DatabaseManager database)
{
// Ask DatabaseManager for the data
List<HabitEntry> entries = database.GetAllEntries();
// Pass the data to UserInterface to display
UserInterface ui = new UserInterface();
ui.DisplayEntries(entries);
Console.WriteLine("\n Press any key to return...");
Console.ReadKey();
}
void UpdateEntry(DatabaseManager database)
{
Console.Clear();
Console.WriteLine(" Update Entry — coming in Step 4");
Console.ReadKey();
}
void DeleteEntry(DatabaseManager database)
{
Console.Clear();
Console.WriteLine(" Delete Entry — coming in Step 4");
Console.ReadKey();
}