diff --git a/App.xaml.cs b/App.xaml.cs index 54e907c..b94c348 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,4 +1,6 @@ -namespace HegreHotel; +using HegreHotel.Views; + +namespace HegreHotel; public partial class App : Application { @@ -6,6 +8,8 @@ public partial class App : Application { InitializeComponent(); - MainPage = new AppShell(); + Task.Run(async () => await Database.CreateDatabaseAsync()).Wait(); + + MainPage = new NavigationPage(new MainPage()); } -} \ No newline at end of file +} diff --git a/Database.cs b/Database.cs index d37bc3a..7fe6ab1 100644 --- a/Database.cs +++ b/Database.cs @@ -1,26 +1,25 @@ +using System.IO; +using Microsoft.Maui.Storage; +using System.Threading.Tasks; using HegreHotel.Models; -using SQLite; -namespace HegreHotel; - -public class Database +namespace HegreHotel { - private static SQLiteAsyncConnection _database; - - public static async Task GetConnection() + public class Database { - if (_database == null) + public static async Task CreateDatabaseAsync() { - var databasePath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db"); - _database = new SQLiteAsyncConnection(databasePath); + // Construction du chemin de la BDD dans le dossier AppData + string dbPath = Path.Combine(FileSystem.AppDataDirectory, "HegreHotel.db3"); - // Créer les tables - await _database.CreateTableAsync(); - await _database.CreateTableAsync(); - await _database.CreateTableAsync(); - await _database.CreateTableAsync(); + // Récupération de l'instance unique du Singleton + var db = SingletonConnection.GetInstance(dbPath); + + // Création des tables + await db.CreateTableAsync(); + await db.CreateTableAsync(); + await db.CreateTableAsync(); + await db.CreateTableAsync(); } - - return _database; } -} +} \ No newline at end of file diff --git a/HegreHotel.csproj b/HegreHotel.csproj index cf89031..8908392 100644 --- a/HegreHotel.csproj +++ b/HegreHotel.csproj @@ -66,4 +66,8 @@ + + + + diff --git a/MainPage.xaml b/MainPage.xaml index 496cf86..9e50782 100644 --- a/MainPage.xaml +++ b/MainPage.xaml @@ -1,36 +1,25 @@ - + + + x:Class="HegreHotel.MainPage" + Title="HegreHotel"> + +