Example #1
0
        private void BB_Retorno_Click(object sender, EventArgs e)
        {
            if (lArquivos.CheckedItems != null)
            {
                if (cbCfgBoleto.SelectedItem == null)
                {
                    MessageBox.Show("Obrigatorio informar configuração.", "Mensagem", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    cbCfgBoleto.Focus();
                    return;
                }
                string[] files = new string[lArquivos.CheckedItems.Count];
                for (int i = 0; i < lArquivos.CheckedItems.Count; i++)
                {
                    files[i] = lArquivos.CheckedItems[i].ToString().Trim();
                }
                if (files.Length > 0)
                {
                    try
                    {
                        blListaTitulo lTitulos =
                            TCN_Titulo.LerRetorno((cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Empresa.Cd_empresa,
                                                  (cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Banco.Cd_banco,
                                                  path_retorno.Text,
                                                  (cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Cd_bancocorrespondente,
                                                  files);

                        if (lTitulos == null ? true : lTitulos.Count.Equals(0))
                        {
                            MessageBox.Show("Lote retorno não possui titulos para serem processados.", "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
                        {
                            //Buscar Cd.Sacado e Nm.Sacado dos titulos
                            lTitulos.ForEach(x =>
                            {
                                blListaTitulo lTitulo = new TCD_Titulo().Select(
                                    new TpBusca[] {
                                    new TpBusca()
                                    {
                                        vNM_Campo = "a.cd_empresa",
                                        vOperador = "=",
                                        vVL_Busca = "'" + (cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Empresa.Cd_empresa.Trim() + "'"
                                    },
                                    new TpBusca()
                                    {
                                        vNM_Campo = "a.id_config",
                                        vOperador = "=",
                                        vVL_Busca = (cbCfgBoleto.SelectedItem as TRegistro_CadCFGBanco).Id_configstr
                                    },
                                    new TpBusca()
                                    {
                                        vNM_Campo = "a.NossoNumero",
                                        vOperador = "=",
                                        vVL_Busca = "'" + x.Nosso_numero.Trim() + "'"
                                    }
                                }, 0, string.Empty);
                                if (lTitulo.Count > 0)
                                {
                                    x.Cd_sacado   = lTitulo[0].Cd_sacado;
                                    x.Sacado.Nome = lTitulo[0].Nm_sacado;
                                }
                            });
                            bsBloqueto.DataSource = lTitulos;
                            tot_documento.Text    = (bsBloqueto.List as blListaTitulo).Sum(p => p.Vl_atual).ToString("N2", new System.Globalization.CultureInfo("pt-BR"));
                            bsBloqueto_PositionChanged(this, new EventArgs());
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.Trim(), "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //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();
                    }
                }
            }
        }