using Gestor.Application.Helpers; using Gestor.Application.Servicos.Configuracoes; using Gestor.Application.ViewModels.Generic; using Gestor.Model.Common; using Gestor.Model.Domain.Relatorios; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Gestor.Application.ViewModels.Relatorios { public class DialogPrintViewModel : BaseViewModel { private bool _carregando; private ConfiguracaoImpressao _configuracoes; private List _tamanhos = new List() { "GRANDE", "MÉDIO", "PEQUENO" }; private bool _orientacaoImpressaoPortrait; private bool _orientacaoImpressaoLandscape; private string _tamanhoFonte = "PEQUENO"; private Relatorio _relatorio { get; set; } private Type _tipo { get; set; } public bool Carregando { get { return this._carregando; } set { this._carregando = value; base.OnPropertyChanged("Carregando"); } } public ConfiguracaoImpressao Configuracoes { get { return this._configuracoes; } set { this._configuracoes = value; base.OnPropertyChanged("Configuracoes"); } } public bool OrientacaoImpressao { get; set; } public bool OrientacaoImpressaoLandscape { get { return this._orientacaoImpressaoLandscape; } set { this._orientacaoImpressaoLandscape = value; base.OnPropertyChanged("OrientacaoImpressaoLandscape"); } } public bool OrientacaoImpressaoPortrait { get { return this._orientacaoImpressaoPortrait; } set { this._orientacaoImpressaoPortrait = value; base.OnPropertyChanged("OrientacaoImpressaoPortrait"); } } public string TamanhoFonte { get { return this._tamanhoFonte; } set { this._tamanhoFonte = value; if (value == "MÉDIO") { this.Configuracoes.set_TamanhoFonte(6); } else if (value == "GRANDE") { this.Configuracoes.set_TamanhoFonte(5); } else { this.Configuracoes.set_TamanhoFonte(7); } base.OnPropertyChanged("TamanhoFonte"); } } public List Tamanhos { get { return this._tamanhos; } set { this._tamanhos = value; base.OnPropertyChanged("Tamanhos"); } } public DialogPrintViewModel(Relatorio relatorio, Type tipo) { this._relatorio = relatorio; this._tipo = tipo; } public async Task Carregar() { List list = await (new ConfuguracoesServico()).BuscarParametros(this._relatorio); if (list == null || list.Count == 0) { list = this._tipo.GetProperties(BindingFlags.Instance | BindingFlags.Public).Select((PropertyInfo x) => { ParametrosRelatorio parametrosRelatorio = new ParametrosRelatorio(); parametrosRelatorio.set_Campo(x.Name); parametrosRelatorio.set_Header(x.GetDescriptionAttribute()); parametrosRelatorio.set_Tipo(x.GetTypeAttribute()); parametrosRelatorio.set_Relatorio(this._relatorio); parametrosRelatorio.set_Width(0); parametrosRelatorio.set_Ordem(0); return parametrosRelatorio; }).ToList(); } List parametrosRelatorios = list; parametrosRelatorios.ForEach((ParametrosRelatorio x) => x.set_Selecionado(true)); ConfiguracaoImpressao configuracaoImpressao = new ConfiguracaoImpressao(); configuracaoImpressao.set_TamanhoFonte(7); configuracaoImpressao.set_Campos(list); configuracaoImpressao.set_OrientacaoImpressao(new bool?(false)); this.Configuracoes = configuracaoImpressao; } public void Selecionar() { if (this.Carregando) { return; } ConfiguracaoImpressao configuracoes = this.Configuracoes; if (configuracoes == null) { return; } List campos = configuracoes.get_Campos(); if (campos == null) { return; } campos.ForEach((ParametrosRelatorio x) => x.set_Selecionado(!x.get_Selecionado())); } } }