From 1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 Mon Sep 17 00:00:00 2001 From: Lucas Faria Mendes Date: Mon, 30 Mar 2026 10:38:18 -0300 Subject: chore: location --- .../Views/Financeiro/FinanceiroView.cs | 1560 ++++++++++++++++++++ 1 file changed, 1560 insertions(+) create mode 100644 Codemerx/Gestor.Application/Views/Financeiro/FinanceiroView.cs (limited to 'Codemerx/Gestor.Application/Views/Financeiro/FinanceiroView.cs') diff --git a/Codemerx/Gestor.Application/Views/Financeiro/FinanceiroView.cs b/Codemerx/Gestor.Application/Views/Financeiro/FinanceiroView.cs new file mode 100644 index 0000000..431e1d1 --- /dev/null +++ b/Codemerx/Gestor.Application/Views/Financeiro/FinanceiroView.cs @@ -0,0 +1,1560 @@ +using Gestor.Application.Actions; +using Gestor.Application.Drawers; +using Gestor.Application.Helpers; +using Gestor.Application.Servicos; +using Gestor.Application.ViewModels.Financeiro; +using Gestor.Application.ViewModels.Generic; +using Gestor.Application.Views.Generic; +using Gestor.Common.Validation; +using Gestor.Model.Common; +using Gestor.Model.Domain.Financeiro; +using Gestor.Model.Domain.Generic; +using Gestor.Model.Domain.Relatorios; +using Gestor.Model.Domain.Seguros; +using MaterialDesignThemes.Wpf; +using System; +using System.CodeDom.Compiler; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Markup; +using Xceed.Wpf.AvalonDock.Controls; + +namespace Gestor.Application.Views.Financeiro +{ + public class FinanceiroView : BaseUserControl, IComponentConnector, IStyleConnector + { + private bool _selecionando; + + private List _sortDirections; + + private List _sortDescriptions; + + internal AutoCompleteBox AutoCompleteFornecedor; + + internal MenuItem MenuFiltros; + + internal Grid GridFiltros; + + internal DataGrid LancamentoGrid; + + internal AutoCompleteBox AutoCompleteFornecedorInclusao; + + private bool _contentLoaded; + + private string OriginalValue + { + get; + set; + } + + private TipoPagamento? tipoPagamento + { + get; + set; + } + + public FinanceiroViewModel ViewModel + { + get; + set; + } + + [DebuggerNonUserCode] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + internal Delegate _CreateDelegate(Type delegateType, string handler) + { + return Delegate.CreateDelegate(delegateType, this, handler); + } + + public FinanceiroView() + { + base.Tag = "CONSULTA DE FINANÇAS"; + this.ViewModel = new FinanceiroViewModel(); + base.DataContext = this.ViewModel; + this.InitializeComponent(); + Gestor.Application.Actions.Actions.SortLancamentos = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.SortLancamentos, new Action(this.SortLancamentos)); + Gestor.Application.Actions.Actions.SaveSortLancamentos = (Action)Delegate.Combine(Gestor.Application.Actions.Actions.SaveSortLancamentos, new Action(this.SaveSortLancamentos)); + } + + private async void AbrirLancamento(Lancamento lancamento) + { + if (this.ViewModel.SelectedLancamento == null) + { + await this.ViewModel.ShowMessage("SELECIONE UM LANCAMENTO ANTES DE PROSSEGUIR", "OK", "", false); + } + else if (lancamento.get_Id() <= (long)0 || lancamento.get_Controle().get_Plano() != null) + { + this.ViewModel.SelectedLancamento = lancamento; + this.ViewModel.VencimentoAlterado = false; + this.ViewModel.VencimentoAnt = this.ViewModel.SelectedLancamento.get_Vencimento(); + if (lancamento.get_Id() <= (long)0) + { + this.ViewModel.FiltrarLancamento(lancamento); + } + else + { + this.ViewModel.FiltrarLancamento(lancamento.get_Id()); + } + this.ViewModel.Alterando = System.Windows.Visibility.Visible; + this.ViewModel.BuscaHabilitada = false; + this.ValidarLancamento(); + } + } + + private void AbrirLog_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.AbrirLog(25, this.ViewModel.SelectedLancamento.get_Id()); + } + + private void AbrirLogEmail_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.AbrirLogEmail(25, this.ViewModel.SelectedLancamento.get_Id()); + } + + private async Task AbrirVinculo() + { + Lancamento lancamento; + if (this.ViewModel.LancamentosVinculo.Count != 0) + { + lancamento = await this.ViewModel.ShowVinculo(this.ViewModel); + if (lancamento != null) + { + if (!await this.ViewModel.ShowMessage(string.Format("DESEJA VINCULAR O LANÇAMENTO {0} A MOVIMENTAÇÃO SELECIONADA?", this.ViewModel.LancamentoVinculo.get_Id()), "SIM", "NÃO", false)) + { + await this.AbrirVinculo(); + } + this.ViewModel.FeedImportando(lancamento); + this.ViewModel.BindImportando(); + } + } + else + { + await this.ViewModel.ShowMessage("NÃO HÁ LANÇAMENTOS CRIADOS PARA O FORNECEDOR SELECIONADO.", "OK", "", false); + } + lancamento = null; + } + + private void AdicionarFiltro_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.AdcionarFiltroPersonalizado(); + } + + private void AdicionarFiltros_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.LimparFiltros(); + this.ViewModel.AdicionarFiltros(); + this.ViewModel.IsExpanded = !this.ViewModel.IsExpanded; + } + + private void Alterar_OnClick(object sender, RoutedEventArgs e) + { + Lancamento dataContext = (Lancamento)((Button)sender).DataContext; + this.ViewModel.VisibilityFornecedor = (this.ViewModel.Importando ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed); + this.ViewModel.BotaoSalvarVisibility = (this.ViewModel.Importando ? System.Windows.Visibility.Collapsed : System.Windows.Visibility.Visible); + this.AbrirLancamento(dataContext); + this.ViewModel.Loading(false); + } + + private async void ArquivoDigital_OnClick(object sender, RoutedEventArgs e) + { + if ((new PermissaoArquivoDigitalServico()).BuscarPermissao(Recursos.Usuario, 9).get_Consultar()) + { + FiltroArquivoDigital filtroArquivoDigital = new FiltroArquivoDigital(); + filtroArquivoDigital.set_Id(this.ViewModel.SelectedLancamento.get_Id()); + filtroArquivoDigital.set_Tipo(9); + filtroArquivoDigital.set_Parente(this.ViewModel.SelectedLancamento); + this.ViewModel.ShowDrawer(new ArquivoDigitalDrawer(filtroArquivoDigital), 0, false); + } + else + { + await this.ViewModel.ShowMessage(string.Concat("VOCÊ NÃO POSSUI PERMISSÃO PARA ACESSAR\nARQUIVO DIGITAL DE ", ValidationHelper.GetDescription((TipoArquivoDigital)9), "."), "OK", "", false); + } + } + + private void AutoCompleteBoxDetalhe_Populating(object sender, PopulatingEventArgs e) + { + if (e.get_Parameter().Length < 3) + { + return; + } + e.set_Cancel(true); + this.ViewModel.FiltroPersonalizadoTask(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task> searchResult) => { + if (searchResult.Result == null) + { + return; + } + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + autoCompleteBox.set_ItemsSource(searchResult.Result); + autoCompleteBox.PopulateComplete(); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + + private void AutoCompleteFornecedor_OnPopulating(object sender, PopulatingEventArgs e) + { + if (e.get_Parameter().Length < 3) + { + return; + } + e.set_Cancel(true); + this.ViewModel.BuscarFornecedor(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task> searchResult) => { + if (searchResult.Result == null) + { + return; + } + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + autoCompleteBox.set_ItemsSource(searchResult.Result); + autoCompleteBox.PopulateComplete(); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + + private void AutoCompleteFornecedorAtivo_OnPopulating(object sender, PopulatingEventArgs e) + { + if (e.get_Parameter().Length < 3) + { + return; + } + e.set_Cancel(true); + this.ViewModel.BuscarFornecedorAtivo(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task> searchResult) => { + if (searchResult.Result == null) + { + return; + } + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + autoCompleteBox.set_ItemsSource(searchResult.Result); + autoCompleteBox.PopulateComplete(); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + + private void AutoCompleteLancamento_OnPopulating(object sender, PopulatingEventArgs e) + { + if (e.get_Parameter().Length < 3) + { + return; + } + e.set_Cancel(true); + this.ViewModel.FiltrarLancamento(ValidationHelper.RemoveDiacritics(e.get_Parameter().Trim())).ContinueWith((Task> searchResult) => { + if (searchResult.Result == null) + { + return; + } + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + autoCompleteBox.set_ItemsSource(searchResult.Result); + autoCompleteBox.PopulateComplete(); + }, TaskScheduler.FromCurrentSynchronizationContext()); + } + + private void AutoCompleteLancamento_OnTextChanged(object sender, RoutedEventArgs e) + { + if (!string.IsNullOrWhiteSpace(((AutoCompleteBox)sender).get_Text())) + { + return; + } + this.ViewModel.Filtrar(""); + } + + private void Baixados_Click(object sender, RoutedEventArgs e) + { + this.ViewModel.SelectedStatusImportacao = 1; + this.ViewModel.FiltroImportacao(); + } + + private async void Buscar_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.Loading(true); + await this.ViewModel.Buscar(); + this.ViewModel.Loading(false); + } + + private async void BuscarLancamentos_Click(object sender, RoutedEventArgs e) + { + if (this.ViewModel.FornecedorInclusao == null || this.ViewModel.FornecedorInclusao.get_Id() == 0) + { + await this.ViewModel.ShowMessage("É NECESSÁRIO PESQUISAR O FORNECEDOR AO LADO PARA VINCULAR UM LANÇAMENTO A ESSA MOVIMENTAÇÃO.", "OK", "", false); + } + else + { + this.ViewModel.Loading(true); + await this.ViewModel.BuscarLancamentosVinculo(); + this.ViewModel.Loading(false); + await this.AbrirVinculo(); + } + } + + private void CancelarAlteracao_OnClick(object sender, RoutedEventArgs e) + { + this.AutoCompleteFornecedorInclusao.set_Text(string.Empty); + this.ViewModel.Alterando = System.Windows.Visibility.Collapsed; + this.ViewModel.BuscaHabilitada = true; + this.ViewModel.CancelarAlteracao(); + this.ViewModel.EnableIncluirNovo = false; + } + + private async void CancelarImportacao_Click(object sender, RoutedEventArgs e) + { + this.ViewModel.Loading(true); + this.ViewModel.Importando = false; + await this.ViewModel.Buscar(); + this.ViewModel.Loading(false); + } + + private void CheckBox_Checked(object sender, RoutedEventArgs e) + { + if (this._selecionando) + { + return; + } + this._selecionando = true; + ((CheckBox)sender).IsChecked = new bool?(false); + this.ViewModel.SelecionarTodos(); + this._selecionando = false; + } + + private void CheckBoxFiltros_Checked(object sender, RoutedEventArgs e) + { + string name = ((CheckBox)sender).Name; + if (name == "GridPlanos") + { + this.ViewModel.PlanosFiltro.ForEach((Planos x) => x.set_Selecionado(!x.get_Selecionado())); + this.ViewModel.PlanosFiltro = new List(this.ViewModel.PlanosFiltro); + return; + } + if (name == "GridCentro") + { + this.ViewModel.CentroFiltro.ForEach((Centro x) => x.set_Selecionado(!x.get_Selecionado())); + this.ViewModel.CentroFiltro = new List(this.ViewModel.CentroFiltro); + return; + } + if (name != "GridConta") + { + return; + } + this.ViewModel.ContaFiltro.ForEach((BancosContas x) => x.set_Selecionado(!x.get_Selecionado())); + this.ViewModel.ContaFiltro = new List(this.ViewModel.ContaFiltro); + } + + private async void DataGrid_OnCellEditEnding(object sender, DataGridCellEditEndingEventArgs e) + { + string sortMemberPath; + DateTime vencimento; + DateTime? nullable; + string str; + DateTime? nullable1; + DateTime? nullable2; + string shortDateString; + string text; + TextBox editingElement; + if (e.EditingElement is TextBox) + { + editingElement = e.EditingElement as TextBox; + bool flag = true; + string stringFormat = e.Column.ClipboardContentBinding.StringFormat; + if (stringFormat == "d") + { + if (editingElement != null) + { + TextBox textBox = editingElement; + if (string.IsNullOrEmpty(editingElement.Text)) + { + str = null; + } + else + { + str = ValidationHelper.FormatDate(editingElement.Text); + } + textBox.Text = str; + if (e.Column.SortMemberPath == "Vencimento" && string.IsNullOrWhiteSpace(editingElement.Text)) + { + TextBox shortDateString1 = editingElement; + vencimento = this.ViewModel.SelectedLancamento.get_Vencimento(); + shortDateString1.Text = vencimento.ToShortDateString(); + await this.ViewModel.ShowMessage("VENCIMENTO NÃO PODE SER EM BRANCO", "OK", "", false); + editingElement = null; + return; + } + else if (string.IsNullOrWhiteSpace(editingElement.Text) || ValidationHelper.ValidateDate(editingElement.Text)) + { + sortMemberPath = e.Column.SortMemberPath; + if (sortMemberPath != "Baixa") + { + if (sortMemberPath == "Pagamento") + { + if (this.OriginalValue != editingElement.Text) + { + if (!await this.ViewModel.ShowMessage("DESEJA REPLICAR PARA OS DEMAIS LANÇAMENTOS FILTRADOS?", "SIM", "NÃO", false)) + { + flag = false; + } + foreach (Lancamento lancamento in this.LancamentoGrid.Items.Cast()) + { + if (!(lancamento.get_Id() == ((Lancamento)this.LancamentoGrid.SelectedItem).get_Id() | flag)) + { + continue; + } + Lancamento lancamento1 = lancamento; + if (string.IsNullOrEmpty(editingElement.Text)) + { + nullable = null; + nullable2 = nullable; + } + else + { + nullable2 = new DateTime?(DateTime.Parse(editingElement.Text)); + } + lancamento1.set_Pagamento(nullable2); + } + this.LancamentoGrid.Items.Refresh(); + } + else + { + editingElement = null; + return; + } + } + } + else if (this.OriginalValue != editingElement.Text) + { + if (!await this.ViewModel.ShowMessage("DESEJA REPLICAR PARA OS DEMAIS LANÇAMENTOS FILTRADOS?", "SIM", "NÃO", false)) + { + flag = false; + } + foreach (Lancamento lancamento2 in this.LancamentoGrid.Items.Cast()) + { + if (!(lancamento2.get_Id() == ((Lancamento)this.LancamentoGrid.SelectedItem).get_Id() | flag)) + { + continue; + } + Lancamento lancamento3 = lancamento2; + if (string.IsNullOrEmpty(editingElement.Text)) + { + nullable = null; + nullable1 = nullable; + } + else + { + nullable1 = new DateTime?(DateTime.Parse(editingElement.Text)); + } + lancamento3.set_Baixa(nullable1); + } + this.LancamentoGrid.Items.Refresh(); + } + else + { + editingElement = null; + return; + } + } + else + { + TextBox textBox1 = editingElement; + if (e.Column.SortMemberPath == "Vencimento") + { + vencimento = this.ViewModel.SelectedLancamento.get_Vencimento(); + shortDateString = vencimento.ToShortDateString(); + } + else + { + shortDateString = null; + } + textBox1.Text = shortDateString; + await this.ViewModel.ShowMessage("DATA INVÁLIDA", "OK", "", false); + editingElement = null; + return; + } + } + else + { + editingElement = null; + return; + } + } + else if (stringFormat != "c") + { + TextBox textBox2 = editingElement; + if (textBox2 != null) + { + text = textBox2.Text; + } + else + { + text = null; + } + if (!string.IsNullOrEmpty(text)) + { + sortMemberPath = e.Column.SortMemberPath; + if (sortMemberPath != "Documento") + { + if (sortMemberPath != "Competencia") + { + if (sortMemberPath == "Complemento") + { + if (editingElement.Text.Length > 15) + { + editingElement.Text = ""; + await this.ViewModel.ShowMessage("LIMITE DE CARACTERES: 15", "OK", "", false); + } + else + { + editingElement = null; + return; + } + } + } + else if (editingElement.Text.Length > 7) + { + editingElement.Text = ""; + await this.ViewModel.ShowMessage("LIMITE DE CARACTERES: 7", "OK", "", false); + } + else + { + editingElement.Text = ValidationHelper.FormatCompetencia(editingElement.Text); + editingElement = null; + return; + } + } + else if (editingElement.Text.Length > 50) + { + editingElement.Text = string.Empty; + await this.ViewModel.ShowMessage("LIMITE DE CARACTERES: 50", "OK", "", false); + } + else if (this.OriginalValue != editingElement.Text) + { + if (!await this.ViewModel.ShowMessage("DESEJA REPLICAR PARA OS DEMAIS LANÇAMENTOS FILTRADOS?", "SIM", "NÃO", false)) + { + flag = false; + } + foreach (Lancamento lancamento4 in this.LancamentoGrid.Items.Cast()) + { + if (!(lancamento4.get_Id() == ((Lancamento)this.LancamentoGrid.SelectedItem).get_Id() | flag)) + { + continue; + } + lancamento4.set_Documento(editingElement.Text); + } + this.LancamentoGrid.Items.Refresh(); + editingElement = null; + return; + } + else + { + editingElement = null; + return; + } + } + } + else if (editingElement != null) + { + editingElement.Text = ValidationHelper.FormatCurrency(editingElement.Text); + } + } + editingElement = null; + } + + public new void DatePicker_OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) + { + DatePicker datePicker = (DatePicker)sender; + datePicker.Text = ValidationHelper.FormatDate(datePicker.Text); + } + + private new void DatePicker_PreviewKeyDown(object sender, KeyEventArgs e) + { + if (e.Key != Key.Return) + { + return; + } + DatePicker str = (DatePicker)sender; + DateTime date = Funcoes.GetNetworkTime().Date; + str.Text = date.ToString("dd/MM/yyyy"); + } + + private void EsconderFiltros_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.VisibleFiltros = System.Windows.Visibility.Collapsed; + this.ViewModel.VisibleOlho = System.Windows.Visibility.Visible; + } + + private async void Excluir_OnClick(object sender, RoutedEventArgs e) + { + await this.ViewModel.Excluir(); + this.ViewModel.Alterando = System.Windows.Visibility.Collapsed; + this.ViewModel.BuscaHabilitada = true; + this.ViewModel.CancelarAlteracao(); + } + + private async void ExcluirBaixa_OnClick(object sender, RoutedEventArgs e) + { + await this.ViewModel.ExcluirBaixa(); + } + + private async void ExcluirBaixaRange_OnClick(object sender, RoutedEventArgs e) + { + await this.ViewModel.ExcluirBaixaRange(); + } + + private void ExcluirFiltro_OnClick(object sender, RoutedEventArgs e) + { + Chip chip = sender as Chip; + if (chip == null) + { + return; + } + ListBox listBox = Extentions.FindVisualAncestor(chip); + Gestor.Model.Domain.Relatorios.FiltroPersonalizado item = (Gestor.Model.Domain.Relatorios.FiltroPersonalizado)listBox.Items[listBox.Items.IndexOf(chip.DataContext)]; + if (item == null) + { + return; + } + this.ViewModel.PersonalizadoSelecionado.Remove(item); + this.ViewModel.PesquisaPersonalizada(); + } + + private void ExcluirFiltro_onDeleteClick(object sender, RoutedEventArgs e) + { + Chip chip = sender as Chip; + if (chip == null) + { + return; + } + ListBox listBox = Extentions.FindVisualAncestor(chip); + Gestor.Model.Domain.Financeiro.FiltroPersonalizado item = (Gestor.Model.Domain.Financeiro.FiltroPersonalizado)listBox.Items[listBox.Items.IndexOf(chip.DataContext)]; + if (item == null) + { + return; + } + this.ViewModel.ExcluirFiltro(item); + } + + private async void ExcluirRange_OnClick(object sender, RoutedEventArgs e) + { + await this.ViewModel.ExcluirRange(); + } + + private async void ExportarExcel_OnClick(object sender, RoutedEventArgs e) + { + List list = this.LancamentoGrid.Items.Cast().ToList(); + await this.ViewModel.GerarExcel(list); + } + + private void ExtratoConta_OnClick(object sender, RoutedEventArgs e) + { + Button button = (Button)sender; + if (button == null || button.DataContext == null) + { + return; + } + (new ExtratoWindow(((Saldo)button.DataContext).get_Conta().get_Id())).Show(); + } + + private void Fechar_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.IsExpanded = !this.ViewModel.IsExpanded; + } + + private void Filtrar_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.IsExpanded = !this.ViewModel.IsExpanded; + } + + private void FiltroDetalhes_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + AutoCompleteBox autoCompleteBox = (AutoCompleteBox)sender; + if (autoCompleteBox == null || autoCompleteBox.get_SelectedItem() == null) + { + return; + } + if (!autoCompleteBox.get_IsDropDownOpen()) + { + return; + } + this.ViewModel.AdicionarFiltro((Gestor.Model.Domain.Financeiro.FiltroPersonalizado)autoCompleteBox.get_SelectedItem()); + autoCompleteBox.set_Text(string.Empty); + } + + private async Task ImportarOfx() + { + BancosContas bancosConta; + if (this.ViewModel.ContasFiltradas == null || this.ViewModel.ContasFiltradas.Count == 0) + { + await this.ViewModel.ShowMessage("NÃO HÁ CONTAS CADASTRADAS PARA REALIZAR A IMPORTAÇÃO.", "OK", "", false); + } + else + { + if (this.ViewModel.ContasFiltradas.Count <= 1) + { + bancosConta = this.ViewModel.ContasFiltradas.First(); + } + else + { + bancosConta = await this.ViewModel.ShowContas(this.ViewModel.ContasFiltradas.ToList()); + } + BancosContas bancosConta1 = bancosConta; + if (bancosConta1 != null) + { + this.ViewModel.Loading(true); + await this.ViewModel.ParseOfx(bancosConta1); + this.ViewModel.Loading(false); + } + } + } + + private async void ImportarOfx_Click(object sender, RoutedEventArgs e) + { + await this.ImportarOfx(); + } + + private async void Imprimir_OnClick(object sender, RoutedEventArgs e) + { + List list = this.LancamentoGrid.Items.Cast().ToList(); + if (await this.ViewModel.ShowMessage("DESEJA CONTINUAR COM A IMPRESSÃO?", "SIM", "NÃO", false)) + { + bool flag = await this.ViewModel.ShowMessage("EM QUAL POSIÇÂO DESEJA IMPRIMIR?", "PAISAGEM (horizontal)", "RETRATO (vertical)", false); + await this.ViewModel.Print(list, flag); + } + list = null; + } + + private void Incluir_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.IncluirLancamento(); + this.ViewModel.IdLancamento = (long)0; + this.ValidarLancamento(); + } + + private void IncluirParcela_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.IncluirParcela(); + this.ValidarLancamento(); + } + + [DebuggerNonUserCode] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + public void InitializeComponent() + { + if (this._contentLoaded) + { + return; + } + this._contentLoaded = true; + System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/views/financeiro/financeiroview.xaml", UriKind.Relative)); + } + + private void LancamentoGrid_OnPreparingCellForEdit(object sender, DataGridPreparingCellForEditEventArgs e) + { + if (e.Column.GetType().Name != "DataGridTextColumn") + { + this.LancamentoGrid.CancelEdit(); + this.LancamentoGrid.CancelEdit(); + } + TextBox editingElement = e.EditingElement as TextBox; + if (editingElement != null) + { + this.OriginalValue = editingElement.Text; + } + } + + private void LimparFiltros_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.LimparFiltros(); + this.ViewModel.FiltrarPersonalizado(); + } + + private void MostrarFiltros_Click(object sender, RoutedEventArgs e) + { + MenuItem menuItem = (MenuItem)sender; + this.GridFiltros.Visibility = (this.GridFiltros.Visibility == System.Windows.Visibility.Collapsed ? System.Windows.Visibility.Visible : System.Windows.Visibility.Collapsed); + menuItem.Header = (this.GridFiltros.Visibility == System.Windows.Visibility.Collapsed ? "MOSTRAR FILTROS" : "ESCONDER FILTROS"); + } + + private void MostrarFiltros_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.VisibleFiltros = System.Windows.Visibility.Visible; + this.ViewModel.VisibleOlho = System.Windows.Visibility.Collapsed; + } + + private void OnChecked_OnHandler(object sender, RoutedEventArgs e) + { + DataGridCell dataGridCell = (DataGridCell)sender; + if (this.LancamentoGrid.SelectedItem == null) + { + return; + } + Lancamento dataContext = dataGridCell.DataContext as Lancamento; + if (dataContext != null) + { + if (dataContext.get_Selecionado()) + { + return; + } + this.ViewModel.SelecionarLancamento(dataContext); + this.LancamentoGrid.CommitEdit(); + this.LancamentoGrid.CommitEdit(); + CollectionViewSource.GetDefaultView(this.LancamentoGrid.ItemsSource).Refresh(); + } + } + + private void Pendentes_Click(object sender, RoutedEventArgs e) + { + this.ViewModel.SelectedStatusImportacao = 0; + this.ViewModel.FiltroImportacao(); + } + + private void Saldos_OnMouseDoubleClick(object sender, MouseButtonEventArgs e) + { + if (this.ViewModel.SelectedSaldo == null) + { + return; + } + string str = string.Concat("INFORMAÇÕES DO EXTRATO - ", this.ViewModel.SelectedSaldo.get_Conta().get_Descricao()); + Window window = Funcoes.IsHosterOpen(str); + if (window == null) + { + (new HosterWindow(new InfoExtratoView(this.ViewModel.SelectedSaldo, false), str, new double?((double)800), new double?((double)450), true)).Show(); + return; + } + window.WindowState = (window.WindowState == WindowState.Minimized ? WindowState.Maximized : window.WindowState); + window.Activate(); + } + + private async Task Salvar(bool fechar) + { + bool flag; + bool flag1; + DatePickerTextBox focusedElement = Keyboard.FocusedElement as DatePickerTextBox; + if (focusedElement != null) + { + ((DatePicker)focusedElement.TemplatedParent).SelectedDate = new DateTime?(ValidationHelper.ToDateTime(ValidationHelper.FormatDate(focusedElement.Text))); + DateTime? selectedDate = ((DatePicker)focusedElement.TemplatedParent).SelectedDate; + if (selectedDate.ToString() == "01/01/0001 00:00:00") + { + selectedDate = null; + ((DatePicker)focusedElement.TemplatedParent).SelectedDate = selectedDate; + } + } + flag = (!this.ViewModel.Importando ? false : this.ViewModel.Parcelas > 1); + bool flag2 = flag; + if (flag2) + { + flag2 = !await this.ViewModel.ShowMessage(string.Format("SERÁ CRIADO COM {0} PARCELAS, INICIADO POR ESSE LANÇAMENTO, DESEJA PROSSEGUIR?", this.ViewModel.Parcelas), "SIM", "NÃO", false); + } + if (!flag2) + { + this.ViewModel.Loading(true); + if (!this.ViewModel.Importando) + { + this.ViewModel.Bind(); + List> keyValuePairs = await this.ViewModel.Salvar(); + flag1 = (keyValuePairs == null ? true : keyValuePairs.Count == 0); + this.ViewModel.Loading(false); + if (!flag1) + { + await this.ViewModel.ShowMessage(keyValuePairs, this.ViewModel.ErroCamposInvalidos, "OK", ""); + } + else if (!fechar) + { + Fornecedor fornecedorInclusao = this.ViewModel.FornecedorInclusao; + string historico = this.ViewModel.Historico; + string documento = this.ViewModel.Documento; + string competencia = this.ViewModel.Competencia; + string complemento = this.ViewModel.Complemento; + Planos plano = this.ViewModel.Plano; + Centro centro = this.ViewModel.Centro; + BancosContas conta = this.ViewModel.Conta; + Sinal sinal = this.ViewModel.Sinal; + int parcelas = this.ViewModel.Parcelas; + int parcela = this.ViewModel.Parcela; + DateTime vencimento = this.ViewModel.Vencimento; + decimal valor = this.ViewModel.Valor; + DateTime? baixa = this.ViewModel.Baixa; + decimal? valorPago = this.ViewModel.ValorPago; + DateTime? pagamento = this.ViewModel.Pagamento; + TipoPagamento tipoPagamento = this.ViewModel.TipoPagamento; + string observacao = this.ViewModel.Observacao; + this.ViewModel.FornecedorInclusao = fornecedorInclusao; + this.ViewModel.Historico = historico; + this.ViewModel.Documento = documento; + this.ViewModel.Competencia = competencia; + this.ViewModel.Complemento = complemento; + this.ViewModel.Plano = plano; + this.ViewModel.Centro = centro; + this.ViewModel.Conta = conta; + this.ViewModel.Sinal = sinal; + this.ViewModel.Parcelas = parcelas; + this.ViewModel.Parcela = parcela; + this.ViewModel.Vencimento = vencimento; + this.ViewModel.Valor = valor; + this.ViewModel.Baixa = baixa; + this.ViewModel.ValorPago = valorPago; + this.ViewModel.Pagamento = pagamento; + this.ViewModel.TipoPagamento = tipoPagamento; + this.ViewModel.Observacao = observacao; + this.ViewModel.EnableIncluirNovo = true; + } + else + { + this.AutoCompleteFornecedorInclusao.set_Text(string.Empty); + this.ViewModel.Alterando = System.Windows.Visibility.Collapsed; + this.ViewModel.BuscaHabilitada = true; + await this.ViewModel.Buscar(); + } + } + else + { + this.ViewModel.BindImportando(); + List> keyValuePairs1 = this.ViewModel.SelectedLancamento.Validate(); + if (keyValuePairs1 == null) + { + keyValuePairs1 = new List>(); + } + List> keyValuePairs2 = keyValuePairs1; + if (keyValuePairs2.Count <= 0) + { + this.ViewModel.LancamentosFiltrados = this.ViewModel.Lancamentos; + this.AutoCompleteFornecedorInclusao.set_Text(string.Empty); + this.ViewModel.Alterando = System.Windows.Visibility.Collapsed; + this.ViewModel.BuscaHabilitada = true; + this.ViewModel.Loading(false); + } + else + { + this.ViewModel.Loading(false); + await this.ViewModel.ShowMessage(keyValuePairs2, this.ViewModel.ErroCamposInvalidos, "OK", ""); + } + } + } + } + + private async void SalvarImportacao_Click(object sender, RoutedEventArgs e) + { + if (await this.ViewModel.ShowMessage(string.Concat("DESEJA PROSSEGUIR COM A IMPORTAÇÃO?", Environment.NewLine, Environment.NewLine, "SOMENTE OS LANÇAMENTOS VÁLIDOS SERÃO ALTERADOS OU INCLUÍDOS"), "SIM", "NÃO", false)) + { + this.ViewModel.Loading(true); + ObservableCollection lancamentos = this.ViewModel.Lancamentos; + List list = ( + from x in lancamentos + where x.Validate().Count == 0 + select x).ToList(); + if (await this.ViewModel.SalvarImportacao(list)) + { + this.ViewModel.Importando = false; + } + this.ViewModel.Loading(false); + } + } + + private async void SalvarInclusao_Click(object sender, RoutedEventArgs e) + { + await this.Salvar(false); + } + + private async void SalvarLancamento_OnClick(object sender, RoutedEventArgs e) + { + await this.Salvar(true); + } + + private async void SalvarRange_OnClick(object sender, RoutedEventArgs e) + { + await this.ViewModel.Atualizar(this.LancamentoGrid.Items.Cast().ToList()); + this.LancamentoGrid.CommitEdit(); + this.LancamentoGrid.CommitEdit(); + CollectionViewSource.GetDefaultView(this.LancamentoGrid.ItemsSource).Refresh(); + } + + public void SaveSortLancamentos() + { + this._sortDirections = new List(); + this._sortDescriptions = new List(); + foreach (DataGridColumn column in this.LancamentoGrid.Columns) + { + this._sortDirections.Add(column.SortDirection); + } + foreach (SortDescription sortDescription in this.LancamentoGrid.Items.SortDescriptions) + { + this._sortDescriptions.Add(sortDescription); + } + } + + private void Sintetizar_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.Sintetizar(); + } + + public void SortLancamentos() + { + if (this._sortDirections == null || this._sortDirections.Count != this.LancamentoGrid.Columns.Count) + { + return; + } + foreach (DataGridColumn column in this.LancamentoGrid.Columns) + { + column.SortDirection = this._sortDirections[this.LancamentoGrid.Columns.IndexOf(column)]; + } + this.LancamentoGrid.Items.SortDescriptions.Clear(); + foreach (SortDescription _sortDescription in this._sortDescriptions) + { + this.LancamentoGrid.Items.SortDescriptions.Add(_sortDescription); + } + } + + [DebuggerNonUserCode] + [EditorBrowsable(EditorBrowsableState.Never)] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target) + { + switch (connectionId) + { + case 1: + { + ((ComboBox)target).SelectionChanged += new SelectionChangedEventHandler(this.TipoFiltrosBox_OnSelectionChanged); + return; + } + case 2: + { + ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); + ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); + ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); + return; + } + case 3: + { + ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); + ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); + ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); + return; + } + case 4: + { + this.AutoCompleteFornecedor = (AutoCompleteBox)target; + this.AutoCompleteFornecedor.add_Populating(new PopulatingEventHandler(this, FinanceiroView.AutoCompleteFornecedor_OnPopulating)); + return; + } + case 5: + { + ((AutoCompleteBox)target).add_Populating(new PopulatingEventHandler(this, FinanceiroView.AutoCompleteBoxDetalhe_Populating)); + ((AutoCompleteBox)target).add_SelectionChanged(new SelectionChangedEventHandler(this.FiltroDetalhes_OnSelectionChanged)); + return; + } + case 6: + { + ((Button)target).Click += new RoutedEventHandler(this.MostrarFiltros_OnClick); + return; + } + case 7: + { + this.MenuFiltros = (MenuItem)target; + this.MenuFiltros.Click += new RoutedEventHandler(this.MostrarFiltros_Click); + return; + } + case 8: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Pendentes_Click); + return; + } + case 9: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Baixados_Click); + return; + } + case 10: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Todos_Click); + return; + } + case 11: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.SalvarImportacao_Click); + return; + } + case 12: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.CancelarImportacao_Click); + return; + } + case 13: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Buscar_OnClick); + return; + } + case 14: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Imprimir_OnClick); + return; + } + case 15: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.ExportarExcel_OnClick); + return; + } + case 16: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Sintetizar_OnClick); + return; + } + case 17: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.TrocarFornecedor_OnClick); + return; + } + case 18: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.SalvarRange_OnClick); + return; + } + case 19: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Incluir_OnClick); + return; + } + case 20: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.IncluirParcela_OnClick); + return; + } + case 21: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.ExcluirBaixaRange_OnClick); + return; + } + case 22: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.ExcluirRange_OnClick); + return; + } + case 23: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Transferir_OnClick); + return; + } + case 24: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLog_OnClick); + return; + } + case 25: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.AbrirLogEmail_OnClick); + return; + } + case 26: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.ImportarOfx_Click); + return; + } + case 27: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Filtrar_OnClick); + return; + } + case 28: + { + this.GridFiltros = (Grid)target; + return; + } + case 29: + { + ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); + ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); + ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); + return; + } + case 30: + { + ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); + ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); + ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); + return; + } + case 31: + { + ((Button)target).Click += new RoutedEventHandler(this.AdicionarFiltro_OnClick); + return; + } + case 32: + case 33: + case 37: + case 38: + case 39: + case 40: + case 41: + case 44: + case 45: + case 46: + case 60: + { + this._contentLoaded = true; + return; + } + case 34: + { + ((Button)target).Click += new RoutedEventHandler(this.LimparFiltros_OnClick); + return; + } + case 35: + { + ((Button)target).Click += new RoutedEventHandler(this.EsconderFiltros_OnClick); + return; + } + case 36: + { + this.LancamentoGrid = (DataGrid)target; + this.LancamentoGrid.CellEditEnding += new EventHandler(this.DataGrid_OnCellEditEnding); + this.LancamentoGrid.PreparingCellForEdit += new EventHandler(this.LancamentoGrid_OnPreparingCellForEdit); + return; + } + case 42: + { + ((Button)target).Click += new RoutedEventHandler(this.AdicionarFiltros_OnClick); + return; + } + case 43: + { + ((Button)target).Click += new RoutedEventHandler(this.Fechar_OnClick); + return; + } + case 47: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Incluir_OnClick); + return; + } + case 48: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.SalvarInclusao_Click); + return; + } + case 49: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.SalvarLancamento_OnClick); + return; + } + case 50: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.CancelarAlteracao_OnClick); + return; + } + case 51: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.ExcluirBaixa_OnClick); + return; + } + case 52: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.Excluir_OnClick); + return; + } + case 53: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.ArquivoDigital_OnClick); + return; + } + case 54: + { + this.AutoCompleteFornecedorInclusao = (AutoCompleteBox)target; + this.AutoCompleteFornecedorInclusao.add_Populating(new PopulatingEventHandler(this, FinanceiroView.AutoCompleteFornecedorAtivo_OnPopulating)); + return; + } + case 55: + { + ((MenuItem)target).Click += new RoutedEventHandler(this.BuscarLancamentos_Click); + return; + } + case 56: + { + ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); + ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); + ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); + return; + } + case 57: + { + ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); + ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); + ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); + return; + } + case 58: + { + ((DatePicker)target).LostKeyboardFocus += new KeyboardFocusChangedEventHandler(this.DatePicker_OnLostKeyboardFocus); + ((DatePicker)target).PreviewKeyDown += new KeyEventHandler(this.DatePicker_PreviewKeyDown); + ((DatePicker)target).MouseDoubleClick += new MouseButtonEventHandler(this.DataAtual_OnDoubleClick); + return; + } + case 59: + { + ((DataGrid)target).MouseDoubleClick += new MouseButtonEventHandler(this.Saldos_OnMouseDoubleClick); + return; + } + case 61: + { + ((DataGrid)target).CellEditEnding += new EventHandler(this.DataGrid_OnCellEditEnding); + return; + } + default: + { + this._contentLoaded = true; + return; + } + } + } + + [DebuggerNonUserCode] + [EditorBrowsable(EditorBrowsableState.Never)] + [GeneratedCode("PresentationBuildTasks", "4.0.0.0")] + void System.Windows.Markup.IStyleConnector.Connect(int connectionId, object target) + { + switch (connectionId) + { + case 32: + { + ((Chip)target).add_DeleteClick(new RoutedEventHandler(this.ExcluirFiltro_OnClick)); + return; + } + case 33: + { + ((Chip)target).add_DeleteClick(new RoutedEventHandler(this.ExcluirFiltro_onDeleteClick)); + return; + } + case 34: + case 35: + case 36: + case 42: + case 43: + { + return; + } + case 37: + { + ((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBox_Checked); + ((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBox_Checked); + return; + } + case 38: + { + EventSetter eventSetter = new EventSetter() + { + Event = ToggleButton.CheckedEvent, + Handler = new RoutedEventHandler(this.OnChecked_OnHandler) + }; + ((System.Windows.Style)target).Setters.Add(eventSetter); + eventSetter = new EventSetter() + { + Event = ToggleButton.UncheckedEvent, + Handler = new RoutedEventHandler(this.Unchecked_OnHandler) + }; + ((System.Windows.Style)target).Setters.Add(eventSetter); + return; + } + case 39: + { + ((Button)target).Click += new RoutedEventHandler(this.ArquivoDigital_OnClick); + return; + } + case 40: + { + ((Button)target).Click += new RoutedEventHandler(this.Alterar_OnClick); + return; + } + case 41: + { + ((ComboBox)target).DropDownOpened += new EventHandler(this.TipoPagamento_DropDownOpened); + ((ComboBox)target).DropDownClosed += new EventHandler(this.TipoPagamento_OnDropDownClosed); + return; + } + case 44: + { + ((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBoxFiltros_Checked); + ((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBoxFiltros_Checked); + return; + } + case 45: + { + ((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBoxFiltros_Checked); + ((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBoxFiltros_Checked); + return; + } + case 46: + { + ((CheckBox)target).Checked += new RoutedEventHandler(this.CheckBoxFiltros_Checked); + ((CheckBox)target).Unchecked += new RoutedEventHandler(this.CheckBoxFiltros_Checked); + return; + } + default: + { + if (connectionId != 60) + { + return; + } + ((Button)target).Click += new RoutedEventHandler(this.ExtratoConta_OnClick); + return; + } + } + } + + private void TipoFiltrosBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + ComboBox comboBox = (ComboBox)sender; + if (comboBox == null || comboBox.SelectedItem == null) + { + return; + } + this.ViewModel.IsvisibleStatus = System.Windows.Visibility.Visible; + this.ViewModel.IsVisibleData = System.Windows.Visibility.Collapsed; + this.ViewModel.IsVisibleFornecedor = System.Windows.Visibility.Collapsed; + this.ViewModel.IsVisiblePersonalizado = System.Windows.Visibility.Collapsed; + this.ViewModel.IsVisibleFiltros = System.Windows.Visibility.Visible; + this.ViewModel.LimparFiltros(); + this.ViewModel.SelectedFornecedor = null; + if (this.AutoCompleteFornecedor != null) + { + this.AutoCompleteFornecedor.set_Text(string.Empty); + } + this.ViewModel.DropDownHeight = 0; + switch ((FiltroLancamento)comboBox.SelectedItem) + { + case 1: + case 2: + { + this.ViewModel.IsvisibleStatus = System.Windows.Visibility.Collapsed; + this.ViewModel.IsVisibleData = System.Windows.Visibility.Visible; + return; + } + case 3: + { + this.ViewModel.IsVisibleFornecedor = System.Windows.Visibility.Visible; + return; + } + case 5: + { + this.ViewModel.IsVisiblePersonalizado = System.Windows.Visibility.Visible; + this.ViewModel.IsVisibleFiltros = System.Windows.Visibility.Collapsed; + this.GridFiltros.Visibility = System.Windows.Visibility.Collapsed; + this.MenuFiltros.Header = "MOSTRAR FILTROS"; + this.ViewModel.IsVisibleData = System.Windows.Visibility.Visible; + this.ViewModel.DropDownHeight = 200; + return; + } + default: + { + this.ViewModel.IsVisibleData = System.Windows.Visibility.Visible; + return; + } + } + } + + private void TipoPagamento_DropDownOpened(object sender, EventArgs e) + { + if (((ComboBox)sender).SelectedItem == null) + { + this.tipoPagamento = null; + return; + } + this.tipoPagamento = new TipoPagamento?((TipoPagamento)((ComboBox)sender).SelectedItem); + } + + private async void TipoPagamento_OnDropDownClosed(object sender, EventArgs e) + { + TipoPagamento? nullable = this.tipoPagamento; + TipoPagamento selectedItem = (TipoPagamento)((ComboBox)sender).SelectedItem; + if (nullable.GetValueOrDefault() == selectedItem & nullable.HasValue) + { + nullable = null; + this.tipoPagamento = nullable; + } + else if (await this.ViewModel.ShowMessage("DESEJA REPLICAR PARA OS DEMAIS LANÇAMENTOS FILTRADOS?", "SIM", "NÃO", false)) + { + nullable = null; + this.tipoPagamento = nullable; + foreach (Lancamento lancamento in this.LancamentoGrid.Items.Cast()) + { + lancamento.set_TipoPagamento((TipoPagamento)((ComboBox)sender).SelectedItem); + } + this.LancamentoGrid.CommitEdit(); + this.LancamentoGrid.CommitEdit(); + this.LancamentoGrid.Items.Refresh(); + } + } + + private void Todos_Click(object sender, RoutedEventArgs e) + { + this.ViewModel.SelectedStatusImportacao = 2; + this.ViewModel.FiltroImportacao(); + } + + private async void Transferir_OnClick(object sender, RoutedEventArgs e) + { + bool flag; + Transferencia transferencium = new Transferencia(); + transferencium.set_Data(Funcoes.GetNetworkTime().Date); + Transferencia transferencium1 = transferencium; + while (true) + { + transferencium1 = await this.ViewModel.ShowTransferencia(transferencium1); + if (transferencium1 == null) + { + transferencium1 = null; + return; + } + List> keyValuePairs = await this.ViewModel.Salvar(transferencium1); + flag = (keyValuePairs == null ? true : keyValuePairs.Count == 0); + this.ViewModel.Loading(false); + if (flag) + { + break; + } + await this.ViewModel.ShowMessage(keyValuePairs, this.ViewModel.ErroCamposInvalidos, "OK", ""); + } + this.ViewModel.ToggleSnackBar("TRANSFERÊNCIA SALVA COM SUCESSO.", true); + this.ViewModel.Alterar(false); + transferencium1 = null; + return; + transferencium1 = null; + } + + private void TrocarFornecedor_OnClick(object sender, RoutedEventArgs e) + { + this.ViewModel.Loading(true); + this.AbrirLancamento(this.ViewModel.SelectedLancamento); + this.ViewModel.VisibilityFornecedor = System.Windows.Visibility.Visible; + this.ViewModel.Loading(false); + } + + private void Unchecked_OnHandler(object sender, RoutedEventArgs e) + { + DataGridCell dataGridCell = (DataGridCell)sender; + if (this.LancamentoGrid.SelectedItem == null) + { + return; + } + Lancamento dataContext = dataGridCell.DataContext as Lancamento; + if (dataContext != null) + { + if (!dataContext.get_Selecionado()) + { + return; + } + this.ViewModel.DeSelecionarLancamento(dataContext); + this.LancamentoGrid.CommitEdit(); + this.LancamentoGrid.CommitEdit(); + CollectionViewSource.GetDefaultView(this.LancamentoGrid.ItemsSource).Refresh(); + } + } + + private void ValidarLancamento() + { + if (this.ViewModel.SelectedLancamento == null) + { + return; + } + List> keyValuePairs = this.ViewModel.SelectedLancamento.Validate(); + this.ValidateFields(keyValuePairs, false); + } + } +} \ No newline at end of file -- cgit v1.2.3