public bool EnviarReportePorEmail(int nCodCred, int nCodAge, string cEmail, string cnombres, double nPrestamo, int nPEP, ref bool bError, ref string cMensajeError) { bool bRespuesta = true; MemoryStream datoFile = null; List <Attachment> lstFiles = new List <Attachment>(); List <string> lstArchivos = new List <string>(); List <object> lstArchivos1 = new List <object>(); List <string> lstArchivos2 = new List <string>(); List <DocumentosReporte> lstDocumentos = new List <DocumentosReporte>(); Attachment anexo = null; Dictionary <int, string> lstDiccionario = null; DocumentosReporte documentos = new DocumentosReporte(); lstDiccionario = listaDictionary(); string cNombreDocumento = ""; string cBodyCliente = generaCuerpoEmail(cnombres, nPrestamo); try { foreach (var item in lstDiccionario) { if (item.Value == "/WEB/004_FormularioIdentificacionPersonas" && nPEP == 0) { //nada } else { var renderedbytes = ReporteABytes(nCodAge, nCodCred, item.Value); datoFile = new MemoryStream(renderedbytes); datoFile.Seek(0, SeekOrigin.Begin); var splited = item.Value.Split('/'); cNombreDocumento = splited[2] + ".PDF"; anexo = new Attachment(datoFile, cNombreDocumento); lstFiles.Add(anexo); documentos = new DocumentosReporte(); documentos.nombre = cNombreDocumento; documentos.doc = renderedbytes; lstDocumentos.Add(documentos); } } using (var smtpCliente = new SmtpClient(SMTP, PUERTO)) { smtpCliente.Credentials = new NetworkCredential(CORREO_CREDENCIALES, CLAVE_CREDENCIALES); smtpCliente.EnableSsl = true; MailMessage mail = new MailMessage(); mail.Body = cBodyCliente; mail.IsBodyHtml = true; mail.To.Add(new MailAddress(cEmail)); mail.From = new MailAddress(CORREO, NOMBRE); mail.Subject = "¡Felicitaciones!, tu préstamo ha sido aprobado."; mail.SubjectEncoding = Encoding.UTF8; mail.Priority = MailPriority.Normal; mail.IsBodyHtml = true; foreach (var item in lstFiles) { mail.Attachments.Add(item); } smtpCliente.Send(mail); bRespuesta = true; } if (bRespuesta) { _unit.Reporte.LucasInsCabeceraReporte(nCodAge, nCodCred, "¡Felicitaciones!, tu préstamo ha sido aprobado.", cBodyCliente); var nTipoDoc = 0; for (int i = 0; i < lstDocumentos.Count; i++) { if (lstDocumentos[i].nombre == "Hoja_Resumen_Informativa_Anexo_1_ONL.PDF") { nTipoDoc = 1; } if (lstDocumentos[i].nombre == "Hoja_Resumen_Informativa_Anexo_2_ONL.PDF") { nTipoDoc = 2; } if (lstDocumentos[i].nombre == "001_FichaDeSolicitudDePrestamo.PDF") { nTipoDoc = 6; } if (lstDocumentos[i].nombre == "002_ContratoPrestamoOnline.PDF") { nTipoDoc = 5; } if (lstDocumentos[i].nombre == "003_CertificadoDeSeguroDesgravamen.PDF") { nTipoDoc = 7; } if (lstDocumentos[i].nombre == "004_FormularioIdentificacionPersonas.PDF") { nTipoDoc = 8; } _unit.Reporte.LucasInsDetalleReporte(nCodAge, nCodCred, nTipoDoc, lstDocumentos[i].doc); } } } catch (Exception ex) { bError = true; cMensajeError = "Error: " + ex.Message; bRespuesta = false; _unit.Error.InsertaError("Reporte Controller - EnviarReportePorEmail", ex.Message); } return(bRespuesta); }
public bool generaReportes(int nCodCred, int nCodAge, int nPEP, ref bool bError, ref string cMensajeError) { bool bRespuesta = true; MemoryStream datoFile = null; List <Attachment> lstFiles = new List <Attachment>(); List <string> lstArchivos = new List <string>(); List <object> lstArchivos1 = new List <object>(); List <string> lstArchivos2 = new List <string>(); List <DocumentosReporte> lstDocumentos = new List <DocumentosReporte>(); Attachment anexo = null; Dictionary <int, string> lstDiccionario = null; DocumentosReporte documentos = new DocumentosReporte(); lstDiccionario = listaDictionary(); string cNombreDocumento = ""; try { foreach (var item in lstDiccionario) { if (item.Value == "/WEB/004_FormularioIdentificacionPersonas" && nPEP == 0) { //nada } else { var renderedbytes = ReporteABytes(nCodAge, nCodCred, item.Value); datoFile = new MemoryStream(renderedbytes); datoFile.Seek(0, SeekOrigin.Begin); var splited = item.Value.Split('/'); cNombreDocumento = splited[2] + ".PDF"; anexo = new Attachment(datoFile, cNombreDocumento); lstFiles.Add(anexo); documentos = new DocumentosReporte(); documentos.nombre = cNombreDocumento; documentos.doc = renderedbytes; lstDocumentos.Add(documentos); } } _unit.Reporte.LucasInsCabeceraReporte(nCodAge, nCodCred, "¡Felicitaciones!, tu préstamo ha sido aprobado.", ""); var nTipoDoc = 0; for (int i = 0; i < lstDocumentos.Count; i++) { if (lstDocumentos[i].nombre == "Hoja_Resumen_Informativa_Anexo_1_ONL.PDF") { nTipoDoc = 1; } if (lstDocumentos[i].nombre == "Hoja_Resumen_Informativa_Anexo_2_ONL.PDF") { nTipoDoc = 2; } if (lstDocumentos[i].nombre == "001_FichaDeSolicitudDePrestamo.PDF") { nTipoDoc = 6; } if (lstDocumentos[i].nombre == "002_ContratoPrestamoOnline.PDF") { nTipoDoc = 5; } if (lstDocumentos[i].nombre == "003_CertificadoDeSeguroDesgravamen.PDF") { nTipoDoc = 7; } if (lstDocumentos[i].nombre == "004_FormularioIdentificacionPersonas.PDF") { nTipoDoc = 8; } _unit.Reporte.LucasInsDetalleReporte(nCodAge, nCodCred, nTipoDoc, lstDocumentos[i].doc); } } catch (Exception ex) { bError = true; cMensajeError = "Error: " + ex.Message; bRespuesta = false; _unit.Error.InsertaError("Reporte Controller - generaReportes", ex.Message); } return(bRespuesta); }