From 4570c071a793f61b458f1414457b6ec8676ff52e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Szab=C3=B3?= Date: Wed, 5 Feb 2025 13:47:11 +0100 Subject: [PATCH] SQLLite vol 1. --- src/WorkFlowCheck.MAUI/App.xaml.cs | 12 +++++- .../DataLayer/AppDbContext.cs | 29 ++++++++++++++ .../Entities/CheckListTemplateHeader.cs | 16 ++++++++ .../Entities/CheckListTemplateRow.cs | 22 ++++++++++ .../DataLayer/Entities/CheckPoint.cs | 17 ++++++++ .../DataLayer/Entities/Equipment.cs | 15 +++++++ src/WorkFlowCheck.MAUI/MauiProgram.cs | 40 ++++++++----------- .../Pages/NFC/NFCTestPage.xaml.cs | 4 ++ .../Pages/Security/LoginPage.xaml.cs | 3 +- .../Platforms/Android/AndroidManifest.xml | 5 +++ .../Services/ISyncService.cs | 13 ++++++ .../Services/IUserService.cs | 3 +- .../Services/SyncService.cs | 22 ++++++++++ .../Services/UserService.cs | 6 +++ .../WorkFlowCheck.MAUI.csproj | 11 +++++ 15 files changed, 190 insertions(+), 28 deletions(-) create mode 100644 src/WorkFlowCheck.MAUI/DataLayer/AppDbContext.cs create mode 100644 src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateHeader.cs create mode 100644 src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateRow.cs create mode 100644 src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckPoint.cs create mode 100644 src/WorkFlowCheck.MAUI/DataLayer/Entities/Equipment.cs create mode 100644 src/WorkFlowCheck.MAUI/Services/ISyncService.cs create mode 100644 src/WorkFlowCheck.MAUI/Services/SyncService.cs diff --git a/src/WorkFlowCheck.MAUI/App.xaml.cs b/src/WorkFlowCheck.MAUI/App.xaml.cs index 16d827f..ca6d497 100644 --- a/src/WorkFlowCheck.MAUI/App.xaml.cs +++ b/src/WorkFlowCheck.MAUI/App.xaml.cs @@ -1,16 +1,24 @@ -using Microsoft.Extensions.DependencyInjection; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; using WorkFlowCheck.Common.DTO; +using WorkFlowCheck.MAUI.DataLayer; using WorkFlowCheck.MAUI.Services; namespace WorkFlowCheck.MAUI { public partial class App : Application { + private readonly AppDbContext _dbContext; public App(IServiceProvider serviceProvider) { InitializeComponent(); - //MainPage = serviceProvider.GetRequiredService(); + _dbContext = serviceProvider.GetRequiredService(); + + _dbContext.Database.EnsureDeleted(); // Adatbázis törlése + _dbContext.Database.EnsureCreated(); // Új adatbázis létrehozása + + MainPage = new AppShell(); } diff --git a/src/WorkFlowCheck.MAUI/DataLayer/AppDbContext.cs b/src/WorkFlowCheck.MAUI/DataLayer/AppDbContext.cs new file mode 100644 index 0000000..048c1d4 --- /dev/null +++ b/src/WorkFlowCheck.MAUI/DataLayer/AppDbContext.cs @@ -0,0 +1,29 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WorkFlowCheck.MAUI.DataLayer.Entities; + +namespace WorkFlowCheck.MAUI.DataLayer +{ + public class AppDbContext : DbContext + { + private string DbPath { get; } + + public DbSet CheckListTemplateHeaders { get; set; } + public DbSet CheckListTemplateRows { get; set; } + public DbSet CheckPoints { get; set; } + public DbSet Equipments { get; set; } + + public AppDbContext() + { + DbPath = Path.Combine(FileSystem.AppDataDirectory, "wfc.db"); + } + protected override void OnConfiguring(DbContextOptionsBuilder options) + { + options.UseSqlite($"Data Source={DbPath}"); + } + } +} diff --git a/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateHeader.cs b/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateHeader.cs new file mode 100644 index 0000000..70337bd --- /dev/null +++ b/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateHeader.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.MAUI.DataLayer.Entities +{ + public class CheckListTemplateHeader + { + public int Id { get; set; } + public string ShortName { get; set; } = null!; + public string Description { get; set; } = null!; + + } +} diff --git a/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateRow.cs b/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateRow.cs new file mode 100644 index 0000000..052b0d1 --- /dev/null +++ b/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckListTemplateRow.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.MAUI.DataLayer.Entities +{ + public class CheckListTemplateRow + { + public int Id { get; set; } + public int RowIndex { get; set; } + public int CheckListTemplateHeaderId { get; set; } + public virtual CheckListTemplateHeader CheckListTemplateHeader { get; set; } + public int EquipmentId { get; set; } + public virtual Equipment Equipment { get; set; } + public int CheckPointId { get; set; } + public virtual CheckPoint CheckPoint { get; set; } + public string OperationDescription { get; set; } = null!; + + } +} diff --git a/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckPoint.cs b/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckPoint.cs new file mode 100644 index 0000000..7c08de5 --- /dev/null +++ b/src/WorkFlowCheck.MAUI/DataLayer/Entities/CheckPoint.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.MAUI.DataLayer.Entities +{ + public class CheckPoint + { + public int Id { get; set; } + public string ShortName { get; set; } = null!; + public string Code { get; set; } = null!; + + + } +} diff --git a/src/WorkFlowCheck.MAUI/DataLayer/Entities/Equipment.cs b/src/WorkFlowCheck.MAUI/DataLayer/Entities/Equipment.cs new file mode 100644 index 0000000..5f954bc --- /dev/null +++ b/src/WorkFlowCheck.MAUI/DataLayer/Entities/Equipment.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.MAUI.DataLayer.Entities +{ + public class Equipment + { + public int Id { get; set; } + public string ShortName { get; set; } = null!; + public string EquipmentNumber { get; set; } = null!; + } +} diff --git a/src/WorkFlowCheck.MAUI/MauiProgram.cs b/src/WorkFlowCheck.MAUI/MauiProgram.cs index 73e1622..7331a03 100644 --- a/src/WorkFlowCheck.MAUI/MauiProgram.cs +++ b/src/WorkFlowCheck.MAUI/MauiProgram.cs @@ -3,6 +3,8 @@ using Microsoft.Extensions.Logging; using WorkFlowCheck.MAUI.Services; using Microsoft.Extensions.Http; using Microsoft.Extensions.DependencyInjection; +using CommunityToolkit.Maui; +using WorkFlowCheck.MAUI.DataLayer; namespace WorkFlowCheck.MAUI { @@ -11,12 +13,8 @@ namespace WorkFlowCheck.MAUI public static MauiApp CreateMauiApp() { var builder = MauiApp.CreateBuilder(); - - // appsettings.json beállítása - string jsonFilePath = Path.Combine(FileSystem.AppDataDirectory, "appsettings.json"); - // Másold a fájlt a Raw erőforrásokból az AppDataDirectory-ba, ha még nincs ott if (!File.Exists(jsonFilePath)) { @@ -25,43 +23,37 @@ namespace WorkFlowCheck.MAUI File.WriteAllText(jsonFilePath, reader.ReadToEnd()); } - var configuration = new ConfigurationBuilder() - .SetBasePath(FileSystem.AppDataDirectory) // A konfigurációs fájl betöltése az alkalmazás adat könyvtárából - .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .Build(); - + var configuration = new ConfigurationBuilder().SetBasePath(FileSystem.AppDataDirectory) // A konfigurációs fájl betöltése az alkalmazás adat könyvtárából + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).Build(); builder.Services.AddHttpClient(client => { var apiUrl = configuration["ApiBaseUrl"]; // API-cím betöltése a konfigurációból client.BaseAddress = new Uri(apiUrl); }); + builder.Services.AddDbContext(); + builder.Services.AddSingleton(configuration); + builder.Services.AddSingleton(); + builder.Services.AddSingleton(); - builder.Services.AddTransient(); builder.Services.AddTransient(); - - builder - .UseMauiApp() - .ConfigureFonts(fonts => - { - fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); - fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); - }); - + + builder.UseMauiApp().ConfigureFonts(fonts => + { + fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular"); + fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold"); + }).UseMauiCommunityToolkit(); #if DEBUG builder.Logging.AddDebug(); #endif // HttpClient regisztrálása az alap API-címmel - - var app = builder.Build(); - // Szolgáltató tárolása globálisan ServiceProvider = app.Services; - return app; } + public static IServiceProvider ServiceProvider { get; private set; } } -} +} \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs index 370acc0..3b53ff7 100644 --- a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCTestPage.xaml.cs @@ -127,4 +127,8 @@ public partial class NFCTestPage : ContentPage return message; } + protected override bool OnBackButtonPressed() { + Shell.Current.GoToAsync("//MainPage"); + return true; + } } \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs index 6e31e3a..a70c0e4 100644 --- a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs @@ -5,7 +5,7 @@ namespace WorkFlowCheck.MAUI.Pages.Security; public partial class LoginPage : ContentPage { - private readonly IUserService _userService; + private IUserService _userService; public LoginPage() { InitializeComponent(); @@ -24,6 +24,7 @@ public partial class LoginPage : ContentPage if (response != null && response.IsSuccess) { + _userService.SetUser(response.Data); var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data); await SecureStorage.Default.SetAsync("WFCUser", "wFCUser"); diff --git a/src/WorkFlowCheck.MAUI/Platforms/Android/AndroidManifest.xml b/src/WorkFlowCheck.MAUI/Platforms/Android/AndroidManifest.xml index db3fcde..ad6ee37 100644 --- a/src/WorkFlowCheck.MAUI/Platforms/Android/AndroidManifest.xml +++ b/src/WorkFlowCheck.MAUI/Platforms/Android/AndroidManifest.xml @@ -4,5 +4,10 @@ + + + + + \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Services/ISyncService.cs b/src/WorkFlowCheck.MAUI/Services/ISyncService.cs new file mode 100644 index 0000000..3e17a55 --- /dev/null +++ b/src/WorkFlowCheck.MAUI/Services/ISyncService.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WorkFlowCheck.MAUI.Services +{ + public interface ISyncService + { + + } +} diff --git a/src/WorkFlowCheck.MAUI/Services/IUserService.cs b/src/WorkFlowCheck.MAUI/Services/IUserService.cs index 3a51074..91ed02c 100644 --- a/src/WorkFlowCheck.MAUI/Services/IUserService.cs +++ b/src/WorkFlowCheck.MAUI/Services/IUserService.cs @@ -10,6 +10,7 @@ namespace WorkFlowCheck.MAUI.Services public interface IUserService { Task> GetUserAsync(); - Task> Authenticate(string username, string password); + Task> Authenticate(string username, string password); + void SetUser(UserDTO user); } } diff --git a/src/WorkFlowCheck.MAUI/Services/SyncService.cs b/src/WorkFlowCheck.MAUI/Services/SyncService.cs new file mode 100644 index 0000000..917692c --- /dev/null +++ b/src/WorkFlowCheck.MAUI/Services/SyncService.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WorkFlowCheck.MAUI.DataLayer; + +namespace WorkFlowCheck.MAUI.Services +{ + public class SyncService: ISyncService + { + private readonly HttpClient _httpClient; + private readonly AppDbContext _dbContext; + + public SyncService(HttpClient httpClient, AppDbContext dbContext) + { + _httpClient = httpClient; + _dbContext = dbContext; + } + + } +} diff --git a/src/WorkFlowCheck.MAUI/Services/UserService.cs b/src/WorkFlowCheck.MAUI/Services/UserService.cs index 0245763..2c2b430 100644 --- a/src/WorkFlowCheck.MAUI/Services/UserService.cs +++ b/src/WorkFlowCheck.MAUI/Services/UserService.cs @@ -16,6 +16,8 @@ namespace WorkFlowCheck.MAUI.Services public class UserService : IUserService { private readonly HttpClient _httpClient; + + public UserDTO? CurrentUser { get; private set; } public UserService(HttpClient httpClient, IConfiguration configuration) { _httpClient = httpClient; @@ -91,5 +93,9 @@ namespace WorkFlowCheck.MAUI.Services }; } } + public void SetUser(UserDTO user) + { + CurrentUser = user; + } } } diff --git a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj index faa7492..c330d17 100644 --- a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj +++ b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj @@ -57,9 +57,16 @@ + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + @@ -81,4 +88,8 @@ + + + +