Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*.user
*.userosscache
*.sln.docstates
*.db

# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
Expand Down
31 changes: 31 additions & 0 deletions DataConnection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Microsoft.Data.Sqlite;

namespace Habit_Tracker_App;

public class DataConnection
{
static string databaseName = "Habit-Tracker";
string tableName = "drinking_water";
static string connectionString = $"Data Source={databaseName}.db";
public DataConnection()
{
CreateTable();
}
public void CreateTable()
{
using (var conn = new SqliteConnection(connectionString))
{
conn.Open();
var tableCmd = conn.CreateCommand();

tableCmd.CommandText = @$"CREATE TABLE IF NOT EXISTS {tableName}(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Date TEXT,
Quantity INTEGER
)";

tableCmd.ExecuteNonQuery();
conn.Close();
}
}
}
Binary file added Habit-Tracker.db
Binary file not shown.
8 changes: 8 additions & 0 deletions Habit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Habit_Tracker_App;

internal class Habit
{
public int HabitId { get; set; }
public required string Date { get; set; }
public int Quantity { get; set; }
}
3 changes: 3 additions & 0 deletions Habit_Tracker.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Solution>
<Project Path="Habit_Tracker_App/Habit_Tracker_App.csproj" />
</Solution>
21 changes: 21 additions & 0 deletions Habit_Tracker_App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0" />
<PackageReference Include="Spectre.Console" Version="0.54.0" />
</ItemGroup>

<ItemGroup>
<None Update="Habit-Tracker.db">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions Habit_Tracker_App.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
VisualStudioVersion = 18.0.11222.15 d18.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Habit_Tracker_App", "Habit_Tracker_App.csproj", "{030116D8-7B25-5231-1781-6774979F91DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{030116D8-7B25-5231-1781-6774979F91DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{030116D8-7B25-5231-1781-6774979F91DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{030116D8-7B25-5231-1781-6774979F91DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{030116D8-7B25-5231-1781-6774979F91DA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C7362BB7-ADA6-47C2-9FC5-2E3BD7EC1258}
EndGlobalSection
EndGlobal
52 changes: 52 additions & 0 deletions MenuUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Spectre.Console;

namespace Habit_Tracker_App;
public static class MenuUI
{
public static void WelcomeMessage()
{
AnsiConsole.MarkupLine("[bold orange3]Welcome to the Habit Tracker Application![/]\n");
AnsiConsole.MarkupLine("[bold orange3]In this application you will manage the drinking water habit. To Continue, please press Enter... [/]");
Console.ReadKey();
}
public static string GetMenuChoice()
{
Console.Clear();
string userInput;

while (true)
{
var menuTitle = new Rule("[bold orange3]Main Menu[/]");
menuTitle.Justification = Justify.Left;
AnsiConsole.Write(menuTitle);
Console.WriteLine();
AnsiConsole.MarkupLine($"[green]1[/] - Add an entry");
AnsiConsole.MarkupLine($"[green]2[/] - View saved entries");
AnsiConsole.MarkupLine($"[green]3[/] - Update an entry");
AnsiConsole.MarkupLine($"[green]4[/] - Delete an entry");
AnsiConsole.MarkupLine($"[red]X[/] - Exit the application");
AnsiConsole.Markup("[green]Your Selection: [/]");
userInput = Console.ReadLine().ToLower();

switch (userInput)
{
case "1":
case "2":
case "3":
case "4":
case "x":
return userInput;
default:
AnsiConsole.MarkupLine("[red]Invalid entry. Please type a [/][green]menu choice[/]");
break;
}
}
}
public static void AddSpace(int number)
{
for (int i = 0; i < number; i++)
{
Console.WriteLine();
}
}
}
Loading