private ListViewItem CriarItem(ref DadosBgCarregar dados, DateTime hoje, ref double valorTotal, ref double valorTotalLíquido, ref double valorPendente, Entidades.Pagamentos.Pagamento p) { ListViewItem item = new ListViewItem(new string[11] { "", "", "", "", "", "", "", "", "", "", "" }); ListaPagamentoItem itemPagamento = new ListaPagamentoItem(p); valorTotal += p.Valor; item.SubItems[colData.Index].Text = p.Data.ToShortDateString(); item.SubItems[colRegistradoPor.Index].Text = p.RegistradoPor.Nome; item.SubItems[colValor.Index].Text = Math.Abs(p.Valor).ToString("C", DadosGlobais.Instância.Cultura); item.SubItems[colDescrição.Index].Text = p.DescriçãoCompleta; if (p is IProrrogável) { IProrrogável prorrogável = (IProrrogável)p; itemPagamento.ProrrogadoPara = prorrogável.ProrrogadoPara; if (prorrogável.ProrrogadoPara.HasValue) item.SubItems[colProrrogação.Index].Text = prorrogável.ProrrogadoPara.Value.ToShortDateString(); else item.SubItems[colProrrogação.Index].Text = ""; } else itemPagamento.ProrrogadoPara = null; if (p is Cheque) itemPagamento.Vencimento = ((Cheque) p).Vencimento; else itemPagamento.Vencimento = p.ÚltimoVencimento; if (itemPagamento.Vencimento.HasValue) { item.SubItems[colVencimento.Index].Text = itemPagamento.Vencimento.Value.ToString("dd/MM/yyyy"); } if (p.Pendente) valorPendente += p.Valor; if (venda != null) { itemPagamento.Dias = p.ObterDiasJuros(venda); item.SubItems[colDias.Index].Text = itemPagamento.Dias.ToString(); try { itemPagamento.ValorLíquido = p.ObterValorLíquido(venda); } catch { itemPagamento.ValorLíquido = 0; } valorTotalLíquido += itemPagamento.ValorLíquido; item.SubItems[colValorLíquido.Index].Text = itemPagamento.ValorLíquido.ToString("C", Entidades.Configuração.DadosGlobais.Instância.Cultura); } if (p.Venda.HasValue) item.SubItems[colPagaVenda.Index].Text = Entidades.Relacionamento.Venda.Venda.FormatarCódigo(p.Venda.Value); long? pagoNaVenda = null; dados.hashPagoNaVenda.TryGetValue(p.Código, out pagoNaVenda); if (pagoNaVenda.HasValue) item.SubItems[colPagoNaVenda.Index].Text = Entidades.Relacionamento.Venda.Venda.FormatarCódigo(pagoNaVenda.Value).ToString(); else item.SubItems[colPagoNaVenda.Index].Text = ""; item.ImageKey = p.Tipo.ToString(); if (p.Pendente) { item.UseItemStyleForSubItems = true; item.BackColor = Color.Yellow; if (p.ÚltimoVencimento < hoje) item.ForeColor = Color.Red; } hashItemListaPagamento[item] = itemPagamento; return item; }
private void bgCarregar_DoWork(object sender, DoWorkEventArgs e) { try { DadosBgCarregar dados = new DadosBgCarregar(); // Reobtem os dados if (venda != null) dados.entidades = Entidades.Pagamentos.Pagamento.ObterPagamentos(venda); else dados.entidades = Entidades.Pagamentos.Pagamento.ObterPagamentos(cliente); dados.hashPagoNaVenda = Entidades.Relacionamento.Venda.Venda.ObterCódigoVendasQuePagam(dados.entidades); e.Result = dados; } catch (Exception erro) { Acesso.Comum.Usuários.UsuárioAtual.RegistrarErro(erro); } }