diff options
Diffstat (limited to 'Decompiler/Gestor.Application.ViewModels.Generic/ItemViewModel.cs')
| -rw-r--r-- | Decompiler/Gestor.Application.ViewModels.Generic/ItemViewModel.cs | 682 |
1 files changed, 682 insertions, 0 deletions
diff --git a/Decompiler/Gestor.Application.ViewModels.Generic/ItemViewModel.cs b/Decompiler/Gestor.Application.ViewModels.Generic/ItemViewModel.cs new file mode 100644 index 0000000..22dba97 --- /dev/null +++ b/Decompiler/Gestor.Application.ViewModels.Generic/ItemViewModel.cs @@ -0,0 +1,682 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Data; +using System.Globalization; +using System.Linq; +using System.Runtime.InteropServices; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Forms; +using CsQuery.ExtensionMethods.Internal; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos.Seguros.Itens; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Seguros; +using Microsoft.Office.Interop.Excel; + +namespace Gestor.Application.ViewModels.Generic; + +public class ItemViewModel : BaseSegurosViewModel +{ + private bool _alterandoFiltros; + + public CoberturaViewModel CoberturaViewModel; + + public ItemServico _itemServico; + + private Visibility _alteracaoTitularesVisibility = (Visibility)2; + + private bool _enableAlterarExcluirTitulares; + + private List<TitularesVida> _excluirTlitulares = new List<TitularesVida>(); + + private TitularesVida _titularAlteracao = new TitularesVida(); + + private bool _codigo; + + private bool _inicio; + + private bool _fim; + + private bool _fatura; + + private bool _nome; + + private bool _observacao; + + private bool _nascimento; + + private bool _cpf; + + private bool _matricula; + + private bool _premio; + + private bool _capital; + + private bool _tipo; + + private ObservableCollection<TitularesVida> _titulares = new ObservableCollection<TitularesVida>(); + + private bool? _allSelected = false; + + private bool _allSelectedChanging; + + private List<TitularesVida> _oldTitulares = new List<TitularesVida>(); + + public Item ItemSubstituido { get; set; } + + public bool Mantido { get; set; } + + public Visibility AlteracaoTitularesVisibility + { + get + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + return _alteracaoTitularesVisibility; + } + set + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + _alteracaoTitularesVisibility = value; + OnPropertyChanged("AlteracaoTitularesVisibility"); + } + } + + public bool EnableAlterarExcluirTitulares + { + get + { + return _enableAlterarExcluirTitulares; + } + set + { + _enableAlterarExcluirTitulares = value; + OnPropertyChanged("EnableAlterarExcluirTitulares"); + } + } + + public List<TitularesVida> ExcluirTitulares + { + get + { + return _excluirTlitulares; + } + set + { + _excluirTlitulares = value; + OnPropertyChanged("ExcluirTitulares"); + } + } + + public TitularesVida TitularAlteracao + { + get + { + return _titularAlteracao; + } + set + { + _titularAlteracao = value; + OnPropertyChanged("TitularAlteracao"); + } + } + + public bool Codigo + { + get + { + return _codigo; + } + set + { + _codigo = value; + OnPropertyChanged("Codigo"); + } + } + + public bool Inicio + { + get + { + return _inicio; + } + set + { + _inicio = value; + OnPropertyChanged("Inicio"); + } + } + + public bool Fim + { + get + { + return _fim; + } + set + { + _fim = value; + OnPropertyChanged("Fim"); + } + } + + public bool Fatura + { + get + { + return _fatura; + } + set + { + _fatura = value; + OnPropertyChanged("Fatura"); + } + } + + public bool Nome + { + get + { + return _nome; + } + set + { + _nome = value; + OnPropertyChanged("Nome"); + } + } + + public bool Observacao + { + get + { + return _observacao; + } + set + { + _observacao = value; + OnPropertyChanged("Observacao"); + } + } + + public bool Nascimento + { + get + { + return _nascimento; + } + set + { + _nascimento = value; + OnPropertyChanged("Nascimento"); + } + } + + public bool Cpf + { + get + { + return _cpf; + } + set + { + _cpf = value; + OnPropertyChanged("Cpf"); + } + } + + public bool Matricula + { + get + { + return _matricula; + } + set + { + _matricula = value; + OnPropertyChanged("Matricula"); + } + } + + public bool Premio + { + get + { + return _premio; + } + set + { + _premio = value; + OnPropertyChanged("Premio"); + } + } + + public bool Capital + { + get + { + return _capital; + } + set + { + _capital = value; + OnPropertyChanged("Capital"); + } + } + + public bool Tipo + { + get + { + return _tipo; + } + set + { + _tipo = value; + OnPropertyChanged("Tipo"); + } + } + + public ObservableCollection<TitularesVida> Titulares + { + get + { + return _titulares; + } + set + { + _titulares = value; + foreach (TitularesVida titulare in Titulares) + { + titulare.PropertyChanged += TitularesOnPropertyChanged; + } + OnPropertyChanged("Titulares"); + } + } + + public bool? AllSelected + { + get + { + return _allSelected; + } + set + { + if (value != _allSelected) + { + EnableAlterarExcluirTitulares = value != false; + if (value == false) + { + AlteracaoTitularesVisibility = (Visibility)2; + } + _allSelected = value; + AllSelectedChanged(); + Titulares = new ObservableCollection<TitularesVida>(Titulares); + OnPropertyChanged("AllSelected"); + } + } + } + + public List<TitularesVida> OldTitulares + { + get + { + return _oldTitulares; + } + set + { + _oldTitulares = value; + OnPropertyChanged("OldTitulares"); + } + } + + public AutoCompleteFilterPredicate<object> DependenteItemFilter => (string searchText, object obj) => ((TitularesVida)obj).Nome.ToUpper().Contains(searchText.ToUpper()) && (int)((TitularesVida)obj).Tipo.GetValueOrDefault() != 2; + + public ItemViewModel() + { + //IL_0002: Unknown result type (might be due to invalid IL or missing references) + //IL_0013: Unknown result type (might be due to invalid IL or missing references) + //IL_001d: Expected O, but got Unknown + CoberturaViewModel = new CoberturaViewModel(); + _itemServico = new ItemServico(); + } + + public async Task<int> QuantidadeDeItens(long id) + { + return await new ItemServico().BuscarProximoItem(id); + } + + private void AllSelectedChanged() + { + if (_allSelectedChanging) + { + return; + } + try + { + _alterandoFiltros = true; + _allSelectedChanging = true; + if (!AllSelected.HasValue) + { + return; + } + foreach (TitularesVida titulare in Titulares) + { + titulare.Selecionado = AllSelected.Value; + } + _alterandoFiltros = false; + } + finally + { + _allSelectedChanging = false; + } + } + + private void TitularesOnPropertyChanged(object sender, PropertyChangedEventArgs args) + { + if (!_alterandoFiltros) + { + RecheckAllSelected(); + } + } + + public void RecheckAllSelected() + { + if (_allSelectedChanging) + { + return; + } + try + { + _allSelectedChanging = true; + if (Titulares.All((TitularesVida e) => e.Selecionado)) + { + AllSelected = true; + } + else if (Titulares.All((TitularesVida e) => !e.Selecionado)) + { + AllSelected = false; + } + else + { + AllSelected = null; + } + } + finally + { + _allSelectedChanging = false; + } + } + + public async Task ImportarTitulares() + { + OpenFileDialog val = new OpenFileDialog(); + string path; + try + { + ((FileDialog)val).Filter = "Excel|*.xls;*.xlsx"; + ((FileDialog)val).InitialDirectory = Environment.SpecialFolder.Desktop.ToString(); + if (1 != (int)((CommonDialog)val).ShowDialog()) + { + return; + } + path = ((FileDialog)val).FileName; + } + finally + { + ((IDisposable)val)?.Dispose(); + } + Loading(isLoading: true); + try + { + List<TitularesVida> list = await Task.Run(delegate + { + Microsoft.Office.Interop.Excel.Application application = (Microsoft.Office.Interop.Excel.Application)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("00024500-0000-0000-C000-000000000046"))); + Workbook workbook = application.Workbooks.Open(path, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); + List<string> list2 = new List<string> + { + "codigo", "inicio", "fim", "fatura", "nome", "nascimento", "cpf", "matricula", "premio", "capital", + "tipo", "observacao", "titulardependente" + }; + List<DataTable> list3 = new List<DataTable>(); + foreach (object worksheet in workbook.Worksheets) + { + DataTable dataTable = new DataTable(); + Microsoft.Office.Interop.Excel.Range usedRange = ((Worksheet)worksheet).UsedRange; + object[,] array = (dynamic)usedRange.Value2; + int num = 0; + if (array != null) + { + for (int i = 0; i <= usedRange.Columns.Count - 1; i++) + { + if (array[1, i + 1] == null || !list2.Contains(Funcoes.RemoverAcentos(array[1, i + 1].ToString().ToLower().Trim()))) + { + num--; + } + else + { + DataColumn column = new DataColumn + { + DataType = Type.GetType("System.String"), + ColumnName = Funcoes.RemoverAcentos(array[1, i + 1].ToString().ToLower().Trim()) + }; + dataTable.Columns.Add(column); + for (int j = 0; j <= usedRange.Rows.Count - 2; j++) + { + object obj2 = array[j + 2, i + 1]; + array[1, i + 1].ToString().ToLower(); + string value; + if (Funcoes.RemoverAcentos(array[1, i + 1].ToString().Trim().ToLower()) == "inicio" || Funcoes.RemoverAcentos(array[1, i + 1].ToString().Trim().ToLower()) == "fim" || Funcoes.RemoverAcentos(array[1, i + 1].ToString().Trim().ToLower()) == "nascimento") + { + DateTime result; + if (obj2 is double d) + { + result = DateTime.FromOADate(d); + value = result.ToShortDateString(); + } + else if (DateTime.TryParse((string)obj2, out result)) + { + result = DateTime.Parse((string)obj2); + value = result.ToShortDateString(); + } + else + { + value = ""; + } + } + else + { + value = ((obj2 is string text) ? Funcoes.RemoverAcentos(text).ToUpper().Trim() : ((obj2 is double num2) ? num2.ToString(CultureInfo.InvariantCulture) : ((!(obj2 is bool)) ? "" : (((bool)obj2) ? "1" : "0")))); + } + if (i + num == 0) + { + dataTable.Rows.Add(dataTable.NewRow()); + dataTable.Rows[j][i + num] = value; + } + else + { + dataTable.Rows[j][i + num] = value; + } + } + } + } + list3.Add(dataTable); + } + } + application.Quit(); + List<TitularesVida> list4 = new List<TitularesVida>(); + foreach (DataTable dt in list3) + { + list4.AddRange(((IEnumerable<DataRow>)(from x in dt.AsEnumerable() + where x.Field<object>("nome") != null && !string.IsNullOrEmpty(x.Field<object>("nome").ToString()) + select x).ToList()).Select((Func<DataRow, TitularesVida>)((DataRow x) => new TitularesVida + { + Codigo = ((!dt.Columns.Contains("codigo") || string.IsNullOrWhiteSpace(x.Field<object>("codigo").ToString())) ? null : x.Field<object>("codigo").ToString().ToUpper()), + Inicio = ((!dt.Columns.Contains("inicio") || string.IsNullOrWhiteSpace(x.Field<object>("inicio").ToString())) ? null : new DateTime?(DateTime.Parse(x.Field<object>("inicio").ToString()))), + Fim = ((!dt.Columns.Contains("fim") | string.IsNullOrWhiteSpace(x.Field<object>("fim").ToString())) ? null : new DateTime?(DateTime.Parse(x.Field<object>("fim").ToString()))), + Fatura = ((!dt.Columns.Contains("fatura") || string.IsNullOrWhiteSpace(x.Field<object>("fatura").ToString())) ? null : x.Field<object>("fatura").ToString().ToUpper()), + Nome = ((!dt.Columns.Contains("nome") || string.IsNullOrWhiteSpace(x.Field<object>("nome").ToString())) ? null : x.Field<object>("nome").ToString().ToUpper()), + Observacao = ((!dt.Columns.Contains("observacao") || string.IsNullOrWhiteSpace(x.Field<object>("observacao").ToString())) ? null : x.Field<object>("observacao").ToString().ToUpper()), + Nascimento = ((!dt.Columns.Contains("nascimento") || string.IsNullOrWhiteSpace(x.Field<object>("nascimento").ToString())) ? null : new DateTime?(DateTime.Parse(x.Field<object>("nascimento").ToString()))), + Cpf = ((!dt.Columns.Contains("cpf") || string.IsNullOrWhiteSpace(x.Field<object>("cpf").ToString())) ? null : x.Field<object>("cpf").ToString()), + Matricula = ((!dt.Columns.Contains("matricula") || string.IsNullOrWhiteSpace(x.Field<object>("matricula").ToString())) ? null : x.Field<object>("matricula").ToString().ToUpper()), + Premio = ((!dt.Columns.Contains("premio") || string.IsNullOrWhiteSpace(x.Field<object>("premio").ToString())) ? null : new decimal?(decimal.Parse(x.Field<object>("premio").ToString(), NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands, CultureInfo.InvariantCulture))), + Capital = ((!dt.Columns.Contains("capital") || string.IsNullOrWhiteSpace(x.Field<object>("capital").ToString())) ? null : new decimal?(decimal.Parse(x.Field<object>("capital").ToString(), NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands, CultureInfo.InvariantCulture))), + Tipo = ((!dt.Columns.Contains("tipo") || string.IsNullOrWhiteSpace(x.Field<object>("tipo").ToString())) ? null : ((x.Field<object>("tipo").ToString() == "SOCIO") ? new TipoTitular?((TipoTitular)0) : ((x.Field<object>("tipo").ToString() == "FUNCIONARIO") ? new TipoTitular?((TipoTitular)1) : null))) + })).ToList()); + } + return list4; + }); + Loading(isLoading: false); + if (list.Count == 0) + { + await ShowMessage("NENHUMA COLUNA FOI ENCONTRADA"); + } + else + { + ExtensionMethods.AddRange<TitularesVida>((ICollection<TitularesVida>)Titulares, (IEnumerable<TitularesVida>)list); + } + } + catch + { + Loading(isLoading: false); + await ShowMessage("FALHA AO IMPORTAR O EXCEL, VERIFIQUE SE O ARQUIVO POSSUI ALGUM ERRO."); + } + } + + public void AlterarTitular() + { + //IL_0001: Unknown result type (might be due to invalid IL or missing references) + //IL_0011: Unknown result type (might be due to invalid IL or missing references) + //IL_001b: Expected O, but got Unknown + if ((int)AlteracaoTitularesVisibility == 0) + { + AlteracaoTitularesVisibility = (Visibility)2; + return; + } + TitularAlteracao = new TitularesVida(); + Codigo = false; + Inicio = false; + Fim = false; + Fatura = false; + Nome = false; + Nascimento = false; + Cpf = false; + Matricula = false; + Premio = false; + Capital = false; + Tipo = false; + AlteracaoTitularesVisibility = (Visibility)0; + } + + public void AplicarTitular() + { + foreach (TitularesVida item in Titulares.Where((TitularesVida x) => x.Selecionado).ToList()) + { + if (Codigo) + { + item.Codigo = TitularAlteracao.Codigo; + } + if (Inicio) + { + item.Inicio = TitularAlteracao.Inicio; + } + if (Fim) + { + item.Fim = TitularAlteracao.Fim; + } + if (Fatura) + { + item.Fatura = TitularAlteracao.Fatura; + } + if (Nome) + { + item.Nome = TitularAlteracao.Nome; + } + if (Observacao) + { + item.Observacao = TitularAlteracao.Observacao; + } + if (Nascimento) + { + item.Nascimento = TitularAlteracao.Nascimento; + } + if (Cpf) + { + item.Cpf = TitularAlteracao.Cpf; + } + if (Matricula) + { + item.Matricula = TitularAlteracao.Matricula; + } + if (Premio) + { + item.Premio = TitularAlteracao.Premio; + } + if (Capital) + { + item.Capital = TitularAlteracao.Capital; + } + if (Tipo) + { + item.Tipo = TitularAlteracao.Tipo; + } + } + Titulares = new ObservableCollection<TitularesVida>(Titulares); + AlteracaoTitularesVisibility = (Visibility)2; + } + + internal async Task<List<TitularesVida>> BuscarTitulares(string value) + { + return await Task.Run(() => Titulares.Where((TitularesVida x) => (int)x.Tipo.GetValueOrDefault() != 2 && x.Nome != null && ValidationHelper.RemoveDiacritics(x.Nome.Trim()).ToUpper().Contains(value.ToUpper())).ToList()); + } + + public async Task CarregarTitulares(long id) + { + Titulares = new ObservableCollection<TitularesVida>(await _itemServico.BuscaTitularesVida(id)); + OldTitulares = ((IEnumerable<TitularesVida>)Titulares.ToList()).Select((Func<TitularesVida, TitularesVida>)((TitularesVida x) => new TitularesVida + { + Id = ((DomainBase)x).Id, + IdItem = x.IdItem, + Codigo = x.Codigo, + Inicio = x.Inicio, + Fim = x.Fim, + Fatura = x.Fatura, + Nome = x.Nome, + Observacao = x.Observacao, + Nascimento = x.Nascimento, + Cpf = x.Cpf, + Matricula = x.Matricula, + Premio = x.Premio, + Capital = x.Capital, + Tipo = x.Tipo, + Dependente = x.Dependente + })).ToList(); + } + + public void IncluirTitular() + { + //IL_0007: Unknown result type (might be due to invalid IL or missing references) + //IL_0011: Expected O, but got Unknown + Titulares.Insert(0, new TitularesVida()); + Titulares = new ObservableCollection<TitularesVida>(Titulares); + } + + public void ExcluirTitular() + { + List<TitularesVida> list = Titulares.Where((TitularesVida x) => x.Selecionado).ToList(); + ExcluirTitulares.AddRange(list.Where((TitularesVida x) => ((DomainBase)x).Id > 0)); + foreach (TitularesVida item in list) + { + Titulares.Remove(item); + } + AllSelected = false; + } +} |