added the creation of a sqlite database locally - need to switch from saving to the txt to sqlite database

This commit is contained in:
Taarly 2025-04-15 09:14:46 +02:00
parent c7af174de5
commit 7d89cf2e87
11 changed files with 54 additions and 4 deletions

View File

@ -5,6 +5,10 @@
<ProjectReference Include="..\Project.Persistence\Project.Persistence.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>

View File

@ -6,4 +6,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,6 @@
namespace Project.Persistence;
public class CheckLogin
{
}

View File

@ -4,6 +4,10 @@
<ProjectReference Include="..\Project.Model\Project.Model.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>

View File

@ -0,0 +1,24 @@
using Microsoft.Data.Sqlite;
namespace Project.Persistence;
public class SQLite
{
private string _dbPath = "C:/Users/lowns/Desktop/logins.db";
public void Init()
{
using var connection = new SqliteConnection($"Data Source={_dbPath}");
connection.Open();
var command = connection.CreateCommand();
command.CommandText =
@"
CREATE TABLE IF NOT EXISTS logins (
loginname STRING PRIMARY KEY NOT NULL,
loginpass STRING NOT NULL,
loginemail STRING NOT NULL
);
";
command.ExecuteNonQuery();
}
}

View File

@ -1,7 +1,7 @@
using Project.Model;
namespace Project.Persistence;
public static class NewLoginStorage
public static class SaveNewLogin
{
private static readonly string FilePath = "C:/Users/lowns/desktop/users.txt";
public static void SaveUser(CreateLogin user)

View File

@ -1,6 +1,7 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using Project.Persistence;
namespace Project.View;
@ -16,6 +17,9 @@ public partial class App : Application
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
desktop.MainWindow = new MainWindow();
// Initialising the database that contains all the logins
var initdb = new SQLite();
initdb.Init();
}
base.OnFrameworkInitializationCompleted();

View File

@ -1,11 +1,13 @@
using Avalonia.Controls;
using Project.Controller;
using Project.Persistence;
namespace Project.View;
public partial class MainWindow : Window
{
readonly AppController _controller;
public AppController AppController {get {return _controller;}}
public MainWindow()
{

View File

@ -6,7 +6,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Border Background="SaddleBrown">
<Border Background="SandyBrown">
<StackPanel Orientation="Vertical">
<TextBlock

View File

@ -28,17 +28,18 @@ public partial class NewLogin : Window
string email = NewLoginEmailBox.Text?.Trim();
var user = new CreateLogin(username, password, email);
NewLoginStorage.SaveUser(user);
SaveNewLogin.SaveUser(user);
NewLoginUsernameBox.Text = "";
NewLoginPasswordBox.Text = "";
NewLoginEmailBox.Text = "";
Close();
}
private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)
{
Close();
}
}

View File

@ -18,6 +18,7 @@
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
</ItemGroup>
<ItemGroup>