Create dabase service and start creation of models

This commit is contained in:
2026-01-03 20:17:45 -06:00
parent 3b4ed895c1
commit 2b4ca9436a
9 changed files with 91 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="splash_background">#FFFFFF</color>
<color name="splash_background">#1a1a1a</color>
</resources>

View File

@@ -0,0 +1,21 @@
using System;
using SQLite;
namespace CritterFolio.DataModels;
[Table("Critters")]
public class Critter
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string ProfileImagePath { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string Gender { get; set; } = string.Empty;
public DateTime DateOfBirth { get; set; }
public int FatherId { get; set; }
public int MotherId { get; set; }
public string Notes { get; set; } = string.Empty;
}

View File

@@ -0,0 +1,12 @@
using SQLite;
namespace CritterFolio.DataModels;
[Table("Documents")]
public class Document
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
}

View File

@@ -6,6 +6,6 @@
x:Class="CritterFolio.Pages.HomePage">
<StackPanel>
<Label>Home</Label>
<Button x:Name="TestBttn">Test</Button>
<Button x:Name="TestBttn" Classes="normal">Test</Button>
</StackPanel>
</UserControl>

View File

@@ -4,5 +4,12 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="CritterFolio.Pages.TestPage">
Test page!
<ScrollViewer VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
<StackPanel Spacing="5">
<Label FontSize="20" HorizontalAlignment="Stretch">Database operations</Label>
<Button HorizontalAlignment="Stretch" Classes="normal">Insert test data</Button>
<Button HorizontalAlignment="Stretch" Classes="normal">Clear database</Button>
<Button HorizontalAlignment="Stretch" Classes="normal">Re-init Database</Button>
</StackPanel>
</ScrollViewer>
</UserControl>

View File

@@ -0,0 +1,32 @@
using System;
using System.IO;
using System.Threading.Tasks;
using CritterFolio.DataModels;
using Microsoft.VisualBasic.FileIO;
using SQLite;
namespace CritterFolio.Services;
public static class DatabaseService
{
private static SQLiteAsyncConnection? _db;
public static async Task Init()
{
if (_db is not null) return;
var databasePath = Path.Combine(AppContext.BaseDirectory, "CritterFolio.db");
_db = new SQLiteAsyncConnection(databasePath);
Console.WriteLine(databasePath);
try
{
await _db.CreateTablesAsync<Critter, Document>();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}

View File

@@ -6,10 +6,6 @@
</Border>
</Design.PreviewWith>
<Style Selector="Window">
</Style>
<Style Selector="Button.headerBttn">
<Setter Property="FontFamily" Value="{DynamicResource Phosphor}"/>
<Setter Property="Background" Value="Transparent" />
@@ -20,4 +16,16 @@
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
<Style Selector="Button.normal">
<Setter Property="Background" Value="{DynamicResource AccentBackground}" />
<Setter Property="Foreground" Value="{DynamicResource PrimaryForeground}"/>
<Setter Property="MinWidth" Value="100"/>
<Setter Property="Height" Value="40"/>
<Setter Property="FontSize" Value="15"/>
<Setter Property="Padding" Value="10"></Setter>
<Setter Property="CornerRadius" Value="20"></Setter>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</Styles>

View File

@@ -16,7 +16,7 @@
<Grid RowDefinitions="Auto, *" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{DynamicResource PrimaryBackground}">
<critterFolio:Navigation Grid.Row="0" x:Name="Nav"/>
<ScrollViewer Grid.Row="1" x:Name="ScrollView" />
<ScrollViewer Grid.Row="1" x:Name="ScrollView" Margin="20"/>
</Grid>

View File

@@ -1,5 +1,6 @@
using Avalonia.Controls;
using CritterFolio.Pages;
using CritterFolio.Services;
namespace CritterFolio.Views;
@@ -11,5 +12,7 @@ public partial class MainView : UserControl
Sys.Navigation = Nav;
Nav.Init(ScrollView);
Nav.PushPage(new HomePage());
_ = DatabaseService.Init();
}
}