From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../ViewModels/ImportViewModel.cs | 105 +++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs (limited to 'Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs') diff --git a/Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs b/Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs new file mode 100644 index 0000000..48249e7 --- /dev/null +++ b/Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs @@ -0,0 +1,105 @@ +using Gestor.Application.Helpers; +using Gestor.Application.ViewModels.Generic; +using Gestor.Model.Domain.Generic; +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; + +namespace Gestor.Application.ViewModels +{ + public class ImportViewModel : BaseViewModel + { + private ObservableCollection _arquivos = new ObservableCollection(); + + public ObservableCollection Arquivos + { + get + { + return this._arquivos; + } + set + { + this._arquivos = value; + base.OnPropertyChanged("Arquivos"); + } + } + + public ImportViewModel() + { + } + + public void CarregarArquivos() + { + OpenFileDialog openFileDialog = new OpenFileDialog() + { + Title = "Selecione o PDF", + Filter = "Arquivos PDF|*.pdf", + Multiselect = true + }; + if (!openFileDialog.ShowDialog().GetValueOrDefault()) + { + return; + } + this.Arquivos = new ObservableCollection(); + openFileDialog.FileNames.ToList().ForEach((string x) => this.Arquivos.Add(new Arquivo() + { + Nome = x, + Processo = 0 + })); + } + + public async Task Import(Arquivo arquivo) + { + await Task.Run(() => { + try + { + Process process = new Process() + { + StartInfo = new ProcessStartInfo() + { + FileName = "C:\\AggerSeguros\\Agger.Import201911261630\\Agger.ImportPDF.exe", + Arguments = string.Format(" {0} {1} NOVOGESTOR {2}", Recursos.Empresa.get_Id(), Recursos.Usuario.get_Id(), arquivo.Nome), + UseShellExecute = false, + RedirectStandardOutput = true, + CreateNoWindow = true + } + }; + process.Start(); + process.WaitForExit(); + string end = process.StandardError.ReadToEnd(); + string str = process.StandardOutput.ReadToEnd(); + if (process.ExitCode != 0) + { + string[] strArrays = new string[] { "netsh exit code: ", null, null, null, null, null }; + strArrays[1] = process.ExitCode.ToString(); + strArrays[2] = " "; + strArrays[3] = (!string.IsNullOrEmpty(end) ? string.Concat(" ", end) : ""); + strArrays[4] = " "; + strArrays[5] = (!string.IsNullOrEmpty(str) ? string.Concat(" ", str) : ""); + throw new Exception(string.Concat(strArrays)); + } + } + catch (Exception exception) + { + } + }); + } + + public void Importar() + { + (new TaskFactory()).StartNew>(() => this.Importar(this.Arquivos.ToList())); + } + + public async Task Importar(List arquivos) + { + arquivos.ForEach(async (Arquivo x) => await this.Import(x)); + return true; + } + } +} \ No newline at end of file -- cgit v1.2.3