Van új és folytatható CheckLista

This commit is contained in:
2025-03-22 14:18:25 +01:00
parent 6d78762275
commit 3a4db4dd14
10 changed files with 232 additions and 26 deletions
@@ -13,6 +13,8 @@ namespace WorkFlowCheck.MAUI.DataLayer
{ {
private string DbPath { get; } private string DbPath { get; }
public DbSet<CheckListHeader> CheckListHeaders { get; set; }
public DbSet<CheckListRow> CheckListRows { get; set; }
public DbSet<CheckListTemplateHeader> CheckListTemplateHeaders { get; set; } public DbSet<CheckListTemplateHeader> CheckListTemplateHeaders { get; set; }
public DbSet<CheckListTemplateRow> CheckListTemplateRows { get; set; } public DbSet<CheckListTemplateRow> CheckListTemplateRows { get; set; }
public DbSet<CheckPoint> CheckPoints { get; set; } public DbSet<CheckPoint> CheckPoints { get; set; }
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkFlowCheck.MAUI.DataLayer.Entities
{
public class CheckListHeader
{
public int Id { get; set; }
public int CheckListTemplateHeaderId { get; set; }
public virtual CheckListTemplateHeader CheckListTemplateHeader { get; set; }
public DateTime DateExecution { get; set; }
public int UserId { get; set; }
public string ShortName { get; set; } = null!;
public string Description { get; set; } = null!;
public string DocumentNumber { get; set; } = null!;
public Guid GuidNumber { get; set; }
public bool IsStorno { get; set; }
public bool IsEditable { get; set; }
public virtual ICollection<CheckListRow> CheckListRows { get; set; } = new List<CheckListRow>();
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkFlowCheck.MAUI.DataLayer.Entities
{
public class CheckListRow
{
public int Id { get; set; }
public int CheckListHeaderId { get; set; }
public virtual CheckListHeader CheckListHeader { get; set; } = null!;
public int CheckListTemplateRowId { get; set; }
public virtual CheckListTemplateRow CheckListTemplateRow { get; set; } = null!;
public string Answer { get; set; } = null!;
public byte[] Photo { get; set; } = null!;
public Guid GuidNumber { get; set; }
}
}
@@ -22,6 +22,11 @@ namespace WorkFlowCheck.MAUI.Mapper
.ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRows)); .ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRows));
CreateMap<CheckListTemplateRow, CheckListTemplateRowDTO>(); CreateMap<CheckListTemplateRow, CheckListTemplateRowDTO>();
CreateMap<CheckListTemplateRowDTO, CheckListTemplateRow>(); CreateMap<CheckListTemplateRowDTO, CheckListTemplateRow>();
CreateMap<CheckListHeader, CheckListHeaderDTO>()
.ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows));
CreateMap<CheckListHeaderDTO, CheckListHeader>()
.ForMember(dest => dest.CheckListRows, opt => opt.MapFrom(src => src.CheckListRowDTO));
} }
} }
} }
+1
View File
@@ -45,6 +45,7 @@ namespace WorkFlowCheck.MAUI
builder.Services.AddSingleton<IUserService, UserService>(); builder.Services.AddSingleton<IUserService, UserService>();
builder.Services.AddSingleton<ISyncService, SyncService>(); builder.Services.AddSingleton<ISyncService, SyncService>();
builder.Services.AddSingleton<IBaseStockService, BaseStockService>(); builder.Services.AddSingleton<IBaseStockService, BaseStockService>();
builder.Services.AddSingleton<ICheckListService, CheckListService>();
builder.Services.AddTransient<MainPage>(); builder.Services.AddTransient<MainPage>();
@@ -3,32 +3,62 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="WorkFlowCheck.MAUI.Pages.CheckList.CheckListPage" x:Class="WorkFlowCheck.MAUI.Pages.CheckList.CheckListPage"
Title="Ellenőrzések"> Title="Ellenőrzések">
<Grid RowDefinitions="Auto, * , Auto" Padding="30,0"> <Grid RowDefinitions="*,*" Padding="30,0">
<ScrollView Grid.Row="0">
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
<VerticalStackLayout>
<Label Text="Megkezdett ellenőrzések" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
<CollectionView x:Name="CheckList">
<CollectionView.ItemTemplate>
<DataTemplate>
<Frame BorderColor="Gray" Padding="10" Margin="5" HasShadow="True" BackgroundColor="WhiteSmoke">
<StackLayout>
<Label Text="{Binding DocumentNumber}" FontSize="16" FontAttributes="Bold" />
<Label Text="{Binding DateExecution}" FontSize="14" />
<HorizontalStackLayout HorizontalOptions="End">
<Button Text="Folytatás"
Margin="5,0,0,0"
BackgroundColor="Blue"
Command="{Binding BindingContext.ContinueCommand, Source={x:Reference CheckList}}"
CommandParameter="{Binding .}" />
</HorizontalStackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
</Frame>
</ScrollView>
<ScrollView Grid.Row="1"> <ScrollView Grid.Row="1">
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
<VerticalStackLayout>
<Label Text="Megkezdett ellenőrzések" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
</VerticalStackLayout>
</Frame>
</ScrollView>
<ScrollView Grid.Row="2">
<Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True"> <Frame BorderColor="Gray" Padding="5" Margin="1" HasShadow="True">
<VerticalStackLayout> <VerticalStackLayout>
<Label Text="Új ellenőrzés" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" /> <Label Text="Új ellenőrzés" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="Center" />
<Button <CollectionView x:Name="CheckListTemplate">
x:Name="ButtonNewCheck" Margin="5" <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 Description}" FontSize="14" />
<HorizontalStackLayout HorizontalOptions="End">
<Button Text="Új ellenőrzés"
BackgroundColor="Green" BackgroundColor="Green"
Text="Új indítása" Margin="5,0,0,0"
SemanticProperties.Hint="Új indítása" Command="{Binding BindingContext.NewCommand, Source={x:Reference CheckListTemplate}}"
Clicked="OnButtonNewCheck" CommandParameter="{Binding .}" />
HorizontalOptions="Fill" /> </HorizontalStackLayout>
</StackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout> </VerticalStackLayout>
</Frame> </Frame>
</ScrollView> </ScrollView>
</Grid> </Grid>
</ContentPage> </ContentPage>
@@ -1,19 +1,56 @@
using System.Windows.Input;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.Services.Interfaces;
namespace WorkFlowCheck.MAUI.Pages.CheckList; namespace WorkFlowCheck.MAUI.Pages.CheckList;
public partial class CheckListPage : ContentPage public partial class CheckListPage : ContentPage
{ {
private readonly ICheckListService _checkListService;
private readonly IUserService _userService;
public ICommand NewCommand { get; set; }
public ICommand ContinueCommand { get; set; }
public CheckListPage() public CheckListPage()
{ {
InitializeComponent(); InitializeComponent();
_checkListService = MauiProgram.ServiceProvider.GetRequiredService<ICheckListService>();
_userService = MauiProgram.ServiceProvider.GetRequiredService<IUserService>();
} }
protected override bool OnBackButtonPressed() protected override bool OnBackButtonPressed()
{ {
Shell.Current.GoToAsync("//MainPage"); Shell.Current.GoToAsync("//MainPage");
return true; return true;
} }
public async void OnButtonNewCheck(object sender, EventArgs e) protected override async void OnAppearing()
{
base.OnAppearing();
NewCommand = new Command<CheckListTemplateHeaderDTO>(OnNewItem);
ContinueCommand = new Command<CheckListHeaderDTO>(OnContinueItem);
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 Task LoadCheckListTemplate()
{
var userId = _userService.GetCurrentUser()?.Id;
CheckListTemplate.ItemsSource = await _checkListService.GetCheckListTemplates(userId ?? 1);
}
private async Task LoadCheckList()
{
var userId = _userService.GetCurrentUser()?.Id;
CheckList.ItemsSource = await _checkListService.GetCheckLists(userId ?? 1);
} }
} }
@@ -12,9 +12,16 @@ namespace WorkFlowCheck.MAUI.Services
public class CheckListService : BaseService, ICheckListService public class CheckListService : BaseService, ICheckListService
{ {
private readonly IUserService _userService; private readonly IUserService _userService;
public CheckListService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper, IUserService userService) : base(httpClient, configuration, dbContext, mapper) private readonly ISyncService _syncService;
public CheckListService(HttpClient httpClient,
IConfiguration configuration,
AppDbContext dbContext,
IMapper mapper,
IUserService userService,
ISyncService syncService) : base(httpClient, configuration, dbContext, mapper)
{ {
_userService = userService; _userService = userService;
_syncService = syncService;
} }
public async Task<ApiResponseDTO<CheckPointDTO>> GetCheckPoint(int checkPointId) public async Task<ApiResponseDTO<CheckPointDTO>> GetCheckPoint(int checkPointId)
@@ -39,7 +46,7 @@ namespace WorkFlowCheck.MAUI.Services
{ {
await PrepareAuthenticatedRequestAsync(); await PrepareAuthenticatedRequestAsync();
// Az API végpont meghatározása // Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/checklist/startnew"; string endpoint = $"{_httpClient.BaseAddress}api/checklist/StartNewCheckList";
// HTTP POST kérés küldése // HTTP POST kérés küldése
ApiRequestDTO<CheckListTemplateHeaderDTO> request = new ApiRequestDTO<CheckListTemplateHeaderDTO>(); ApiRequestDTO<CheckListTemplateHeaderDTO> request = new ApiRequestDTO<CheckListTemplateHeaderDTO>();
@@ -69,5 +76,40 @@ namespace WorkFlowCheck.MAUI.Services
}; };
} }
} }
public async Task<List<CheckListHeaderDTO>> GetCheckLists(int userId)
{
await _syncService.SyncDatas();
var retVal = new List<CheckListHeaderDTO>();
try
{
var res = await _dbContext.CheckListHeaders.ToListAsync();
retVal = _mapper.Map<List<CheckListHeaderDTO>>(res);
}
catch (Exception ex)
{
}
return retVal;
}
public async Task<List<CheckListTemplateHeaderDTO>> GetCheckListTemplates(int userId)
{
await _syncService.SyncDatas();
var retVal = new List<CheckListTemplateHeaderDTO>();
try
{
var res = await _dbContext.CheckListTemplateHeaders.ToListAsync();
retVal = _mapper.Map<List<CheckListTemplateHeaderDTO>>(res);
}
catch (Exception ex)
{
}
return retVal;
}
} }
} }
@@ -11,5 +11,9 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces
{ {
Task<ApiResponseDTO<CheckListHeaderDTO>> StartNew(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO); Task<ApiResponseDTO<CheckListHeaderDTO>> StartNew(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO);
Task<ApiResponseDTO<CheckPointDTO>> GetCheckPoint(int checkPointId); Task<ApiResponseDTO<CheckPointDTO>> GetCheckPoint(int checkPointId);
Task<List<CheckListHeaderDTO>> GetCheckLists(int userId);
Task<List<CheckListTemplateHeaderDTO>> GetCheckListTemplates(int userId);
} }
} }
+42 -3
View File
@@ -12,9 +12,10 @@ namespace WorkFlowCheck.MAUI.Services
{ {
public class SyncService : BaseService, ISyncService public class SyncService : BaseService, ISyncService
{ {
public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper) : base(httpClient, configuration, dbContext, mapper) private readonly IUserService _userService;
public SyncService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper, IUserService userService) : base(httpClient, configuration, dbContext, mapper)
{ {
_userService = userService;
} }
public async Task SyncDatas() public async Task SyncDatas()
{ {
@@ -22,6 +23,7 @@ namespace WorkFlowCheck.MAUI.Services
await SyncLocations(); await SyncLocations();
await SyncEquipments(); await SyncEquipments();
await SyncCheckListTemplates(); await SyncCheckListTemplates();
await SyncCheckList();
} }
public async Task SyncCheckPoints() public async Task SyncCheckPoints()
{ {
@@ -119,7 +121,8 @@ namespace WorkFlowCheck.MAUI.Services
{ {
await PrepareAuthenticatedRequestAsync(); await PrepareAuthenticatedRequestAsync();
// Az API végpont meghatározása // Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListTemplateHeader"; var userId = _userService.GetCurrentUser()?.Id;
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListTemplateHeader/{userId}";
// HTTP GET kérés küldése // HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>>(endpoint); var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListTemplateHeaderDTO>>>(endpoint);
@@ -143,5 +146,41 @@ namespace WorkFlowCheck.MAUI.Services
} }
} }
public async Task SyncCheckList()
{
try
{
await PrepareAuthenticatedRequestAsync();
if (_userService == null)
{
return;
}
// Az API végpont meghatározása
var userId = _userService.GetCurrentUser()?.Id;
string endpoint = $"{_httpClient.BaseAddress}api/Sync/GetAllCheckListHeader/{userId}";
// HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<CheckListHeaderDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
var checkListHeaderList = await _dbContext.CheckListHeaders.ToListAsync();
var missingItems = response.Data.Where(f => !checkListHeaderList.Any(s => s.GuidNumber == f.GuidNumber)).ToList();
var missingCheckListHeaders = _mapper.Map<List<CheckListHeader>>(missingItems);
_dbContext.CheckListHeaders.AddRange(missingCheckListHeaders);
await _dbContext.SaveChangesAsync();
}
}
}
catch (Exception ex)
{
// Hiba visszaadása
}
}
} }
} }