diff --git a/src/WorkFlowCheck.Common/DTO/CheckListRowDTO.cs b/src/WorkFlowCheck.Common/DTO/CheckListRowDTO.cs index f16624e..88038c9 100644 --- a/src/WorkFlowCheck.Common/DTO/CheckListRowDTO.cs +++ b/src/WorkFlowCheck.Common/DTO/CheckListRowDTO.cs @@ -11,7 +11,8 @@ namespace WorkFlowCheck.Common.DTO public int Id { get; set; } public int CheckListHeaderId { get; set; } public int CheckListTemplateRowId { get; set; } - public virtual CheckListTemplateRowDTO CheckListTemplateRowDTO { get; set; } + public CheckListTemplateRowDTO CheckListTemplateRowDTO { get; set; } + public string GroupName => $"AnswerGroup_{CheckListTemplateRowDTO.RowIndex}"; public string Answer { get; set; } = null!; public byte[] Photo { get; set; } = null!; public Guid GuidNumber { get; set; } diff --git a/src/WorkFlowCheck.MAUI/Mapper/MapperProfile.cs b/src/WorkFlowCheck.MAUI/Mapper/MapperProfile.cs index 7695465..f7feae6 100644 --- a/src/WorkFlowCheck.MAUI/Mapper/MapperProfile.cs +++ b/src/WorkFlowCheck.MAUI/Mapper/MapperProfile.cs @@ -27,6 +27,9 @@ namespace WorkFlowCheck.MAUI.Mapper .ForMember(dest => dest.CheckListRowDTO, opt => opt.MapFrom(src => src.CheckListRows)); CreateMap() .ForMember(dest => dest.CheckListRows, opt => opt.MapFrom(src => src.CheckListRowDTO)); + CreateMap() + .ForMember(dest => dest.CheckListTemplateRowDTO, opt => opt.MapFrom(src => src.CheckListTemplateRow)); + CreateMap(); } } } diff --git a/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointEditPage.xaml b/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointEditPage.xaml index 27790ab..fdb2368 100644 --- a/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointEditPage.xaml +++ b/src/WorkFlowCheck.MAUI/Pages/BaseStock/CheckPoints/CheckPointEditPage.xaml @@ -3,6 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="WorkFlowCheck.MAUI.Pages.BaseStock.CheckPoints.CheckPointEditPage" xmlns:local="clr-namespace:WorkFlowCheck.MAUI.Pages.BaseStock.CheckPoints" + xmlns:templateselectors="clr-namespace:WorkFlowCheck.MAUI.TemplateSelectors" Title="{Binding CheckPointDTO.ShortName}"> @@ -143,7 +144,7 @@ - I_N_Template, - "P" => P_Template, - "V" => V_Template, - "SI-N" => SI_N_Template, - "I-SN" => I_SN_Template, - "PI-N" => PI_N_Template, - "I-PN" => I_PN_Template, - _ => I_N_Template - }; - } - - return null; - } -} \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs index a0247f7..9011d31 100644 --- a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListPage.xaml.cs @@ -44,9 +44,13 @@ public partial class CheckListPage : ContentPage { var taskCompletionSource = new TaskCompletionSource(); await Navigation.PushAsync(new NFCWaiter(taskCompletionSource)); - var result = await taskCompletionSource.Task; + var checkPintCode = await taskCompletionSource.Task; + if (!string.IsNullOrEmpty(checkPintCode)) + { + await Navigation.PopAsync(); + await Navigation.PushAsync(new CheckListWorkPage(checkListHeaderDTO.Id, checkPintCode)); + } - } private async Task LoadCheckListTemplate() diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml new file mode 100644 index 0000000..a71f3bc --- /dev/null +++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml @@ -0,0 +1,206 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml.cs b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml.cs new file mode 100644 index 0000000..233e006 --- /dev/null +++ b/src/WorkFlowCheck.MAUI/Pages/CheckList/CheckListWorkPage.xaml.cs @@ -0,0 +1,54 @@ +using WorkFlowCheck.Common.DTO; +using WorkFlowCheck.MAUI.Services.Interfaces; +using Microsoft.Maui.Controls; + +namespace WorkFlowCheck.MAUI.Pages.CheckList; + +public partial class CheckListWorkPage : ContentPage +{ + private readonly ICheckListService _checkListService; + private string _checkPointCode; + private int _checkListHeaderId; + private UserDTO _userDTO; + + + public CheckListWorkPage(int checkListHeaderId, string checkPointCode) + { + InitializeComponent(); + _checkPointCode = checkPointCode; + _checkListHeaderId = checkListHeaderId; + _checkListService = MauiProgram.ServiceProvider.GetRequiredService(); + _userDTO = MauiProgram.ServiceProvider.GetRequiredService().GetCurrentUser(); + } + protected override async void OnAppearing() + { + base.OnAppearing(); + BindingContext = this; + + await LoadCheckPointCheckListRows(); + } + + private async Task LoadCheckPointCheckListRows() + { + CheckPointCheckListRows.ItemsSource = await _checkListService.GetCheckListRowsByCheckPointCode(_userDTO.Id, _checkListHeaderId, _checkPointCode); + } +} +public class BindableRadioButton : RadioButton +{ + public static readonly BindableProperty BindableGroupNameProperty = + BindableProperty.Create(nameof(BindableGroupName), typeof(string), typeof(BindableRadioButton), default(string), propertyChanged: OnGroupNameChanged); + + public string BindableGroupName + { + get => (string)GetValue(BindableGroupNameProperty); + set => SetValue(BindableGroupNameProperty, value); + } + + private static void OnGroupNameChanged(BindableObject bindable, object oldValue, object newValue) + { + if (bindable is BindableRadioButton radioButton && newValue is string newGroupName) + { + radioButton.GroupName = newGroupName; + } + } +} \ 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 index 2546270..84f9b07 100644 --- a/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml.cs +++ b/src/WorkFlowCheck.MAUI/Pages/NFC/NFCWaiter.xaml.cs @@ -59,7 +59,7 @@ public partial class NFCWaiter : ContentPage } catch (Exception ex) { - await ShowAlert(ex.Message); + //await ShowAlert(ex.Message); } } async Task EndListening() @@ -76,7 +76,7 @@ public partial class NFCWaiter : ContentPage } catch (Exception ex) { - await ShowAlert(ex.Message); + //await ShowAlert(ex.Message); } } void SubscribeEvents() diff --git a/src/WorkFlowCheck.MAUI/Services/CheckListService.cs b/src/WorkFlowCheck.MAUI/Services/CheckListService.cs index ef77bc9..fe6ea45 100644 --- a/src/WorkFlowCheck.MAUI/Services/CheckListService.cs +++ b/src/WorkFlowCheck.MAUI/Services/CheckListService.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using System.Net.Http.Json; +using System.Runtime.CompilerServices; using WorkFlowCheck.Common.DTO; using WorkFlowCheck.MAUI.DataLayer; using WorkFlowCheck.MAUI.Services.Interfaces; @@ -13,10 +14,10 @@ namespace WorkFlowCheck.MAUI.Services { private readonly IUserService _userService; private readonly ISyncService _syncService; - public CheckListService(HttpClient httpClient, - IConfiguration configuration, - AppDbContext dbContext, - IMapper mapper, + public CheckListService(HttpClient httpClient, + IConfiguration configuration, + AppDbContext dbContext, + IMapper mapper, IUserService userService, ISyncService syncService) : base(httpClient, configuration, dbContext, mapper) { @@ -96,20 +97,46 @@ namespace WorkFlowCheck.MAUI.Services public async Task> GetCheckListTemplates(int userId) { - await _syncService.SyncDatas(); - + await _syncService.SyncDatas(); + var retVal = new List(); try { - var res = await _dbContext.CheckListTemplateHeaders.ToListAsync(); + var res = await _dbContext.CheckListTemplateHeaders.ToListAsync(); retVal = _mapper.Map>(res); } catch (Exception ex) { - + } return retVal; } - + + public async Task> GetCheckListRowsByCheckPointCode(int userId, int checkListHeaderId, string checkPointCode) + { + var retVal = new List(); + + try + { + var checkListRows = await _dbContext.CheckListRows + .Include(i => i.CheckListTemplateRow) + .ThenInclude(i => i.CheckPoint) + .Include(i => i.CheckListHeader) + .Where(w => w.CheckListTemplateRow.CheckPoint.Code == checkPointCode && + w.CheckListHeader.UserId == userId && + w.CheckListHeaderId == checkListHeaderId) + .AsNoTracking() + .ToListAsync(); + retVal = _mapper.Map>(checkListRows); + } + catch (Exception ex) + { + + + } + + + return retVal; + } } } diff --git a/src/WorkFlowCheck.MAUI/Services/Interfaces/ICheckListService.cs b/src/WorkFlowCheck.MAUI/Services/Interfaces/ICheckListService.cs index f764b0b..33d15a4 100644 --- a/src/WorkFlowCheck.MAUI/Services/Interfaces/ICheckListService.cs +++ b/src/WorkFlowCheck.MAUI/Services/Interfaces/ICheckListService.cs @@ -15,5 +15,6 @@ namespace WorkFlowCheck.MAUI.Services.Interfaces Task> GetCheckLists(int userId); Task> GetCheckListTemplates(int userId); + Task> GetCheckListRowsByCheckPointCode(int userId, int checkListHeaderId, string checkPointCode); } } diff --git a/src/WorkFlowCheck.MAUI/Services/SyncService.cs b/src/WorkFlowCheck.MAUI/Services/SyncService.cs index ca78e3a..e7dd728 100644 --- a/src/WorkFlowCheck.MAUI/Services/SyncService.cs +++ b/src/WorkFlowCheck.MAUI/Services/SyncService.cs @@ -220,7 +220,32 @@ namespace WorkFlowCheck.MAUI.Services _dbContext.CheckListHeaders.AddRange(missingCheckListHeaders); await _dbContext.SaveChangesAsync(); + + foreach (var item in missingItems) + { + var checkListHeaderDTO = item as CheckListHeaderDTO; + + foreach (var checkListRowDTO in checkListHeaderDTO.CheckListRowDTO) + { + var checkListRow = _dbContext.CheckListRows.Where(w => w.GuidNumber == checkListRowDTO.GuidNumber).FirstOrDefault(); + var isAdd = false; + if (checkListRow == null) + { + isAdd = true; + checkListRow = new CheckListRow(); + checkListRow.CheckListHeaderId = checkListHeaderDTO.Id; + } + checkListRow.Answer = checkListRowDTO.Answer; + checkListRow.CheckListTemplateRowId = checkListRowDTO.CheckListTemplateRowId; + checkListRow.GuidNumber = checkListRowDTO.GuidNumber; + checkListRow.Photo = checkListRowDTO.Photo; + + if (isAdd) _dbContext.CheckListRows.Add(checkListRow); + await _dbContext.SaveChangesAsync(); + } + } } + } } catch (Exception ex) diff --git a/src/WorkFlowCheck.MAUI/TemplateSelectors/AnswerTypeTemplateSelector.cs b/src/WorkFlowCheck.MAUI/TemplateSelectors/AnswerTypeTemplateSelector.cs new file mode 100644 index 0000000..ab1238b --- /dev/null +++ b/src/WorkFlowCheck.MAUI/TemplateSelectors/AnswerTypeTemplateSelector.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WorkFlowCheck.Common.DTO; + +namespace WorkFlowCheck.MAUI.TemplateSelectors +{ + public class AnswerTypeTemplateSelector : DataTemplateSelector + { + public DataTemplate I_N_Template { get; set; } + public DataTemplate P_Template { get; set; } + public DataTemplate V_Template { get; set; } + public DataTemplate SI_N_Template { get; set; } + public DataTemplate I_SN_Template { get; set; } + public DataTemplate PI_N_Template { get; set; } + public DataTemplate I_PN_Template { get; set; } + + protected override DataTemplate OnSelectTemplate(object item, BindableObject container) + { + if (item is CheckListTemplateRowDTO model) + { + return model.AnswerType switch + { + "I-N" => I_N_Template, + "P" => P_Template, + "V" => V_Template, + "SI-N" => SI_N_Template, + "I-SN" => I_SN_Template, + "PI-N" => PI_N_Template, + "I-PN" => I_PN_Template, + _ => I_N_Template + }; + } + if (item is CheckListRowDTO model2) + { + return model2.CheckListTemplateRowDTO.AnswerType switch + { + "I-N" => I_N_Template, + "P" => P_Template, + "V" => V_Template, + "SI-N" => SI_N_Template, + "I-SN" => I_SN_Template, + "PI-N" => PI_N_Template, + "I-PN" => I_PN_Template, + _ => I_N_Template + }; + } + + return null; + } + } +} diff --git a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj index 11aefb3..0d54262 100644 --- a/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj +++ b/src/WorkFlowCheck.MAUI/WorkFlowCheck.MAUI.csproj @@ -109,6 +109,9 @@ MSBuild:Compile + + MSBuild:Compile + MSBuild:Compile