MemoryStreamos a fotó ...

This commit is contained in:
2025-07-02 18:30:10 +02:00
parent bc977af15c
commit 7f3562fb73
5 changed files with 147 additions and 65 deletions
@@ -0,0 +1,66 @@
using System.ComponentModel;
using WorkFlowCheck.Common.DTO;
namespace WorkFlowCheck.MAUI.Pages.CheckList
{
public class CheckListRowCS : INotifyPropertyChanged
{
private byte[] _photoBytes;
private ImageSource? _photo;
public event PropertyChangedEventHandler PropertyChanged;
public int Id { get; set; }
public string AnswerType { get; set; } = null!;
public int RowIndex { get; set; }
public string OperationDescription { get; set; } = null!;
public string GroupName { get; set; } = null!;
public string Answer { get; set; } = null!;
public bool? AnswerYes { get; set; } = null!;
public bool? AnswerNo { get; set; } = null!;
public byte[] PhotoBytes
{
get => _photoBytes;
set
{
if (_photoBytes != value)
{
_photoBytes = value;
_photo = null;
OnPropertyChanged(nameof(PhotoBytes));
OnPropertyChanged(nameof(Photo));
}
}
}
public ImageSource Photo
{
get
{
if (_photo == null)
{
if (PhotoBytes != null && PhotoBytes.Length > 0)
{
try
{
var bytesCopy = PhotoBytes.ToArray();
_photo = ImageSource.FromStream(() => new MemoryStream(bytesCopy));
}
catch
{
_photo = ImageSource.FromFile("noimage.png");
}
}
else
{
_photo = ImageSource.FromFile("noimage.png");
}
}
return _photo;
}
}
protected void OnPropertyChanged(string name) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
@@ -48,7 +48,7 @@
<Frame BorderColor="Gray" Padding="1" Margin="2" HasShadow="True" CornerRadius="2">
<CollectionView x:Name="CheckPointCheckListRows"
HeightRequest="555"
ItemsSource="{Binding CheckListRows}"
ItemsSource="{Binding CheckListRowCSs}"
ItemTemplate="{StaticResource AnswerTemplateSelector}">
<CollectionView.EmptyView>
<Label Text="Nincsenek feladatok." HorizontalOptions="Center" VerticalOptions="Center"/>
@@ -93,8 +93,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding CheckListTemplateRowDTO.RowIndex,StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" />
<Label Text="{Binding CheckListTemplateRowDTO.OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Label Text="{Binding RowIndex,StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" />
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Grid Grid.Column="2" ColumnDefinitions="*,*">
<Label Text="I" Grid.Column="0" HorizontalTextAlignment="Center"/>
<Label Text="N" Grid.Column="1" HorizontalTextAlignment="Center"/>
@@ -126,8 +126,8 @@
<ColumnDefinition Width="3*" />
<ColumnDefinition Width="2*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding CheckListTemplateRowDTO.RowIndex,StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
<Label Text="{Binding CheckListTemplateRowDTO.OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Label Text="{Binding RowIndex,StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Grid Grid.Column="2" ColumnDefinitions="Auto,Auto" VerticalOptions="Center">
<Image Grid.Column="0"
WidthRequest="95"
@@ -135,13 +135,7 @@
Aspect="AspectFill"
Margin="0,0,10,0"
VerticalOptions="Center"
Source="{Binding Photo, Converter={StaticResource ByteArrayToImageSourceConverter}}" >
<Image.Behaviors>
<toolkit:EventToCommandBehavior
EventName="BindingContextChanged"
Command="{Binding BindingContext.RefreshImageCommand, Source={x:Reference CheckPointCheckListRows}}"
CommandParameter="{Binding .}" />
</Image.Behaviors>
Source="{Binding Photo}" >
</Image>
<Button Text="📷" Grid.Column="1"
VerticalOptions="Center"
@@ -160,8 +154,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding CheckListTemplateRowDTO.RowIndex,StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
<Label Text="{Binding CheckListTemplateRowDTO.OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Label Text="{Binding RowIndex,StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Grid Grid.Column="2" ColumnDefinitions="*">
<Label Text="Érték megadása szükséges" Grid.Column="0" HorizontalTextAlignment="Center"/>
</Grid>
@@ -181,8 +175,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding CheckListTemplateRowDTO.RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding CheckListTemplateRowDTO.OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Label Text="{Binding RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Grid Grid.Column="2" ColumnDefinitions="*,*">
<Label Text="I" Grid.Column="0" BackgroundColor="Yellow" TextColor="Black" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="N" Grid.Column="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
@@ -215,8 +209,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding CheckListTemplateRowDTO.RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding CheckListTemplateRowDTO.OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Label Text="{Binding RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Grid Grid.Column="2" ColumnDefinitions="*,*">
<Label Text="I" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="N" Grid.Column="1" BackgroundColor="Yellow" TextColor="Black" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
@@ -249,8 +243,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding CheckListTemplateRowDTO.RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding CheckListTemplateRowDTO.OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Label Text="{Binding RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Grid Grid.Column="2" ColumnDefinitions="*,*">
<Label Text="I" Grid.Column="0" BackgroundColor="Red" TextColor="Black" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="N" Grid.Column="1" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
@@ -283,8 +277,8 @@
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Text="{Binding CheckListTemplateRowDTO.RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding CheckListTemplateRowDTO.OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Label Text="{Binding RowIndex, StringFormat='{}{0:D1}.'}" BackgroundColor="WhiteSmoke" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="{Binding OperationDescription}" BackgroundColor="WhiteSmoke" Grid.Column="1" />
<Grid Grid.Column="2" ColumnDefinitions="*,*">
<Label Text="I" Grid.Column="0" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
<Label Text="N" Grid.Column="1" BackgroundColor="Red" TextColor="Black" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"/>
@@ -316,6 +310,5 @@
PI_N_Template="{StaticResource PI_N_Template}"
I_PN_Template="{StaticResource I_PN_Template}"
V_Template="{StaticResource V_Template}"/>
<local:ByteArrayToImageSourceConverter x:Key="ByteArrayToImageSourceConverter"/>
</ContentPage.Resources>
</ContentPage>
@@ -29,13 +29,9 @@ public partial class CheckListWorkPage : ContentPage
OnPropertyChanged(nameof(IsLoading));
}
}
public ObservableCollection<CheckListRowDTO> CheckListRows { get; set; } = new ObservableCollection<CheckListRowDTO>();
public ICommand RefreshImageCommand => new Command<CheckListRowDTO>(item =>
{
int i = 0;
// Ha kell, itt újra lehet állítani valamit vagy logolni
//Debug.WriteLine($"Kép frissítés: {item.Id}");
});
public ObservableCollection<CheckListRowCS> CheckListRowCSs { get; set; } = new ObservableCollection<CheckListRowCS>();
public List<CheckListRowDTO> CheckListRowDTOs { get; set; }
public ICommand TakePhoto { get; set; }
public ICommand SendCommand { get; set; }
public ICommand SaveCommand { get; set; }
@@ -122,17 +118,22 @@ public partial class CheckListWorkPage : ContentPage
{
await Task.Run(async () =>
{
foreach (var checkListRow in CheckListRows)
foreach (var checkListRowCS in CheckListRowCSs)
{
if (checkListRow.AnswerYes == true)
var checkListRowDTO = CheckListRowDTOs.Where(w => w.Id == checkListRowCS.Id).FirstOrDefault();
if (checkListRowDTO != null)
{
checkListRow.Answer = "Igen";
if (checkListRowDTO.AnswerYes == true)
{
checkListRowDTO.Answer = "Igen";
}
if (checkListRowDTO.AnswerNo == true)
{
checkListRowDTO.Answer = "Nem";
}
await _checkListService.UpdateCheckListRow(checkListRowDTO, withReload);
}
if (checkListRow.AnswerNo == true)
{
checkListRow.Answer = "Nem";
}
await _checkListService.UpdateCheckListRow(checkListRow, withReload);
}
if (withReload) await LoadCheckPointCheckListRows();
});
@@ -152,7 +153,7 @@ public partial class CheckListWorkPage : ContentPage
base.OnAppearing();
BindingContext = this;
await SetInfo();
TakePhoto = new Command<CheckListRowDTO>(OnTakePhoto);
TakePhoto = new Command<CheckListRowCS>(OnTakePhoto);
await LoadCheckPointCheckListRows();
}
@@ -175,7 +176,7 @@ public partial class CheckListWorkPage : ContentPage
return data.ToArray();
}
private async void OnTakePhoto(CheckListRowDTO checkListRowDTO)
private async void OnTakePhoto(CheckListRowCS checkListRowCS)
{
try
{
@@ -185,11 +186,18 @@ public partial class CheckListWorkPage : ContentPage
var photo = await MediaPicker.CapturePhotoAsync();
if (photo != null)
{
checkListRowDTO.Photo = await ResizePicture(photo, 500);
checkListRowDTO.Answer = "Igen";
checkListRowCS.PhotoBytes = await ResizePicture(photo, 500);
checkListRowCS.Answer = "Igen";
await _checkListService.UpdateCheckListRow(checkListRowDTO, true);
await LoadCheckPointCheckListRows();
var checkListRowDTO = CheckListRowDTOs.FirstOrDefault(w => w.Id == checkListRowCS.Id);
if (checkListRowDTO != null)
{
checkListRowDTO.Photo = checkListRowCS.PhotoBytes;
checkListRowDTO.Answer = "Igen";
await _checkListService.UpdateCheckListRow(checkListRowDTO, true);
await LoadCheckPointCheckListRows();
}
}
}
else
@@ -206,9 +214,11 @@ public partial class CheckListWorkPage : ContentPage
{
IsLoading = true;
CheckListRows.Clear();
var checkListRowDTOs = await _checkListService.GetCheckListRowsByCheckPointCode(_currentUser.Id, _checkListHeaderId, _checkPointCode);
foreach (var item in checkListRowDTOs)
CheckListRowCSs.Clear();
CheckListRowDTOs = await _checkListService.GetCheckListRowsByCheckPointCode(_currentUser.Id, _checkListHeaderId, _checkPointCode);
foreach (var item in CheckListRowDTOs)
{
if (item.Answer == "Igen")
{
@@ -220,7 +230,20 @@ public partial class CheckListWorkPage : ContentPage
item.AnswerYes = false;
item.AnswerNo = true;
}
CheckListRows.Add(item);
var checkListRowCS = new CheckListRowCS()
{
Answer = item.Answer,
AnswerNo = item.AnswerNo,
AnswerYes = item.AnswerYes,
GroupName = $"AnswerGroup_{item.CheckListTemplateRowDTO?.Id ?? 0}",
Id = item.Id,
RowIndex = item.CheckListTemplateRowDTO?.RowIndex ?? 0,
OperationDescription = item.CheckListTemplateRowDTO?.OperationDescription ?? "N/A",
AnswerType = item.CheckListTemplateRowDTO?.AnswerType ?? "I-N",
PhotoBytes = item.Photo ?? Array.Empty<byte>(),
};
CheckListRowCSs.Add(checkListRowCS);
}
IsLoading = false;
@@ -273,19 +296,4 @@ public class BindableRadioButton : RadioButton
}
}
}
public class ByteArrayToImageSourceConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is byte[] bytes && bytes.Length > 0)
{
return ImageSource.FromStream(() => new MemoryStream(bytes));
}
return ImageSource.FromFile("noimage.png"); ;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
@@ -218,7 +218,7 @@ namespace WorkFlowCheck.MAUI.Services
{
if (responseList.IsSuccess)
{
var entityList = await _dbContext.Locations.ToListAsync();
var entityList = await _dbContext.Equipments.ToListAsync();
var missingItems = responseList.Data.Where(f => !entityList.Any(s => s.Id == f.Id)).ToList();
var mappedMissingItems = _mapper.Map<List<Equipment>>(missingItems);
@@ -50,6 +50,21 @@ namespace WorkFlowCheck.MAUI.TemplateSelectors
_ => I_N_Template
};
}
if (item is CheckListRowCS model3)
{
return model3.AnswerType switch
{
"I-N" => I_N_Template,
"P" => P_Template,
"PN" => 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;
}