Create dabase service and start creation of models
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<color name="splash_background">#FFFFFF</color>
|
<color name="splash_background">#1a1a1a</color>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
21
critterfolio/CritterFolio/CritterFolio/DataModels/Critter.cs
Normal file
21
critterfolio/CritterFolio/CritterFolio/DataModels/Critter.cs
Normal 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;
|
||||||
|
}
|
||||||
@@ -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; }
|
||||||
|
}
|
||||||
@@ -6,6 +6,6 @@
|
|||||||
x:Class="CritterFolio.Pages.HomePage">
|
x:Class="CritterFolio.Pages.HomePage">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Label>Home</Label>
|
<Label>Home</Label>
|
||||||
<Button x:Name="TestBttn">Test</Button>
|
<Button x:Name="TestBttn" Classes="normal">Test</Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -4,5 +4,12 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||||
x:Class="CritterFolio.Pages.TestPage">
|
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>
|
</UserControl>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,10 +6,6 @@
|
|||||||
</Border>
|
</Border>
|
||||||
</Design.PreviewWith>
|
</Design.PreviewWith>
|
||||||
|
|
||||||
<Style Selector="Window">
|
|
||||||
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style Selector="Button.headerBttn">
|
<Style Selector="Button.headerBttn">
|
||||||
<Setter Property="FontFamily" Value="{DynamicResource Phosphor}"/>
|
<Setter Property="FontFamily" Value="{DynamicResource Phosphor}"/>
|
||||||
<Setter Property="Background" Value="Transparent" />
|
<Setter Property="Background" Value="Transparent" />
|
||||||
@@ -20,4 +16,16 @@
|
|||||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||||
</Style>
|
</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>
|
</Styles>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<Grid RowDefinitions="Auto, *" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{DynamicResource PrimaryBackground}">
|
<Grid RowDefinitions="Auto, *" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Background="{DynamicResource PrimaryBackground}">
|
||||||
|
|
||||||
<critterFolio:Navigation Grid.Row="0" x:Name="Nav"/>
|
<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>
|
</Grid>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using CritterFolio.Pages;
|
using CritterFolio.Pages;
|
||||||
|
using CritterFolio.Services;
|
||||||
|
|
||||||
namespace CritterFolio.Views;
|
namespace CritterFolio.Views;
|
||||||
|
|
||||||
@@ -11,5 +12,7 @@ public partial class MainView : UserControl
|
|||||||
Sys.Navigation = Nav;
|
Sys.Navigation = Nav;
|
||||||
Nav.Init(ScrollView);
|
Nav.Init(ScrollView);
|
||||||
Nav.PushPage(new HomePage());
|
Nav.PushPage(new HomePage());
|
||||||
|
|
||||||
|
_ = DatabaseService.Init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user