added the creation of a sqlite database locally - need to switch from saving to the txt to sqlite database
This commit is contained in:
parent
c7af174de5
commit
7d89cf2e87
@ -5,6 +5,10 @@
|
|||||||
<ProjectReference Include="..\Project.Persistence\Project.Persistence.csproj" />
|
<ProjectReference Include="..\Project.Persistence\Project.Persistence.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
|||||||
@ -6,4 +6,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
6
Project.Persistence/CheckLogin.cs
Normal file
6
Project.Persistence/CheckLogin.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace Project.Persistence;
|
||||||
|
|
||||||
|
public class CheckLogin
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@ -4,6 +4,10 @@
|
|||||||
<ProjectReference Include="..\Project.Model\Project.Model.csproj" />
|
<ProjectReference Include="..\Project.Model\Project.Model.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
|||||||
24
Project.Persistence/SQLite.cs
Normal file
24
Project.Persistence/SQLite.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
using Project.Model;
|
using Project.Model;
|
||||||
namespace Project.Persistence;
|
namespace Project.Persistence;
|
||||||
|
|
||||||
public static class NewLoginStorage
|
public static class SaveNewLogin
|
||||||
{
|
{
|
||||||
private static readonly string FilePath = "C:/Users/lowns/desktop/users.txt";
|
private static readonly string FilePath = "C:/Users/lowns/desktop/users.txt";
|
||||||
public static void SaveUser(CreateLogin user)
|
public static void SaveUser(CreateLogin user)
|
||||||
@ -1,6 +1,7 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Project.Persistence;
|
||||||
|
|
||||||
namespace Project.View;
|
namespace Project.View;
|
||||||
|
|
||||||
@ -16,6 +17,9 @@ public partial class App : Application
|
|||||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||||
{
|
{
|
||||||
desktop.MainWindow = new MainWindow();
|
desktop.MainWindow = new MainWindow();
|
||||||
|
// Initialising the database that contains all the logins
|
||||||
|
var initdb = new SQLite();
|
||||||
|
initdb.Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
base.OnFrameworkInitializationCompleted();
|
base.OnFrameworkInitializationCompleted();
|
||||||
|
|||||||
@ -1,11 +1,13 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Project.Controller;
|
using Project.Controller;
|
||||||
|
using Project.Persistence;
|
||||||
|
|
||||||
namespace Project.View;
|
namespace Project.View;
|
||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
readonly AppController _controller;
|
readonly AppController _controller;
|
||||||
|
|
||||||
public AppController AppController {get {return _controller;}}
|
public AppController AppController {get {return _controller;}}
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -6,7 +6,7 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|
||||||
<Border Background="SaddleBrown">
|
<Border Background="SandyBrown">
|
||||||
|
|
||||||
<StackPanel Orientation="Vertical">
|
<StackPanel Orientation="Vertical">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
|||||||
@ -28,17 +28,18 @@ public partial class NewLogin : Window
|
|||||||
string email = NewLoginEmailBox.Text?.Trim();
|
string email = NewLoginEmailBox.Text?.Trim();
|
||||||
|
|
||||||
var user = new CreateLogin(username, password, email);
|
var user = new CreateLogin(username, password, email);
|
||||||
NewLoginStorage.SaveUser(user);
|
SaveNewLogin.SaveUser(user);
|
||||||
|
|
||||||
|
|
||||||
NewLoginUsernameBox.Text = "";
|
NewLoginUsernameBox.Text = "";
|
||||||
NewLoginPasswordBox.Text = "";
|
NewLoginPasswordBox.Text = "";
|
||||||
NewLoginEmailBox.Text = "";
|
NewLoginEmailBox.Text = "";
|
||||||
|
|
||||||
|
Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)
|
private void NewLoginCancelOnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,6 +18,7 @@
|
|||||||
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
|
||||||
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Data.Sqlite" Version="10.0.0-preview.3.25171.6" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user