private void BB_Conciliar_Click(object sender, EventArgs e) { if (bsBloqueto.Count > 0) { Cursor = Cursors.WaitCursor; try { string msg = string.Empty; if (TCN_Titulo.ConciliarRetorno(bsBloqueto.List as blListaTitulo, cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco, null, ref msg).Trim() != string.Empty) { MessageBox.Show("Conciliação de bloquetos realizada com sucesso." + (msg.Trim() != string.Empty ? "\r\n\r\nBloqueto que não foram compensados:\r\n" + msg.Trim() : string.Empty), "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); //Gravar tarifa de cobranca if (((bsBloqueto.List as blListaTitulo).Sum(p => p.Vl_despesa_cobranca) > decimal.Zero || (cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Vl_taxa > decimal.Zero) && (!string.IsNullOrEmpty((cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Cd_historico_taxacob))) { try { TCN_Titulo.GravarTarifas(bsBloqueto.List as blListaTitulo, cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco, null); MessageBox.Show("Tarifa(s) gravada(s) com sucesso.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Erro gravar tarifa: " + ex.Message); } } //Verificar se empresa integra Vendas Externa TList_CFGVendasExterna lCfg = TCN_CFGVendasExterna.Buscar((cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Empresa.Cd_empresa, null); if (lCfg.Count > 0) { if (ValidarToken(lCfg[0].Login, lCfg[0].Senha, lCfg[0].Licenca, lCfg[0].Integracao)) { string mensagem = string.Empty; (bsBloqueto.List as blListaTitulo) .Where(x => x.Vl_recebido > decimal.Zero) .ToList() .ForEach(x => { try { if (ServiceRest.DataService.BaixarBoletos( new BaixarBoleto { CODIGO = x.Cd_integracao, DATA_PAGAMENTO = x.Dt_credito.Value.ToString("yyyy-MM-dd HH:mm:ss"), VALOR_PAGO = x.Vl_recebido.ToString("N2", new System.Globalization.CultureInfo("en-US", true)) }, _token)) { x.St_baixadointegracao = "S"; TCN_Titulo.Gravar(x, null); } else { mensagem += "Boleto Nº" + x.Nosso_numero + " não foi integrada\r\n"; } } catch { mensagem += "Boleto Nº" + x.Nosso_numero + " não foi integrada\r\n"; } }); if (string.IsNullOrWhiteSpace(mensagem)) { MessageBox.Show("Relação de boletos não integrados com Vendas Externas.\r\n" + mensagem, "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } //Mover arquivos processados para pasta backup if (!System.IO.Directory.Exists(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp")) { System.IO.Directory.CreateDirectory(path_retorno.Text + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp"); } for (int i = 0; i < lArquivos.CheckedItems.Count; i++) { if (!System.IO.File.Exists(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp" + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim())) { System.IO.File.Move(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim(), path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp" + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim()); } else { System.IO.File.Delete(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp" + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim()); } } bsBloqueto.Clear(); MontarListaArqRet(); } else { MessageBox.Show("Não existe bloqueto em aberto para compensar neste arquivo.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); //Mover arquivos processados para pasta backup if (!System.IO.Directory.Exists(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp")) { System.IO.Directory.CreateDirectory(path_retorno.Text + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp"); } for (int i = 0; i < lArquivos.CheckedItems.Count; i++) { if (!System.IO.File.Exists(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp" + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim())) { System.IO.File.Move(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim(), path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp" + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim()); } else { System.IO.File.Delete(path_retorno.Text.Trim() + System.IO.Path.DirectorySeparatorChar.ToString() + "bkp" + System.IO.Path.DirectorySeparatorChar.ToString() + lArquivos.CheckedItems[i].ToString().Trim()); } } bsBloqueto.Clear(); MontarListaArqRet(); } //Cobrança //gerarCobrancaPorEmail(); } catch (Exception ex) { MessageBox.Show("Erro: " + ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { Cursor = Cursors.Default; } } else { MessageBox.Show("Não existe titulos para ser conciliado.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
public TList_CFGVendasExterna Select(Utils.TpBusca[] vBusca, int vTop, string vNm_Campo) { TList_CFGVendasExterna lista = new TList_CFGVendasExterna(); System.Data.SqlClient.SqlDataReader reader = null; bool podeFecharBco = false; if (Banco_Dados == null) { podeFecharBco = CriarBanco_Dados(false); } try { reader = ExecutarBusca(SqlCodeBusca(vBusca, Convert.ToInt16(vTop), vNm_Campo)); while (reader.Read()) { TRegistro_CFGVendasExterna reg = new TRegistro_CFGVendasExterna(); if (!reader.IsDBNull(reader.GetOrdinal("cd_empresa"))) { reg.Cd_empresa = reader.GetString(reader.GetOrdinal("cd_empresa")); } if (!reader.IsDBNull(reader.GetOrdinal("nm_empresa"))) { reg.Nm_empresa = reader.GetString(reader.GetOrdinal("nm_empresa")); } if (!reader.IsDBNull(reader.GetOrdinal("cd_uf"))) { reg.Cd_uf_empresa = reader.GetString(reader.GetOrdinal("cd_uf")); } if (!reader.IsDBNull(reader.GetOrdinal("Login"))) { reg.Login = reader.GetString(reader.GetOrdinal("Login")); } if (!reader.IsDBNull(reader.GetOrdinal("Senha"))) { reg.Senha = reader.GetString(reader.GetOrdinal("Senha")); } if (!reader.IsDBNull(reader.GetOrdinal("Licenca"))) { reg.Licenca = reader.GetString(reader.GetOrdinal("Licenca")); } if (!reader.IsDBNull(reader.GetOrdinal("Integracao"))) { reg.Integracao = reader.GetString(reader.GetOrdinal("Integracao")); } if (!reader.IsDBNull(reader.GetOrdinal("TP_Duplicata"))) { reg.Tp_duplicata = reader.GetString(reader.GetOrdinal("TP_Duplicata")); } if (!reader.IsDBNull(reader.GetOrdinal("DS_TpDuplicata"))) { reg.Ds_tpduplicata = reader.GetString(reader.GetOrdinal("DS_TpDuplicata")); } if (!reader.IsDBNull(reader.GetOrdinal("TP_Docto"))) { reg.Tp_docto = reader.GetDecimal(reader.GetOrdinal("TP_Docto")); } if (!reader.IsDBNull(reader.GetOrdinal("ds_tpdocto"))) { reg.Ds_tpdocto = reader.GetString(reader.GetOrdinal("ds_tpdocto")); } if (!reader.IsDBNull(reader.GetOrdinal("cd_condpgto"))) { reg.Cd_condpgto = reader.GetString(reader.GetOrdinal("cd_condpgto")); } if (!reader.IsDBNull(reader.GetOrdinal("ds_condpgto"))) { reg.Ds_condpgto = reader.GetString(reader.GetOrdinal("ds_condpgto")); } if (!reader.IsDBNull(reader.GetOrdinal("cd_historico"))) { reg.Cd_historico = reader.GetString(reader.GetOrdinal("cd_historico")); } if (!reader.IsDBNull(reader.GetOrdinal("ds_historico"))) { reg.Ds_historico = reader.GetString(reader.GetOrdinal("ds_historico")); } if (!reader.IsDBNull(reader.GetOrdinal("id_config"))) { reg.Id_config = reader.GetDecimal(reader.GetOrdinal("id_config")); } if (!reader.IsDBNull(reader.GetOrdinal("ds_config"))) { reg.Ds_config = reader.GetString(reader.GetOrdinal("ds_config")); } if (!reader.IsDBNull(reader.GetOrdinal("CFG_Pedido"))) { reg.Cfg_pedido = reader.GetString(reader.GetOrdinal("CFG_Pedido")); } if (!reader.IsDBNull(reader.GetOrdinal("DS_TipoPedido"))) { reg.Ds_tipopedido = reader.GetString(reader.GetOrdinal("DS_TipoPedido")); } lista.Add(reg); } } finally { reader.Close(); reader.Dispose(); if (podeFecharBco) { deletarBanco_Dados(); } } return(lista); }