summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs')
-rw-r--r--Codemerx/Gestor.Application/ViewModels/ImportViewModel.cs105
1 files changed, 105 insertions, 0 deletions
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<Arquivo> _arquivos = new ObservableCollection<Arquivo>();
+
+ public ObservableCollection<Arquivo> 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<Arquivo>();
+ openFileDialog.FileNames.ToList<string>().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<Task<bool>>(() => this.Importar(this.Arquivos.ToList<Arquivo>()));
+ }
+
+ public async Task<bool> Importar(List<Arquivo> arquivos)
+ {
+ arquivos.ForEach(async (Arquivo x) => await this.Import(x));
+ return true;
+ }
+ }
+} \ No newline at end of file