From 2636848f6def995d65fdb953d0f2dae1898c0ac9 Mon Sep 17 00:00:00 2001 From: Giuliano Paschoalino Date: Thu, 28 Aug 2025 15:24:44 -0300 Subject: [PATCH] Adiciona funcionalidade de upload de imagens PNG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- Services/IImageService.cs | 1 + Services/ImageService.cs | 19 ++++++++++++++++++- ViewModels/MainWindowViewModel.cs | 29 +++++++++++++++++++++++++++++ Views/MainWindow.xaml | 9 +++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) diff --git a/Services/IImageService.cs b/Services/IImageService.cs index b4b8e5f..1eb24ff 100644 --- a/Services/IImageService.cs +++ b/Services/IImageService.cs @@ -22,5 +22,6 @@ namespace BackgroundBuilder.Services BitmapImage background, string primaryPath, string? overlayPath = null); + Task MoveFile(string sourcePath); } } diff --git a/Services/ImageService.cs b/Services/ImageService.cs index 415f0c0..e9b8abf 100644 --- a/Services/ImageService.cs +++ b/Services/ImageService.cs @@ -43,10 +43,27 @@ namespace BackgroundBuilder.Services var compositeBmp = RenderComposite(overlay, background, OverlayOffset); SaveBitmap(compositeBmp, primaryPath); - SaveBitmap(compositeBmp, "\\\\SRV-DADOS\\Wallpaper$\\Wallpaper.png"); 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; + } /// /// Renders a plus the diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs index dbafde8..cc59bef 100644 --- a/ViewModels/MainWindowViewModel.cs +++ b/ViewModels/MainWindowViewModel.cs @@ -62,6 +62,7 @@ namespace BackgroundBuilder.ViewModels public RelayCommand UpdateCommand { get; } public RelayCommand ExportImageCommand { get; } public RelayCommand ImportExcelCommand { get; } + public RelayCommand UploadImageCommand { get; } public MainWindowViewModel( IContatoRepository repo, @@ -81,6 +82,7 @@ namespace BackgroundBuilder.ViewModels UpdateCommand = new RelayCommand(async _ => await UpdateAsync(), _ => SelectedContatos != null); ExportImageCommand = new RelayCommand(async _ => await RenderImageAsync(), _ => BackgroundImage != null && OverlayElement != null); ImportExcelCommand = new RelayCommand(async _ => await ImportExcelAsync()); + UploadImageCommand = new RelayCommand(async _ => await UploadImageAsync()); } 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() { diff --git a/Views/MainWindow.xaml b/Views/MainWindow.xaml index 07d295b..2afa39d 100644 --- a/Views/MainWindow.xaml +++ b/Views/MainWindow.xaml @@ -136,6 +136,7 @@ + +