private void cmdCarregar_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); if (this.cboBanco.SelectedIndex <= 0) { sb.AppendLine(" -Selecione o banco para que o arquivo seja carregado no layout correto."); } if (string.IsNullOrEmpty(this.txtFile.Text)) { sb.AppendLine(" -Selecione o arquivo de retorno do CNAB para carregar."); } if (sb.Length > 0) { sb.Insert(0, "PREENCHIMENTO OBRIGATÓRIO\r\n\r\n"); CompSoft.compFrameWork.MsgBox.Show(sb.ToString() , "Atenção" , MessageBoxButtons.OK , MessageBoxIcon.Information); } else { //-- Define o bancos BoletoNet.IBanco banco = new BoletoNet.Banco(Convert.ToInt32(this.cboBanco.SelectedValue)); CNAB.CNAB cnab = new CNAB.CNAB(); cnab.Arquivo_Retorno_Banco(this.txtFile.Text, banco); } }
private void cmdGerar_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); if (this.grdNotasFiscais.BindingSource == null || ((DataTable)this.grdNotasFiscais.BindingSource.DataSource).Select("Sel = 1").Length == 0) { sb.AppendLine(" - Selecione as duplicatas que você deseja gerar os boletos."); } if (!this.chkGerarRemessa.Checked && !this.chkImprimirBoleto.Checked) { sb.AppendLine(" - Selecione uma ou mais ações:"); sb.AppendLine(" - Imprimir boletos;"); sb.AppendLine(" - Gerar arquivo de remessa."); } if (this.chkGerarRemessa.Checked && string.IsNullOrEmpty(this.txtArquivoRemessa.Text)) { sb.AppendLine(" - Selecione a pasta onde o arquivo de remessa vai ser gerado."); } if (sb.Length > 0) { sb.Insert(0, "ERRO AO GERAR/IMPRIMIR BOLETOS.\r\n\r\n"); MsgBox.Show(sb.ToString() , "Erro ao gerar boleto" , MessageBoxButtons.OK , MessageBoxIcon.Asterisk); } else { List <int> ilDuplicatas = new List <int>(); foreach (DataRow row in ((DataTable)this.grdNotasFiscais.BindingSource.DataSource).Select("sel=1")) { ilDuplicatas.Add(Convert.ToInt32(row["Nota_Fiscal_Duplicata"])); } CNAB.CNAB cnab = new CNAB.CNAB(); Dictionary <int, BoletoBancario> ilBB = cnab.Gerar_Boleto(ilDuplicatas); //-- Faz a impressão dos boletos... if (this.chkImprimirBoleto.Checked) { DataTable dt = cnab.Gerar_Dados_Boleto(ilDuplicatas); Dictionary <int, Image> ilLogoBanco = cnab.Localizar_Logos_Bancos(ilDuplicatas); ERP.Reports.rBoleto r = new Reports.rBoleto(dt, ilBB, ilLogoBanco); r.ShowPreviewDialog(); } //-- Gera o arquivo de remessa if (this.chkGerarRemessa.Checked) { int iNumeroLote = 0; bool bArquivoGerado = cnab.Gerar_Arquivo_Remessa(ilBB, this.txtArquivoRemessa.Text, ref iNumeroLote); if (bArquivoGerado) { MsgBox.Show("Arquivo de remessa gerado com sucesso." , "Arquivo de remessa" , MessageBoxButtons.OK , MessageBoxIcon.Information); //-- Marca duplicatas como gerada. foreach (int iNota_Fiscal_Duplicata in ilBB.Keys) { CNAB.CNAB.Grava_Arquivo_Remessa(iNota_Fiscal_Duplicata, iNumeroLote); } } else { MsgBox.Show("Erro ao gerar arquivo de remessa." , "Arquivo de remessa" , MessageBoxButtons.OK , MessageBoxIcon.Error); } } ((DataTable)this.grdNotasFiscais.BindingSource.DataSource).Clear(); this.txtNumeroNF.Text = string.Empty; this.txtNumeroPedido.Text = string.Empty; } }