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
@@ -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;
}
}
}