-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInput.cs
More file actions
101 lines (78 loc) · 2.93 KB
/
Copy pathUserInput.cs
File metadata and controls
101 lines (78 loc) · 2.93 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
using Spectre.Console;
using System.Globalization;
namespace CodingTracker;
internal class UserInput
{
internal void Menu()
{
CRUD.CreateDB();
bool closeApp = true;
while (closeApp)
{
var menu = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("What do you want to do with the records?")
.PageSize(10)
.MoreChoicesText("[grey](Move up and down to select an option)[/]")
.AddChoices(new[] {
"View All", "Add",
"Delete", "Update",
"Leave",
}));
switch (menu)
{
case "Leave":
AnsiConsole.MarkupLine("[chartreuse2]Bye![/]");
closeApp = false;
break;
case "View All":
CRUD.ViewRecords();
break;
case "Add":
CRUD.AddToTable();
break;
case "Delete":
CRUD.DeleteRecords();
break;
case "Update":
CRUD.UpdateRecords();
break;
default:
AnsiConsole.MarkupLine("[red]That's not a valid option![/]");
break;
}
}
}
internal static DateOnly GetDate()
{
string? date = AnsiConsole.Ask<string>("[darkturquoise]Please input the date[/] [red](Format dd-MM-yy)[/]:");
DateOnly Date;
while (!DateOnly.TryParseExact(date, "dd-MM-yy", new CultureInfo("en-US"), DateTimeStyles.None, out Date))
{
date = AnsiConsole.Ask<string>("[darkturquoise]Invalid date,please try again[/] [red](Format dd-MM-yy)[/]:");
}
return Date;
}
internal static TimeSpan[] GetTime()
{
string? start = AnsiConsole.Ask<string>("[darkturquoise]Please input your start time[/] [red](Format hh:mm)[/]:");
string? end = AnsiConsole.Ask<string>("[darkturquoise]Please input your end time[/] [red](Format hh:mm)[/]:");
TimeSpan startTime;
TimeSpan endTime;
while (!TimeSpan.TryParseExact(start, "g", new CultureInfo("en-US"),TimeSpanStyles.None, out startTime))
{
start = AnsiConsole.Ask<string>("[darkturquoise]Incorrect start time, Please try again[/] [red](Format hh:mm)[/]:");
}
while (!TimeSpan.TryParseExact(end, "g", new CultureInfo("en-US"), TimeSpanStyles.None, out endTime))
{
end = AnsiConsole.Ask<string>("[darkturquoise]Incorrect end time, Please try again[/] [red](Format hh:mm)[/]:");
}
return new TimeSpan[] { startTime, endTime };
}
internal static int GetId()
{
CRUD.ViewRecords();
string? id = AnsiConsole.Ask<string>("Type the Id of the record you want: ");
return Convert.ToInt32(id);
}
}