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 _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 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("[<NOME>]", Recursos.Empresa.get_Nome()); contrato.HtmlContrato = contrato.HtmlContrato.Replace("[<ENDERECO>]", Recursos.Empresa.get_Endereco()); contrato.HtmlContrato = contrato.HtmlContrato.Replace("[<CIDADE>]", Recursos.Empresa.get_Cidade()); contrato.HtmlContrato = contrato.HtmlContrato.Replace("[<CNPJ>]", Recursos.Empresa.get_Documento()); contrato.HtmlContrato = contrato.HtmlContrato.Replace("[<NS>]", Recursos.Empresa.get_Serial()); string htmlContrato = contrato.HtmlContrato; DateTime date = Funcoes.GetNetworkTime().Date; contrato.HtmlContrato = htmlContrato.Replace("[<DATA>]", date.ToString("dd/MM/yyyy")); contrato.HtmlContrato = contrato.HtmlContrato.Replace("[<VALOR>]", "Conforme Mensalidade"); contrato.HtmlContrato = contrato.HtmlContrato.Replace("[<OUTROS>]", 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)); } } } }