diff options
Diffstat (limited to 'Gestor.Application/ViewModels/AnaliticoViewModel.cs')
| -rw-r--r-- | Gestor.Application/ViewModels/AnaliticoViewModel.cs | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/Gestor.Application/ViewModels/AnaliticoViewModel.cs b/Gestor.Application/ViewModels/AnaliticoViewModel.cs new file mode 100644 index 0000000..bdf394b --- /dev/null +++ b/Gestor.Application/ViewModels/AnaliticoViewModel.cs @@ -0,0 +1,210 @@ +using Gestor.Application.Helpers;
+using Gestor.Application.Servicos;
+using Gestor.Application.Servicos.Generic;
+using Gestor.Application.ViewModels.Generic;
+using Gestor.Model.Common;
+using Gestor.Model.Domain.BI;
+using Gestor.Model.Domain.Ferramentas;
+using Gestor.Model.Domain.Generic;
+using Gestor.Model.Domain.Relatorios;
+using Gestor.Model.Domain.Relatorios.ClientesAtivosInativos;
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+
+namespace Gestor.Application.ViewModels
+{
+ internal class AnaliticoViewModel : BaseSegurosViewModel
+ {
+ private string _head;
+
+ public string Head
+ {
+ get
+ {
+ return this._head;
+ }
+ set
+ {
+ this._head = value;
+ base.OnPropertyChanged("Head");
+ }
+ }
+
+ public TipoTela Tela { get; set; } = 1;
+
+ public string Tipo
+ {
+ get;
+ set;
+ }
+
+ public AnaliticoViewModel(string tipo)
+ {
+ this.Tipo = tipo;
+ string str = this.Tipo;
+ if (str == "PARCELAS")
+ {
+ this.Tela = 5;
+ return;
+ }
+ if (str != "APOLICES")
+ {
+ this.Tela = 1;
+ return;
+ }
+ this.Tela = 2;
+ }
+
+ private async Task<string> GerarHtml(DataGrid grid)
+ {
+ PropertyInfo[] properties = typeof(Analitico).GetProperties();
+ List<string> list = (
+ from x in (IEnumerable<PropertyInfo>)properties
+ select x.Name).ToList<string>();
+ List<string> strs = new List<string>();
+ for (int i = 0; i < grid.Columns.Count; i++)
+ {
+ if (!(grid.Columns[i] is DataGridTemplateColumn))
+ {
+ Binding binding = (grid.Columns[i] as DataGridBoundColumn).Binding as Binding;
+ strs.Add(binding.Path.Path);
+ }
+ }
+ List<string> list1 = list.Except<string>(strs).ToList<string>();
+ IEnumerable<Analitico> analiticos = grid.Items.Cast<Analitico>();
+ string str = await Funcoes.GenerateTable<Analitico>((
+ from x in analiticos
+ where x.get_Selecionado()
+ select x).ToList<Analitico>(), list1, false, true, "", null);
+ string str1 = Funcoes.CreateCard("", str, false);
+ TipoRelatorio tipoRelatorio = new TipoRelatorio();
+ tipoRelatorio.set_Nome(string.Concat("ANALÍTICO - ", this.Head));
+ string str2 = str1;
+ if (str2 == null)
+ {
+ str2 = "";
+ }
+ string str3 = Funcoes.ExportarHtml(tipoRelatorio, str2, "60", "landscape", false, "");
+ return str3;
+ }
+
+ public async Task Print(DataGrid grid)
+ {
+ IEnumerable<Analitico> analiticos = grid.Items.Cast<Analitico>();
+ if (analiticos.Any<Analitico>((Analitico x) => x.get_Selecionado()))
+ {
+ string str = await this.GerarHtml(grid);
+ if (!string.IsNullOrEmpty(str))
+ {
+ string tempPath = Path.GetTempPath();
+ string str1 = 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(this.Head, ""), Funcoes.GetNetworkTime());
+ StreamWriter streamWriter = new StreamWriter(str1, true, Encoding.UTF8);
+ streamWriter.Write(str);
+ streamWriter.Close();
+ Process.Start(str1);
+ }
+ }
+ else
+ {
+ await base.ShowMessage("É NECESSÁRIO SELECIONAR AO MENOS UM DOCUMENTO", "OK", "", false);
+ }
+ }
+
+ public async Task<Trilha> Salvar(Trilha destino)
+ {
+ Trilha trilha;
+ List<Fase> fases = destino.get_Fases();
+ TarefaServico tarefaServico = new TarefaServico();
+ Trilha trilha1 = await tarefaServico.Salvar(destino);
+ if (tarefaServico.Sucesso)
+ {
+ fases.ForEach((Fase x) => x.set_Trilha(trilha1));
+ fases = await tarefaServico.Salvar(fases);
+ if (tarefaServico.Sucesso)
+ {
+ trilha1.set_Fases(fases);
+ trilha = trilha1;
+ }
+ else
+ {
+ trilha = null;
+ }
+ }
+ else
+ {
+ trilha = null;
+ }
+ fases = null;
+ tarefaServico = null;
+ return trilha;
+ }
+
+ public async Task Save(List<Tarefa> tarefas)
+ {
+ await (new TarefaServico()).Salvar(tarefas);
+ }
+
+ public async Task<List<Analitico>> Validar(List<Analitico> analitico, Trilha trilha)
+ {
+ List<long> list;
+ List<Analitico> analiticos;
+ TarefaServico tarefaServico = new TarefaServico();
+ string tipo = this.Tipo;
+ if (tipo == "CLIENTES")
+ {
+ List<Analitico> analiticos1 = analitico;
+ list = (
+ from x in analiticos1
+ select x.get_Cliente().get_Id()).ToList<long>();
+ }
+ else if (tipo == "PARCELAS" || tipo == "COMISSÃO")
+ {
+ List<Analitico> analiticos2 = analitico;
+ list = (
+ from x in analiticos2
+ select x.get_Parcela().get_Id()).ToList<long>();
+ }
+ else
+ {
+ List<Analitico> analiticos3 = analitico;
+ list = (
+ from x in analiticos3
+ select x.get_Documento().get_Id()).ToList<long>();
+ }
+ List<long> nums = await tarefaServico.Validar(list, trilha.get_Id());
+ List<long> nums1 = nums;
+ tipo = this.Head;
+ if (tipo == "CLIENTES")
+ {
+ analiticos = (
+ from x in analitico
+ where nums1.Contains(x.get_Cliente().get_Id())
+ select x).ToList<Analitico>();
+ }
+ else
+ {
+ analiticos = (tipo == "PARCELAS" || tipo == "COMISSÃO" ? (
+ from x in analitico
+ where nums1.Contains(x.get_Parcela().get_Id())
+ select x).ToList<Analitico>() : (
+ from x in analitico
+ where nums1.Contains(x.get_Documento().get_Id())
+ select x).ToList<Analitico>());
+ }
+ List<Analitico> list1 = analitico.Except<Analitico>(analiticos).ToList<Analitico>();
+ return list1;
+ }
+ }
+}
\ No newline at end of file |