diff --git a/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml b/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml
index c28431b..cca35a4 100644
--- a/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml
+++ b/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml
@@ -3,26 +3,34 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.CheckPointsPage"
Title="Ellenőrzési pontok">
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml.cs
index b22bc55..d0aaa32 100644
--- a/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml.cs
+++ b/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointsPage.xaml.cs
@@ -59,7 +59,10 @@ public partial class CheckPointsPage : ContentPage
Shell.Current.GoToAsync("//BaseStockPage");
return true;
}
-
+ private void OnButtonSync(object sender, EventArgs e)
+ {
+ _syncService.SyncCheckPointsUp();
+ }
#region NFC
bool _eventsAlreadySubscribed = false;
CheckPointDTO _checkPointDTO = null;
@@ -75,7 +78,7 @@ public partial class CheckPointsPage : ContentPage
}
catch (Exception ex)
{
-
+
}
}
async Task EndListening()
diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs
index d0647d8..a0247f7 100644
--- a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs
+++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs
@@ -1,5 +1,7 @@
+using System.Diagnostics;
using System.Windows.Input;
using WorkFlowCheck.Common.DTO;
+using WorkFlowCheck.MAUI.Pages.NFC;
using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI.Pages.CheckList;
@@ -13,10 +15,10 @@ public partial class CheckListPage : ContentPage
public ICommand ContinueCommand { get; set; }
public CheckListPage()
- {
- InitializeComponent();
+ {
+ InitializeComponent();
_checkListService = MauiProgram.ServiceProvider.GetRequiredService();
- _userService = MauiProgram.ServiceProvider.GetRequiredService();
+ _userService = MauiProgram.ServiceProvider.GetRequiredService();
}
protected override bool OnBackButtonPressed()
@@ -29,18 +31,23 @@ public partial class CheckListPage : ContentPage
base.OnAppearing();
NewCommand = new Command(OnNewItem);
ContinueCommand = new Command(OnContinueItem);
+ BindingContext = this;
await LoadCheckListTemplate();
await LoadCheckList();
}
private async void OnNewItem(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO)
- {
-
- //await Navigation.PushAsync(new CheckPointEditPage(checkPointDTO));
- }
- private async void OnContinueItem(CheckListHeaderDTO checkListTemplateHeaderDTO)
{
//await Navigation.PushAsync(new CheckPointEditPage(checkPointDTO));
+ }
+ private async void OnContinueItem(CheckListHeaderDTO checkListHeaderDTO)
+ {
+ var taskCompletionSource = new TaskCompletionSource();
+ await Navigation.PushAsync(new NFCWaiter(taskCompletionSource));
+ var result = await taskCompletionSource.Task;
+
+
+
}
private async Task LoadCheckListTemplate()
{
diff --git a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml
new file mode 100644
index 0000000..aadced6
--- /dev/null
+++ b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml.cs
new file mode 100644
index 0000000..2546270
--- /dev/null
+++ b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml.cs
@@ -0,0 +1,117 @@
+using Plugin.NFC;
+using System.Collections.ObjectModel;
+
+namespace WorkFlowCheck.MAUI.Pages.NFC;
+
+public partial class NFCWaiter : ContentPage
+{
+
+ private bool _eventsAlreadySubscribed = false;
+ private bool _onReceiveing = false;
+ private TaskCompletionSource _taskCompletionSource;
+
+ public NFCWaiter(TaskCompletionSource taskCompletionSource)
+ {
+ InitializeComponent();
+ _taskCompletionSource = taskCompletionSource;
+ }
+ protected override async void OnAppearing()
+ {
+ base.OnAppearing();
+
+ CrossNFC.Legacy = false;
+ if (CrossNFC.IsSupported)
+ {
+ if (!CrossNFC.Current.IsAvailable)
+ await ShowAlert("NFC is not available");
+
+ if (!CrossNFC.Current.IsEnabled)
+ await ShowAlert("NFC is disabled");
+
+ await AutoStartAsync().ConfigureAwait(false);
+ }
+ else
+ {
+ await ShowAlert("NFC is not available");
+ }
+
+ }
+ async Task AutoStartAsync()
+ {
+ // Some delay to prevent Java.Lang.IllegalStateException "Foreground dispatch can only be enabled when your activity is resumed" on Android
+ await Task.Delay(500);
+ await StartListeningIfNotiOS();
+ }
+ async Task StartListeningIfNotiOS()
+ {
+
+ await BeginListening();
+ }
+ async Task BeginListening()
+ {
+ try
+ {
+ MainThread.BeginInvokeOnMainThread(() =>
+ {
+ SubscribeEvents();
+ CrossNFC.Current.StartListening();
+ });
+ }
+ catch (Exception ex)
+ {
+ await ShowAlert(ex.Message);
+ }
+ }
+ async Task EndListening()
+ {
+ try
+ {
+ MainThread.BeginInvokeOnMainThread(() =>
+ {
+ UnsubscribeEvents();
+ CrossNFC.Current.StopPublishing();
+ CrossNFC.Current.StopListening();
+
+ });
+ }
+ catch (Exception ex)
+ {
+ await ShowAlert(ex.Message);
+ }
+ }
+ void SubscribeEvents()
+ {
+ if (_eventsAlreadySubscribed)
+ UnsubscribeEvents();
+
+ _eventsAlreadySubscribed = true;
+
+ CrossNFC.Current.OnMessageReceived += Current_OnMessageReceived_NFCData;
+
+
+ }
+ void UnsubscribeEvents()
+ {
+ CrossNFC.Current.OnMessageReceived -= Current_OnMessageReceived_NFCData;
+ _eventsAlreadySubscribed = false;
+ }
+ async void Current_OnMessageReceived_NFCData(ITagInfo tagInfo)
+ {
+ _onReceiveing = true;
+ if (tagInfo == null)
+ {
+ await ShowAlert("No tag found");
+ _onReceiveing = false;
+ return;
+ }
+
+ // Customized serial number
+ var identifier = tagInfo.Identifier;
+ var serialNumber = NFCUtils.ByteArrayToHexString(identifier, ":");
+ _taskCompletionSource.TrySetResult(serialNumber);
+ await EndListening();
+ await Navigation.PopAsync();
+ _onReceiveing = false;
+ }
+ Task ShowAlert(string message, string title = null) => DisplayAlert(string.IsNullOrWhiteSpace(title) ? "NFC olvasás" : title, message, "OK");
+}
\ No newline at end of file
diff --git a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml
index 9c7c4d9..c70388d 100644
--- a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml
+++ b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml
@@ -1,27 +1,69 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
+ BackgroundColor="#f0f0f0">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs
index 6db577a..09a8708 100644
--- a/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs
+++ b/src/WorkFlowCheck.MAUI/Pages/Security/LoginPage.xaml.cs
@@ -5,10 +5,12 @@ namespace WorkFlowCheck.MAUI.Pages.Security;
public partial class LoginPage : ContentPage
{
private IUserService _userService;
+ private ISyncService _syncService;
public LoginPage()
{
InitializeComponent();
_userService = MauiProgram.ServiceProvider.GetRequiredService();
+ _syncService = MauiProgram.ServiceProvider.GetRequiredService();
}
private async void OnLoginClicked(object sender, EventArgs e)
{
@@ -24,6 +26,7 @@ public partial class LoginPage : ContentPage
if (response != null && response.IsSuccess)
{
_userService.SetCurrentUser(response.Data);
+ await _syncService.SyncDatas();
var wFCUser = Newtonsoft.Json.JsonConvert.SerializeObject(response.Data);
await SecureStorage.Default.SetAsync("WFCUser", "wFCUser");
diff --git a/src/WorkFlowCheck.MAUI/Resources/Splash/splash.svg b/src/WorkFlowCheck.MAUI/Resources/Splash/splash.svg
index 21dfb25..38ee3ce 100644
--- a/src/WorkFlowCheck.MAUI/Resources/Splash/splash.svg
+++ b/src/WorkFlowCheck.MAUI/Resources/Splash/splash.svg
@@ -1,8 +1,7 @@
-
-
\ No newline at end of file
+
diff --git a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs
index 6568501..1841a73 100644
--- a/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs
+++ b/src/WorkFlowCheck.MAUI/Services/Interfaces/ISyncService.cs
@@ -9,6 +9,11 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
public interface ISyncService
{
Task SyncDatas();
+ Task SyncCheckPointsDown();
+ Task SyncCheckPointsUp();
+ Task SyncLocations();
+ Task SyncEquipments();
+
}
}
diff --git a/src/WorkFlowCheck.MAUI/Services/SyncService.cs b/src/WorkFlowCheck.MAUI/Services/SyncService.cs
index 470ff8b..ca78e3a 100644
--- a/src/WorkFlowCheck.MAUI/Services/SyncService.cs
+++ b/src/WorkFlowCheck.MAUI/Services/SyncService.cs
@@ -1,6 +1,7 @@
using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
+using Newtonsoft.Json;
using System.Net.Http.Json;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.DataLayer;
@@ -19,13 +20,13 @@ namespace WorkFlowCheck.MAUI.Services
}
public async Task SyncDatas()
{
- await SyncCheckPoints();
+ await SyncCheckPointsDown();
await SyncLocations();
await SyncEquipments();
await SyncCheckListTemplates();
await SyncCheckList();
}
- public async Task SyncCheckPoints()
+ public async Task SyncCheckPointsDown()
{
try
{
@@ -55,6 +56,52 @@ namespace WorkFlowCheck.MAUI.Services
}
}
+ public async Task SyncCheckPointsUp()
+ {
+ try
+ {
+ await PrepareAuthenticatedRequestAsync();
+ // Az API végpont meghatározása
+ string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckPoints";
+ // HTTP GET kérés küldése
+ var response = await _httpClient.GetFromJsonAsync>>(endpoint);
+ if (response != null)
+ {
+ if (response.IsSuccess)
+ {
+ var entityList = await _dbContext.CheckPoints.ToListAsync();
+ var missingItems = response.Data.Where(f => !entityList.Any(s => s.Id == f.Id & s.Code == f.Code)).ToList();
+
+
+
+ var checkPointListDTO = _mapper.Map>(missingItems);
+
+ foreach (var item in checkPointListDTO)
+ {
+ var entity = await _dbContext.CheckPoints.Where(w => w.Id == item.Id).FirstOrDefaultAsync();
+ if (entity != null)
+ {
+ item.ShortName = entity.ShortName;
+ item.Code = entity.Code;
+ }
+ }
+
+ endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllCheckPoint";
+ using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, checkPointListDTO))
+ {
+ httpResponseMessage.EnsureSuccessStatusCode();
+ var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
+ response = JsonConvert.DeserializeObject>>(jsonString);
+ }
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ // Hiba visszaadása
+ }
+ }
+
public async Task SyncLocations()
{
try
@@ -160,7 +207,7 @@ namespace WorkFlowCheck.MAUI.Services
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListHeader/{userId}";
// HTTP GET kérés küldése
-
+
var response = await _httpClient.GetFromJsonAsync>>(endpoint);
if (response != null)
{
diff --git a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj
index b7bb9d9..11aefb3 100644
--- a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj
+++ b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj
@@ -43,7 +43,7 @@
-
+
@@ -115,6 +115,9 @@
MSBuild:Compile
+
+ MSBuild:Compile
+
MSBuild:Compile