Na most kezd valami kinézni
This commit is contained in:
@@ -22,10 +22,13 @@ namespace WorkFlowCheck.MAUI.DataLayer
|
||||
public AppDbContext()
|
||||
{
|
||||
DbPath = Path.Combine(FileSystem.AppDataDirectory, "wfc.db");
|
||||
|
||||
}
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder options)
|
||||
{
|
||||
options.UseSqlite($"Data Source={DbPath}");
|
||||
options.UseSqlite($"Data Source={DbPath};Foreign Keys=False;");
|
||||
options.EnableSensitiveDataLogging();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WorkFlowCheck.MAUI.DataLayer.SQLiteFolder
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const string DatabaseFilename = "WFC.db3";
|
||||
|
||||
public const SQLite.SQLiteOpenFlags Flags =
|
||||
// open the database in read/write mode
|
||||
SQLite.SQLiteOpenFlags.ReadWrite |
|
||||
// create the database if it doesn't exist
|
||||
SQLite.SQLiteOpenFlags.Create |
|
||||
// enable multi-threaded database access
|
||||
SQLite.SQLiteOpenFlags.SharedCache;
|
||||
|
||||
public static string DatabasePath =>
|
||||
Path.Combine(FileSystem.AppDataDirectory, DatabaseFilename);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using SQLite;
|
||||
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.SQLiteFolder
|
||||
{
|
||||
public class WFCDatabase
|
||||
{
|
||||
SQLiteAsyncConnection Database;
|
||||
public WFCDatabase()
|
||||
{
|
||||
}
|
||||
async Task Init()
|
||||
{
|
||||
if (Database is not null)
|
||||
return;
|
||||
|
||||
Database = new SQLiteAsyncConnection(Constants.DatabasePath, Constants.Flags);
|
||||
|
||||
var result = await Database.CreateTableAsync<CheckPoint>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,30 @@
|
||||
x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.BaseStockPage"
|
||||
Title="Törzs adatok">
|
||||
<VerticalStackLayout Margin="10,0,10,0">
|
||||
<Button
|
||||
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
|
||||
<VerticalStackLayout Margin="10,10,10,0">
|
||||
<Button
|
||||
x:Name="ButtonGetCheckPoints"
|
||||
Margin="0,0,0,20"
|
||||
Margin="0,0,0,10"
|
||||
Text="Ellenőrzési pontok"
|
||||
SemanticProperties.Hint="Ellenőrzési pontok"
|
||||
Clicked="OnButtonGetCheckPoints"
|
||||
HorizontalOptions="Fill" />
|
||||
<Button
|
||||
<Button
|
||||
x:Name="ButtonGetEquipments"
|
||||
Margin="0,0,0,20"
|
||||
Margin="0,0,0,10"
|
||||
Text="Berendezések"
|
||||
SemanticProperties.Hint="Berendezések"
|
||||
Clicked="OnButtonGetCheckPoints"
|
||||
HorizontalOptions="Fill" />
|
||||
<Button
|
||||
<Button
|
||||
x:Name="ButtonGetLocations"
|
||||
Margin="0,0,0,20"
|
||||
Margin="0,0,0,10"
|
||||
Text="Lokációk"
|
||||
SemanticProperties.Hint="Lokációk"
|
||||
Clicked="OnButtonGetCheckPoints"
|
||||
HorizontalOptions="Fill" />
|
||||
</VerticalStackLayout>
|
||||
</Frame>
|
||||
</VerticalStackLayout>
|
||||
</ContentPage>
|
||||
@@ -11,7 +11,7 @@ public partial class CheckPointsPage : ContentPage
|
||||
{
|
||||
private readonly IBaseStockService _baseStockService;
|
||||
private readonly ISyncService _syncService;
|
||||
|
||||
private bool _onReceiveing = false;
|
||||
|
||||
public CheckPointsPage()
|
||||
{
|
||||
@@ -93,7 +93,8 @@ public partial class CheckPointsPage : ContentPage
|
||||
}
|
||||
async void Current_OnMessageReceived_NFCData(ITagInfo tagInfo)
|
||||
{
|
||||
|
||||
if (_onReceiveing) return;
|
||||
_onReceiveing = true;
|
||||
if (tagInfo == null)
|
||||
{
|
||||
return;
|
||||
@@ -105,10 +106,11 @@ public partial class CheckPointsPage : ContentPage
|
||||
{
|
||||
_checkPointDTO.Code = serialNumber;
|
||||
await _baseStockService.UpdateCheckPoint(_checkPointDTO);
|
||||
//CrossNFC.Current.StopListening();
|
||||
UnsubscribeEvents();
|
||||
CrossNFC.Current.StopListening();
|
||||
await LoadCheckPoints();
|
||||
}
|
||||
_onReceiveing = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@@ -29,14 +30,32 @@ namespace WorkFlowCheck.MAUI.Services
|
||||
return _mapper.Map<CheckPointDTO>(await _dbContext.CheckPoints.Where(w => w.Id == id).FirstOrDefaultAsync());
|
||||
}
|
||||
|
||||
public async Task<CheckPointDTO> UpdateCheckPoint(CheckPointDTO checkPoint)
|
||||
public async Task<CheckPointDTO> UpdateCheckPoint(CheckPointDTO checkPointDto)
|
||||
{
|
||||
var retVal = checkPoint;
|
||||
// Lekérjük a meglévő entitást az adatbázisból
|
||||
try
|
||||
{
|
||||
var existingEntity = await _dbContext.CheckPoints.FindAsync(checkPointDto.Id);
|
||||
|
||||
_dbContext.CheckPoints.Update(_mapper.Map<CheckPoint>(checkPoint));
|
||||
_dbContext.SaveChanges();
|
||||
if (existingEntity == null)
|
||||
{
|
||||
throw new Exception("CheckPoint not found.");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
// Frissítjük az adatokat
|
||||
existingEntity.ShortName = checkPointDto.ShortName;
|
||||
existingEntity.Code = checkPointDto.Code;
|
||||
|
||||
// Mivel a DbContext már követi az existingEntity-t, nem kell explicit Update() hívás
|
||||
await _dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
return checkPointDto;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user