summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/ViewModels/Drawer/LogEmailViewModel.cs
blob: 8a716357b2f4a7d71dd981be9a888ea0577d2e0f (plain)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
using Gestor.Application.Helpers;
using Gestor.Application.Servicos;
using Gestor.Application.ViewModels.Generic;
using Gestor.Model.Common;
using Gestor.Model.Domain.Configuracoes;
using Gestor.Model.Domain.Ferramentas;
using Gestor.Model.Domain.Seguros;
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.Text;
using System.Threading.Tasks;
using System.Windows;

namespace Gestor.Application.ViewModels.Drawer
{
	public class LogEmailViewModel : BaseSegurosViewModel
	{
		private readonly LogServico _servico;

		private Visibility _visibilityDetalhesLog = Visibility.Hidden;

		private bool _mostrarMensagem;

		private ObservableCollection<LogEmail> _logs = new ObservableCollection<LogEmail>();

		private LogEmail _selectedLog;

		private List<TupleList> _lists = new List<TupleList>();

		public List<TupleList> Lists
		{
			get
			{
				return this._lists;
			}
			set
			{
				this._lists = value;
				base.OnPropertyChanged("Lists");
			}
		}

		public ObservableCollection<LogEmail> Logs
		{
			get
			{
				return this._logs;
			}
			set
			{
				this._logs = value;
				base.OnPropertyChanged("Logs");
			}
		}

		public bool MostrarMensagem
		{
			get
			{
				return this._mostrarMensagem;
			}
			set
			{
				this._mostrarMensagem = value;
				base.OnPropertyChanged("MostrarMensagem");
			}
		}

		public LogEmail SelectedLog
		{
			get
			{
				return this._selectedLog;
			}
			set
			{
				this._selectedLog = value;
				this.Lists = this.SelectedLog.CriarLogEmail();
				base.OnPropertyChanged("SelectedLog");
			}
		}

		public Visibility VisiblityDetalhesLog
		{
			get
			{
				return this._visibilityDetalhesLog;
			}
			set
			{
				this._visibilityDetalhesLog = value;
				base.OnPropertyChanged("VisiblityDetalhesLog");
			}
		}

		public LogEmailViewModel(TipoTela tela, long id, bool singleMode)
		{
			this._servico = new LogServico();
			this.VisiblityDetalhesLog = (Recursos.Configuracoes.Any<ConfiguracaoSistema>((ConfiguracaoSistema c) => c.get_Configuracao() == 55) ? Visibility.Visible : Visibility.Hidden);
			this.Seleciona(tela, id, singleMode);
		}

		public void Imprimir()
		{
			string str = "<html><head><style type='text/css'>@page{size: A4; margin: 0cm}</style><title>LOGS</title><link rel='stylesheet' href='https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css' integrity='sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh' crossorigin='anonymous'></head><body><div align='center'><font size='5px' face='Arial' style='font-weight: 900;'>LOG ENVIO DE E-MAIL</font>";
			foreach (TupleList list in this.Lists)
			{
				foreach (Tuple<string, string, string> tuple in list.get_Tuples())
				{
					if (tuple == list.get_Tuples().First<Tuple<string, string, string>>())
					{
						str = string.Concat(str, "<table border='1' style='border-collapse: collapse; page-break-inside: avoid'><tr style='height: 45px;'><td style='width: 220px; text-align: center;'><font size='3px' face='Arial' style='font-weight: 700;'>DESCRIÇÃO</font></td><td style='width: 240px; text-align:center;'><font size='3px' face='Arial' style='font-weight: 700'>E-MAIL ENVIADO</font></td>");
						str = string.Concat(str, "</tr></table>");
					}
					bool flag = tuple.Item1.Contains("$");
					string[] item2 = new string[] { str, "<table border='1' style='border-collapse: collapse; page-break-inside: avoid; border-TOP: none'><tr style='height: 30px;'><td style='width: 220px'><font size='2px' face='Arial' style='font-weight: ", null, null, null, null, null, null };
					item2[2] = (flag ? "900" : "700");
					item2[3] = "; padding-left: 5px'>";
					item2[4] = tuple.Item1.Replace(" ", "&nbsp;").Replace("$", "");
					item2[5] = "</font></td><td style='width: 240px'><font size='2px' face='Arial' style='padding-left: 5px'>";
					item2[6] = tuple.Item2;
					item2[7] = "</font></td>";
					str = string.Concat(item2);
					str = string.Concat(str, "</tr></table>");
				}
			}
			str = string.Concat(str, "</div><script src='https://code.jquery.com/jquery-3.4.1.slim.min.js' integrity='sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n' crossorigin='anonymous'></script><script src = 'https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js' integrity = 'sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo' crossorigin = 'anonymous' ></script ><script src = 'https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js' integrity = 'sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6' crossorigin = 'anonymous' ></script > </body></html>");
			string tempPath = Path.GetTempPath();
			string str1 = string.Format("{0}{1}_{2:ddMMyyyyhhmmss}.html", tempPath, (TipoExtrato)0, Funcoes.GetNetworkTime());
			StreamWriter streamWriter = new StreamWriter(str1, true, Encoding.UTF8);
			streamWriter.Write(str);
			streamWriter.Close();
			Process.Start(str1);
		}

		private async void Seleciona(TipoTela tela, long id, bool singleMode)
		{
			base.Loading(true);
			if (!singleMode)
			{
				this.Logs = await this._servico.FindByEntity(tela, id);
			}
			else
			{
				this.Logs = await this._servico.FindById(id);
			}
			if (this.Logs.Count <= 0)
			{
				this.MostrarMensagem = true;
			}
			else
			{
				this.SelectedLog = this.Logs[0];
			}
			base.Loading(false);
		}
	}
}