1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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("[<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));
}
}
}
}
|