FÉLKÉSZ

This commit is contained in:
2025-04-05 18:11:42 +02:00
parent 4951fc0c7a
commit 33232bae75
15 changed files with 404 additions and 72 deletions
@@ -20,6 +20,7 @@ namespace WorkFlowCheck.MAUI.DataLayer
public DbSet<CheckPoint> CheckPoints { get; set; }
public DbSet<Equipment> Equipments { get; set; }
public DbSet<Location> Locations { get; set; }
public DbSet<MobileUser> MobileUsers { get; set; }
public AppDbContext()
{
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkFlowCheck.MAUI.DataLayer.Entities
{
public class MobileUser
{
public int Id { get; set; }
public string? UserName { get; set; }
public string? FirstName { get; set; }
public string? LastName { get; set; }
public string? Email { get; set; }
public string? PhoneNumber { get; set; }
public bool NFCActive { get; set; }
public string NFCCode { get; set; } = null!;
}
}
@@ -7,26 +7,33 @@
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
<VerticalStackLayout Margin="10,10,10,0">
<Button
x:Name="ButtonGetCheckPoints"
Margin="0,0,0,10"
Text="Ellenőrzési pontok"
SemanticProperties.Hint="Ellenőrzési pontok"
Clicked="OnButtonGetCheckPoints"
HorizontalOptions="Fill" />
x:Name="ButtonGetCheckPoints"
Margin="0,0,0,10"
Text="Ellenőrzési pontok"
SemanticProperties.Hint="Ellenőrzési pontok"
Clicked="OnButtonGetCheckPoints"
HorizontalOptions="Fill" />
<Button
x:Name="ButtonGetEquipments"
Margin="0,0,0,10"
Text="Berendezések"
SemanticProperties.Hint="Berendezések"
Clicked="OnButtonGetCheckPoints"
HorizontalOptions="Fill" />
x:Name="ButtonGetEquipments"
Margin="0,0,0,10"
Text="Berendezések"
SemanticProperties.Hint="Berendezések"
Clicked="OnButtonGetEquipments"
HorizontalOptions="Fill" />
<Button
x:Name="ButtonGetLocations"
Margin="0,0,0,10"
Text="Lokációk"
SemanticProperties.Hint="Lokációk"
Clicked="OnButtonGetCheckPoints"
HorizontalOptions="Fill" />
x:Name="ButtonGetLocations"
Margin="0,0,0,10"
Text="Lokációk"
SemanticProperties.Hint="Lokációk"
Clicked="OnButtonGetLocations"
HorizontalOptions="Fill" />
<Button
x:Name="ButtonGetUsers"
Margin="0,0,0,10"
Text="Felhasználók"
SemanticProperties.Hint="Felhasználók"
Clicked="OnButtonGetUsers"
HorizontalOptions="Fill" />
</VerticalStackLayout>
</Frame>
</VerticalStackLayout>
@@ -1,4 +1,5 @@
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.Pages.Security;
namespace WorkFlowCheck.MAUI.Pages.BaseStock;
@@ -16,11 +17,18 @@ public partial class BaseStockPage : ContentPage
}
private async void OnButtonGetEquipments(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//EquipmentsPage");
//await Shell.Current.GoToAsync("//EquipmentsPage");
await Navigation.PushAsync(new EquipmentsPage());
}
private async void OnButtonGetLocations(object sender, EventArgs e)
{
await Shell.Current.GoToAsync("//LocationsPage");
//await Shell.Current.GoToAsync("//LocationsPage");
await Navigation.PushAsync(new LocationsPage());
}
private async void OnButtonGetUsers(object sender, EventArgs e)
{
//await Shell.Current.GoToAsync("//LocationsPage");
await Navigation.PushAsync(new UsersPage());
}
protected override bool OnBackButtonPressed()
@@ -3,36 +3,46 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.CheckPointsPage"
Title="Ellenőrzési pontok">
<StackLayout>
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
<Button
x:Name="ButtonSync" Margin="5"
Text="Adatok szinkronizálása"
SemanticProperties.Hint="Adatok szinkronizálása"
Clicked="OnButtonSync"
HorizontalOptions="Fill" />
<RefreshView x:Name="refreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
<CollectionView x:Name="CheckPointsList">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True" BackgroundColor="WhiteSmoke">
<StackLayout>
<Label Text="{Binding ShortName}" FontSize="16" FontAttributes="Bold" />
<Label Text="{Binding Code}" FontSize="14" />
<HorizontalStackLayout HorizontalOptions="End">
<Button Text="Edit" Margin="5,0,0,0"
Command="{Binding BindingContext.EditCommand, Source={x:Reference CheckPointsList}}"
CommandParameter="{Binding .}" />
<Button Text="Pair" Margin="5,0,0,0"
Command="{Binding BindingContext.PairCommand, Source={x:Reference CheckPointsList}}"
CommandParameter="{Binding .}" />
</HorizontalStackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</StackLayout>
</ContentPage>
<Grid>
<!-- Fő tartalom -->
<StackLayout>
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
<Button
x:Name="ButtonSync" Margin="5"
Text="Adatok szinkronizálása"
SemanticProperties.Hint="Adatok szinkronizálása"
Clicked="OnButtonSync"
HorizontalOptions="Fill" />
<RefreshView x:Name="refreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
<CollectionView x:Name="CheckPointsList">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True" BackgroundColor="WhiteSmoke">
<StackLayout>
<Label Text="{Binding ShortName}" FontSize="16" FontAttributes="Bold" />
<Label Text="{Binding Code}" FontSize="14" />
<HorizontalStackLayout HorizontalOptions="End">
<Button Text="Edit" Margin="5,0,0,0"
Command="{Binding BindingContext.EditCommand, Source={x:Reference CheckPointsList}}"
CommandParameter="{Binding .}" />
<Button Text="Pair" Margin="5,0,0,0"
Command="{Binding BindingContext.PairCommand, Source={x:Reference CheckPointsList}}"
CommandParameter="{Binding .}" />
</HorizontalStackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</StackLayout>
<!-- Betöltés közbeni ActivityIndicator -->
<Grid x:Name="loadingOverlay" BackgroundColor="#80000000" IsVisible="{Binding IsLoading}" AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, 1">
<ActivityIndicator IsRunning="{Binding IsLoading}" Color="White"
VerticalOptions="Center" HorizontalOptions="Center"
WidthRequest="50" HeightRequest="50"/>
</Grid>
</Grid>
</ContentPage>
@@ -20,11 +20,20 @@ public partial class CheckPointsPage : ContentPage
_baseStockService = MauiProgram.ServiceProvider.GetRequiredService<IBaseStockService>();
_syncService = MauiProgram.ServiceProvider.GetRequiredService<ISyncService>();
}
private bool _isLoading;
public bool IsLoading
{
get => _isLoading;
set
{
_isLoading = value;
OnPropertyChanged();
}
}
public ICommand RefreshCommand { get; set; }
public ICommand EditCommand { get; set; }
public ICommand PairCommand { get; set; }
public bool IsRefreshing { get; set; }
protected override async void OnAppearing()
{
@@ -39,15 +48,12 @@ public partial class CheckPointsPage : ContentPage
}
private async Task LoadCheckPoints()
{
IsRefreshing = true;
//await _syncService.SyncDatas();
IsLoading = true;
CheckPointsList.ItemsSource = await _baseStockService.GetAllCheckPoints();
IsRefreshing = false;
OnPropertyChanged(nameof(IsRefreshing));
IsLoading = false;
}
private async void OnEditItem(CheckPointDTO checkPointDTO)
{
// Navigálás a CheckPointEdit.xaml-ra, és átadjuk az editálni kívánt elemet
await Navigation.PushAsync(new CheckPointEditPage(checkPointDTO));
}
private async void OnPairItem(CheckPointDTO checkPointDTO)
@@ -74,7 +80,7 @@ public partial class CheckPointsPage : ContentPage
}
private async void OnButtonSync(object sender, EventArgs e)
{
IsRefreshing = true;
IsLoading = true;
ButtonSync.IsEnabled = false;
progressLabel.Text = "Szinkronizálás indítása...";
@@ -103,7 +109,7 @@ public partial class CheckPointsPage : ContentPage
finally
{
ButtonSync.IsEnabled = true;
IsRefreshing = false;
IsLoading = false;
}
}
}
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.Security.UsersPage"
Title="Felhasználók">
<StackLayout>
<Label x:Name="progressLabel" Text="Folyamatjelző" FontSize="Medium" HorizontalOptions="Center" />
<ProgressBar x:Name="progressBar" WidthRequest="300" HeightRequest="40" />
<Button
x:Name="ButtonSync" Margin="5"
Text="Adatok szinkronizálása"
SemanticProperties.Hint="Adatok szinkronizálása"
Clicked="OnButtonSync"
HorizontalOptions="Fill" />
<RefreshView x:Name="refreshView" Command="{Binding RefreshCommand}" IsRefreshing="{Binding IsRefreshing}">
<CollectionView x:Name="UsersList">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True" BackgroundColor="WhiteSmoke">
<StackLayout>
<Label Text="{Binding ShortName}" FontSize="16" FontAttributes="Bold" />
<Label Text="{Binding Code}" FontSize="14" />
<HorizontalStackLayout HorizontalOptions="End">
<Button Text="Edit" Margin="5,0,0,0"
Command="{Binding BindingContext.EditCommand, Source={x:Reference UsersList}}"
CommandParameter="{Binding .}" />
<Button Text="Pair" Margin="5,0,0,0"
Command="{Binding BindingContext.PairCommand, Source={x:Reference UsersList}}"
CommandParameter="{Binding .}" />
</HorizontalStackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</RefreshView>
</StackLayout>
</ContentPage>
@@ -0,0 +1,99 @@
using System.Windows.Input;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.Services.Interfaces;
using WorkFlowCheck.MAUI.Pages.NFC;
namespace WorkFlowCheck.MAUI.Pages.Security;
public partial class UsersPage : ContentPage
{
private readonly IUserService _userService;
public UsersPage()
{
InitializeComponent();
_userService = MauiProgram.ServiceProvider.GetRequiredService<IUserService>();
}
public ICommand RefreshCommand { get; set; }
public ICommand PairCommand { get; set; }
public bool IsRefreshing { get; set; }
protected override async void OnAppearing()
{
base.OnAppearing();
RefreshCommand = new Command(async () => await LoadUsers());
PairCommand = new Command<UserDTO>(OnPairItem);
BindingContext = this;
await LoadUsers();
}
private async Task LoadUsers()
{
IsRefreshing = true;
//await _syncService.SyncDatas();
UsersList.ItemsSource = await _userService.GetAllUsers();
IsRefreshing = false;
OnPropertyChanged(nameof(IsRefreshing));
}
private async void OnPairItem(UserDTO UserDTO)
{
var UserCode = await NFCWaiter.ShowModalAsync();
if (!string.IsNullOrEmpty(UserCode))
{
if (Navigation.ModalStack.Count > 0)
{
await Navigation.PopModalAsync();
}
if (UserDTO != null)
{
UserDTO.Code = UserCode;
await _baseStockService.UpdateUser(UserDTO);
await LoadUsers();
}
}
}
protected override bool OnBackButtonPressed()
{
Shell.Current.GoToAsync("//BaseStockPage");
return true;
}
private async void OnButtonSync(object sender, EventArgs e)
{
IsRefreshing = true;
ButtonSync.IsEnabled = false;
progressLabel.Text = "Szinkronizálás indítása...";
progressBar.Progress = 0;
try
{
await Task.Run(async () =>
{
await _userService.SyncUsers_Up((percentage, infostring) =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
progressBar.Progress = percentage / 100;
progressLabel.Text = $"{infostring}: {percentage:0.00}%";
});
});
});
progressLabel.Text = "Szinkronizálás befejezve!";
}
catch (Exception ex)
{
progressLabel.Text = $"Hiba történt: {ex.Message}";
}
finally
{
ButtonSync.IsEnabled = true;
IsRefreshing = false;
}
}
}
@@ -10,6 +10,8 @@ using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.MAUI.DataLayer;
using WorkFlowCheck.MAUI.Services.Interfaces;
using Android.Provider;
using Android.DeviceLock;
namespace WorkFlowCheck.MAUI.Services
{
@@ -20,6 +22,7 @@ namespace WorkFlowCheck.MAUI.Services
public readonly AppDbContext _dbContext;
public readonly IConfiguration _configuration;
public readonly IMapper _mapper;
private string _deviceId;
public BaseService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper)
{
@@ -33,6 +36,7 @@ namespace WorkFlowCheck.MAUI.Services
var apiKey = configuration["ApiKey"];
_httpClient.DefaultRequestHeaders.Add("X-Api-Key", apiKey);
_deviceId = GetDeviceId();
}
protected async Task PrepareAuthenticatedRequestAsync()
{
@@ -41,6 +45,20 @@ namespace WorkFlowCheck.MAUI.Services
if (!string.IsNullOrEmpty(jwtToken) && _httpClient != null)
{
_httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken);
_httpClient.DefaultRequestHeaders.Add("DeviceId", _deviceId);
}
}
protected string GetDeviceId()
{
try
{
var context = Android.App.Application.Context;
return Settings.Secure.GetString(context.ContentResolver, Settings.Secure.AndroidId) ?? "NO_ANDROID_DEVICE";
}
catch (Exception ex)
{
Console.WriteLine($"Error retrieving device ID: {ex.Message}");
return "UnknownDevice";
}
}
}
@@ -11,7 +11,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
{
Task SyncDatas(Action<double, string> reportProgress);
Task SyncCheckPoints_Down(Action<double, string> reportProgress);
Task SyncCheckPoints_Up(Action<double, string> reportProgress);
Task<ApiResponseDTO<string>> SyncCheckPoints_Up(Action<double, string> reportProgress);
Task SyncLocations_Down(Action<double, string> reportProgress);
Task SyncEquipments_Down(Action<double, string> reportProgress);
@@ -19,5 +19,7 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
Task SyncCheckListHeader_Down(Action<double, string> reportProgress);
Task<ApiResponseDTO<string>> SyncCheckListHeader_Up(int Id, Action<double, string> reportProgress);
}
}
@@ -10,8 +10,10 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
public interface IUserService
{
UserDTO? GetCurrentUser();
Task<ApiResponseDTO<UserDTO>> GetUserAsync();
Task<ApiResponseDTO<UserDTO>> GetUserAsync(int id);
Task<ApiResponseDTO<List<UserDTO>>> GetAllUserAsync();
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress);
void SetCurrentUser(UserDTO user);
}
}
+31 -3
View File
@@ -53,16 +53,44 @@ namespace WorkFlowCheck.MAUI.Services
Console.WriteLine($"Hiba történt: {ex.Message}");
}
}
public async Task SyncCheckPoints_Up(Action<double, string> reportProgress)
public async Task<ApiResponseDTO<string>> SyncCheckPoints_Up(Action<double, string> reportProgress)
{
var retVal = new ApiResponseDTO<string>();
try
{
await PrepareAuthenticatedRequestAsync();
var checkPointList = await _dbContext.CheckPoints.ToListAsync();
var checkPointListDTO = _mapper.Map<List<CheckPointDTO>>(checkPointList);
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllCheckPoint";
var json = JsonConvert.SerializeObject(checkPointListDTO);
var jsonBytes = Encoding.UTF8.GetBytes(json);
var jsonStream = new MemoryStream(jsonBytes);
var progressContent = new ProgressableStreamContent(jsonStream, 8192, (uploaded, total) =>
{
double percentage = (double)uploaded / total * 100;
reportProgress(percentage, "Beküldés...");
});
progressContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync(endpoint, progressContent))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
retVal = JsonConvert.DeserializeObject<ApiResponseDTO<string>>(jsonString);
}
}
catch (Exception ex)
{
// Hiba visszaadása
retVal.IsSuccess = false;
retVal.Errors.Add(ex.Message);
}
return retVal;
}
public async Task SyncLocations_Down(Action<double, string> reportProgress)
@@ -221,7 +249,7 @@ namespace WorkFlowCheck.MAUI.Services
catch (Exception ex)
{
retVal.IsSuccess = false;
retVal.Errors.Add(ex.Message);
retVal.Errors.Add(ex.Message);
}
return retVal;
}
+68 -5
View File
@@ -13,6 +13,8 @@ using Newtonsoft.Json;
using WorkFlowCheck.MAUI.DataLayer;
using AutoMapper;
using WorkFlowCheck.MAUI.Services.Interfaces;
using Microsoft.EntityFrameworkCore;
using WorkFlowCheck.MAUI.Handlers;
namespace WorkFlowCheck.MAUI.Services
{
@@ -22,15 +24,14 @@ namespace WorkFlowCheck.MAUI.Services
public UserService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper)
{
}
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync(int id)
{
try
{
await PrepareAuthenticatedRequestAsync();
// Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/User/1";
// HTTP GET kérés küldése
string endpoint = $"{_httpClient.BaseAddress}api/GetUser/{id}";
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
return response ?? new ApiResponseDTO<UserDTO>
@@ -47,6 +48,29 @@ namespace WorkFlowCheck.MAUI.Services
};
}
}
public async Task<ApiResponseDTO<List<UserDTO>>> GetAllUserAsync()
{
try
{
await PrepareAuthenticatedRequestAsync();
string endpoint = $"{_httpClient.BaseAddress}api/GetAllUser";
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserDTO>>>(endpoint);
return response ?? new ApiResponseDTO<List<UserDTO>>
{
IsSuccess = false,
};
}
catch (Exception ex)
{
return new ApiResponseDTO<List<UserDTO>>
{
IsSuccess = false
};
}
}
public async Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password)
{
try
@@ -58,7 +82,7 @@ namespace WorkFlowCheck.MAUI.Services
{
UserName = username,
Password = password,
};
// HTTP POST kérés küldése
@@ -85,6 +109,45 @@ namespace WorkFlowCheck.MAUI.Services
};
}
}
public async Task<ApiResponseDTO<string>> SyncUsers_Up(Action<double, string> reportProgress)
{
var retVal = new ApiResponseDTO<string>();
try
{
await PrepareAuthenticatedRequestAsync();
var userList = await _dbContext.Users.ToListAsync();
var userListDTO = _mapper.Map<List<UserDTO>>(userList);
var endpoint = $"{_httpClient.BaseAddress}api/Sync/UpdateAllUser";
var json = JsonConvert.SerializeObject(userListDTO);
var jsonBytes = Encoding.UTF8.GetBytes(json);
var jsonStream = new MemoryStream(jsonBytes);
var progressContent = new ProgressableStreamContent(jsonStream, 8192, (uploaded, total) =>
{
double percentage = (double)uploaded / total * 100;
reportProgress(percentage, "Beküldés...");
});
progressContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsync(endpoint, progressContent))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
retVal = JsonConvert.DeserializeObject<ApiResponseDTO<string>>(jsonString);
}
}
catch (Exception ex)
{
retVal.IsSuccess = false;
retVal.Errors.Add(ex.Message);
}
return retVal;
}
public void SetCurrentUser(UserDTO user)
{
CurrentUser = user;
@@ -88,6 +88,12 @@
<ProjectReference Include="..\WorkFlowCheck.Common\WorkFlowCheck.Common.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Update="Pages\Security\UsersPage.xaml.cs">
<DependentUpon>UsersPage.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<MauiXaml Update="ContentViews\HeaderView.xaml">
<Generator>MSBuild:Compile</Generator>
@@ -122,6 +128,9 @@
<MauiXaml Update="Pages\NFC\NFCWaiter.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\Security\UsersPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="Pages\Security\LoginPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>