Public Class correos ''' ''' Genera un registro de correo electrónico saliente en la base de datos. ''' ''' ''' ''' ''' ''' ''' ''' 1 si se ha guardado el correo, 0 en caso contrario ''' Devuelve el número de líneas modificadas tras escribir en la base de datos el correo que se desea enviar. Public Shared Function GeneraRegistroCorreo(bd As bdGestionAsegasa.gestionasegasaEntities, Asunto As String, Cuerpo As String, cuenta As cuentascorreo, Destinatario As String, Optional Copia As String = "", Optional CopiaOculta As String = "", Optional idfichero As Integer? = Nothing, Optional MarcarComoAnulado As Boolean = False, Optional Remitente As String = "", Optional ResponderA As String = "") As Integer Dim resultado As Integer = 0 Try If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto Dim sRutaAdjunto As String = "" Dim correo = New correos With { .Asunto = Asunto, .Cuerpo = Cuerpo, .Destinatario = Destinatario, .Copia = Copia, .CopiaOculta = CopiaOculta, .DireccionRespuesta = If(ResponderA <> "", ResponderA, cuenta.ResponderA), .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idcuenta = cuenta.idCuenta, .Remitente = If(Remitente <> "", Remitente, cuenta.Remitente), .idFicheroAdjunto = idfichero } If MarcarComoAnulado Then correo.FechaAnulacion = Now bd.correos.AddObject(correo) bd.GuardarCambios() Return correo.idcorreo Catch ex As Exception Debug.Write(ex.Message) Throw New Exception(ex.Message, ex) End Try Return resultado End Function Public Shared Function GeneraRegistroCorreoConAdjunto(bd As bdGestionAsegasa.gestionasegasaEntities, Asunto As String, Cuerpo As String, cuenta As cuentascorreo, Fichero As Byte(), NombreFichero As String, DescripcionFichero As String, Destinatario As String, Optional Copia As String = "", Optional CopiaOculta As String = "", Optional MarcarComoAnulado As Boolean = False, Optional Remitente As String = "", Optional idAplicacion As Integer? = Nothing, Optional CodigoAplicacion As String = "") As Integer Dim resultado As Integer = 0 Try If bd Is Nothing Then bd = bdGestionAsegasa.gestionasegasaEntities.NuevoContexto Dim idTipoAdjunto = bd.enumeraciones.First(Function(x) x.Codigo = "TIPFIC.ADJCOR").idEnumeracion Dim f As New ficheros With { .idTipo = idTipoAdjunto, .Descripcion = DescripcionFichero, .Fichero = Fichero, .NombreFichero = NombreFichero} bd.ficheros.AddObject(f) bd.SaveChanges() Dim correo = New correos With { .Asunto = Asunto, .Cuerpo = Cuerpo, .Destinatario = Destinatario, .Copia = Copia, .CopiaOculta = CopiaOculta, .DireccionRespuesta = cuenta.ResponderA, .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idcuenta = cuenta.idCuenta, .Remitente = If(Remitente <> "", Remitente, cuenta.Remitente), .idFicheroAdjunto = f.idFichero, .idAplicacion = idAplicacion, .CodigoAplicacion = CodigoAplicacion } If MarcarComoAnulado Then correo.FechaAnulacion = Now bd.correos.AddObject(correo) bd.GuardarCambios() Return correo.idcorreo Catch ex As Exception Debug.Write(ex.Message) Throw End Try Return resultado End Function Public Shared Function GeneraRegistroCorreoVariosFicheros(bd As bdGestionAsegasa.gestionasegasaEntities, Asunto As String, Cuerpo As String, cuenta As cuentascorreo, Destinatario As String, Optional idficheros As List(Of Integer) = Nothing, Optional FechaAnulacion As DateTime? = Nothing) As Integer Try Dim sRutaAdjunto As String = "" Dim correo = New correos With { .Asunto = Asunto, .Cuerpo = Cuerpo, .Destinatario = Destinatario, .DireccionRespuesta = cuenta.Remitente, .FechaCreacion = bdGestionAsegasa.Utilidades.AhoraMysql(bd), .idcuenta = cuenta.idCuenta, .Remitente = cuenta.Remitente, .FechaAnulacion = FechaAnulacion } For Each f In idficheros Dim nf As New ficherosadjuntos With {.idFichero = f} correo.ficherosadjuntos.Add(nf) Next bd.correos.AddObject(correo) bd.GuardarCambios() Return correo.idcorreo Catch ex As Exception Throw New Exception("Error en GeneraRegistroCorreoVariosFicheros. Asunto:" & Asunto & " " & ex.Message, ex) End Try End Function Public ReadOnly Property FicheroAdjunto As String Get If Me.idFicheroAdjunto.HasValue Then Return Me.ficheros.NombreFichero Else Return "" End If End Get End Property Public Class CorreoReducido Public Property idCorreo As Integer Public Property Destinatario As String Public Property Asunto As String Public Property FechaCreacion As DateTime Public Property FechaAnulacion As DateTime? Public Property MensajeError As String Public Property Aplicacion As String Public Property CodigoAplicacion As String End Class End Class