Adiciona funcionalidade de upload de imagens PNG
Foi adicionada a funcionalidade de upload de imagens PNG para um local de rede específico. No backend, a interface `IImageService` e o serviço `ImageService` foram atualizados com o método assíncrono `MoveFile`, que move arquivos para o destino desejado, criando diretórios se necessário e exibindo mensagens de erro em caso de falha. No frontend, foi adicionado um botão "Upload" à interface gráfica (`MainWindow.xaml`), vinculado ao comando `UploadImageCommand` no `MainWindowViewModel`. Este comando utiliza o método privado `UploadImageAsync` para abrir uma caixa de diálogo, permitir a seleção de um arquivo PNG e mover o arquivo utilizando o serviço de imagens. Feedback ao usuário é exibido para sucesso ou erro.
This commit is contained in:
parent
47ac74d87b
commit
2636848f6d
@ -22,5 +22,6 @@ namespace BackgroundBuilder.Services
|
|||||||
BitmapImage background,
|
BitmapImage background,
|
||||||
string primaryPath,
|
string primaryPath,
|
||||||
string? overlayPath = null);
|
string? overlayPath = null);
|
||||||
|
Task MoveFile(string sourcePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -43,10 +43,27 @@ namespace BackgroundBuilder.Services
|
|||||||
|
|
||||||
var compositeBmp = RenderComposite(overlay, background, OverlayOffset);
|
var compositeBmp = RenderComposite(overlay, background, OverlayOffset);
|
||||||
SaveBitmap(compositeBmp, primaryPath);
|
SaveBitmap(compositeBmp, primaryPath);
|
||||||
SaveBitmap(compositeBmp, "\\\\SRV-DADOS\\Wallpaper$\\Wallpaper.png");
|
|
||||||
|
|
||||||
await Task.FromResult((primaryPath, savedOverlayPath));
|
await Task.FromResult((primaryPath, savedOverlayPath));
|
||||||
}
|
}
|
||||||
|
public async Task MoveFile(string sourcePath)
|
||||||
|
{
|
||||||
|
string destinationPath = "\\\\SRV-DADOS\\Wallpaper$\\Wallpaper.png";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var directory = Path.GetDirectoryName(destinationPath);
|
||||||
|
if (!Directory.Exists(directory))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(directory!);
|
||||||
|
}
|
||||||
|
File.Copy(sourcePath, destinationPath, true);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show($"Erro ao mover a imagem:\n{ex.Message}\n\nCaminho: {sourcePath} para {destinationPath}");
|
||||||
|
}
|
||||||
|
await Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Renders a <paramref name="background"/> plus the <paramref name="mainGrid"/>
|
/// Renders a <paramref name="background"/> plus the <paramref name="mainGrid"/>
|
||||||
|
|||||||
@ -62,6 +62,7 @@ namespace BackgroundBuilder.ViewModels
|
|||||||
public RelayCommand UpdateCommand { get; }
|
public RelayCommand UpdateCommand { get; }
|
||||||
public RelayCommand ExportImageCommand { get; }
|
public RelayCommand ExportImageCommand { get; }
|
||||||
public RelayCommand ImportExcelCommand { get; }
|
public RelayCommand ImportExcelCommand { get; }
|
||||||
|
public RelayCommand UploadImageCommand { get; }
|
||||||
|
|
||||||
public MainWindowViewModel(
|
public MainWindowViewModel(
|
||||||
IContatoRepository repo,
|
IContatoRepository repo,
|
||||||
@ -81,6 +82,7 @@ namespace BackgroundBuilder.ViewModels
|
|||||||
UpdateCommand = new RelayCommand(async _ => await UpdateAsync(), _ => SelectedContatos != null);
|
UpdateCommand = new RelayCommand(async _ => await UpdateAsync(), _ => SelectedContatos != null);
|
||||||
ExportImageCommand = new RelayCommand(async _ => await RenderImageAsync(), _ => BackgroundImage != null && OverlayElement != null);
|
ExportImageCommand = new RelayCommand(async _ => await RenderImageAsync(), _ => BackgroundImage != null && OverlayElement != null);
|
||||||
ImportExcelCommand = new RelayCommand(async _ => await ImportExcelAsync());
|
ImportExcelCommand = new RelayCommand(async _ => await ImportExcelAsync());
|
||||||
|
UploadImageCommand = new RelayCommand(async _ => await UploadImageAsync());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RefreshTaskbarInfo()
|
public void RefreshTaskbarInfo()
|
||||||
@ -181,6 +183,33 @@ namespace BackgroundBuilder.ViewModels
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async Task UploadImageAsync()
|
||||||
|
{
|
||||||
|
var dlg = new OpenFileDialog
|
||||||
|
{
|
||||||
|
Filter = "PNG Image|*.png"
|
||||||
|
};
|
||||||
|
if (dlg.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _imageService.MoveFile(dlg.FileName);
|
||||||
|
MessageBox.Show(
|
||||||
|
"Concluído!",
|
||||||
|
"Confirm Upload",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Information);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(
|
||||||
|
$"Erro ao mover a imagem:\n{ex.Message}",
|
||||||
|
"Upload Failed",
|
||||||
|
MessageBoxButton.OK,
|
||||||
|
MessageBoxImage.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateAsync()
|
public async Task UpdateAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -136,6 +136,7 @@
|
|||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
<ColumnDefinition Width="Auto"/>
|
<ColumnDefinition Width="Auto"/>
|
||||||
|
<ColumnDefinition Width="Auto"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<!-- Row 2: Image-->
|
<!-- Row 2: Image-->
|
||||||
<Rectangle Grid.Column="0"
|
<Rectangle Grid.Column="0"
|
||||||
@ -204,6 +205,14 @@
|
|||||||
Padding="5"
|
Padding="5"
|
||||||
Height="40"
|
Height="40"
|
||||||
Margin="5"/>
|
Margin="5"/>
|
||||||
|
<Button Content="Upload"
|
||||||
|
Command="{Binding UploadImageCommand}"
|
||||||
|
CommandParameter="MainGrid"
|
||||||
|
Grid.Column = "9"
|
||||||
|
FontWeight="Bold"
|
||||||
|
Padding="5"
|
||||||
|
Height="40"
|
||||||
|
Margin="5"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
Loading…
x
Reference in New Issue
Block a user