summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Drawer/Ajuda/ContratosViewModel.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Codemerx/Gestor.Application/ViewModels/Drawer/Ajuda/ContratosViewModel.cs')
-rw-r--r--Codemerx/Gestor.Application/ViewModels/Drawer/Ajuda/ContratosViewModel.cs112
1 files changed, 112 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/ViewModels/Drawer/Ajuda/ContratosViewModel.cs b/Codemerx/Gestor.Application/ViewModels/Drawer/Ajuda/ContratosViewModel.cs
new file mode 100644
index 0000000..fe46bb4
--- /dev/null
+++ b/Codemerx/Gestor.Application/ViewModels/Drawer/Ajuda/ContratosViewModel.cs
@@ -0,0 +1,112 @@
+using Gestor.Application.Helpers;
+using Gestor.Application.Model.Ajuda;
+using Gestor.Application.Servicos.Ajuda;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Common.Validation;
+using Gestor.Model.Domain.Common;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.License;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+
+namespace Gestor.Application.ViewModels.Drawer.Ajuda
+{
+ public class ContratosViewModel : BaseViewModel
+ {
+ private readonly AjudaServico _ajudaServico;
+
+ private bool _carregando;
+
+ private List<Licenca> _contratos;
+
+ private Licenca _selectedContrato;
+
+ public bool Carregando
+ {
+ get
+ {
+ return this._carregando;
+ }
+ set
+ {
+ this._carregando = value;
+ base.IsEnabled = !value;
+ base.EnableMenu = !value;
+ base.OnPropertyChanged("Carregando");
+ }
+ }
+
+ public List<Licenca> Contratos
+ {
+ get
+ {
+ return this._contratos;
+ }
+ set
+ {
+ this._contratos = value;
+ base.OnPropertyChanged("Contratos");
+ }
+ }
+
+ public Licenca SelectedContrato
+ {
+ get
+ {
+ return this._selectedContrato;
+ }
+ set
+ {
+ this._selectedContrato = value;
+ this.WorkOnSelectedContrato(value);
+ base.OnPropertyChanged("SelectedContrato");
+ }
+ }
+
+ public ContratosViewModel()
+ {
+ this._ajudaServico = new AjudaServico();
+ this.Contratos = LicenseHelper.Produtos;
+ }
+
+ internal async void WorkOnSelectedContrato(Licenca value)
+ {
+ Contrato contrato = await this._ajudaServico.BuscarContrato(value.get_Produto());
+ if (!string.IsNullOrEmpty(contrato.HtmlContrato) || contrato.IdModulo != (long)7)
+ {
+ if (string.IsNullOrEmpty(contrato.HtmlContrato) && contrato.IdModulo != (long)7)
+ {
+ contrato = await this._ajudaServico.BuscarContrato(1);
+ }
+ string empty = string.Empty;
+ LicenseHelper.Produtos.ForEach((Licenca x) => empty = string.Concat(empty, (string.IsNullOrEmpty(empty) ? ValidationHelper.GetDescription(x.get_Produto()) : string.Concat("/ ", ValidationHelper.GetDescription(x.get_Produto())))));
+ contrato.HtmlContrato = contrato.HtmlContrato.Replace("[&lt;NOME&gt;]", Recursos.Empresa.get_Nome());
+ contrato.HtmlContrato = contrato.HtmlContrato.Replace("[&lt;ENDERECO&gt;]", Recursos.Empresa.get_Endereco());
+ contrato.HtmlContrato = contrato.HtmlContrato.Replace("[&lt;CIDADE&gt;]", Recursos.Empresa.get_Cidade());
+ contrato.HtmlContrato = contrato.HtmlContrato.Replace("[&lt;CNPJ&gt;]", Recursos.Empresa.get_Documento());
+ contrato.HtmlContrato = contrato.HtmlContrato.Replace("[&lt;NS&gt;]", Recursos.Empresa.get_Serial());
+ string htmlContrato = contrato.HtmlContrato;
+ DateTime date = Funcoes.GetNetworkTime().Date;
+ contrato.HtmlContrato = htmlContrato.Replace("[&lt;DATA&gt;]", date.ToString("dd/MM/yyyy"));
+ contrato.HtmlContrato = contrato.HtmlContrato.Replace("[&lt;VALOR&gt;]", "Conforme Mensalidade");
+ contrato.HtmlContrato = contrato.HtmlContrato.Replace("[&lt;OUTROS&gt;]", empty.Replace("*", ""));
+ string tempPath = Path.GetTempPath();
+ string str = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, (new Regex(string.Concat("[", Regex.Escape(string.Concat(new string(Path.GetInvalidFileNameChars()), new string(Path.GetInvalidPathChars()))), "]"))).Replace(ValidationHelper.GetDescription(value.get_Produto()), ""), Funcoes.GetNetworkTime());
+ StreamWriter streamWriter = new StreamWriter(str, true, Encoding.UTF8);
+ streamWriter.Write(contrato.HtmlContrato);
+ streamWriter.Close();
+ Process.Start(str);
+ }
+ else
+ {
+ Process.Start(string.Format("https://aggilizador.com.br/Contrato.aspx?id={0}", ApplicationHelper.IdFornecedor));
+ }
+ }
+ }
+} \ No newline at end of file