--unificación de función para envío
This commit is contained in:
@@ -11,7 +11,7 @@ Imports CrystalDecisions.CrystalReports.Engine
|
||||
Imports CrystalDecisions.Shared
|
||||
Imports Microsoft.Reporting.WebForms
|
||||
|
||||
Public Class TareasProgramadas : Implements IHttpHandler
|
||||
Public Class TareasProgramadas : Implements IHttpHandler, IReadOnlySessionState
|
||||
|
||||
|
||||
Private ReadOnly Property GlobalDTUsuariosE140(Optional CveUsuario As Integer = -1, Optional CveCliente As Integer = -1, Optional CveProveedor As Integer = -1) As DataTable
|
||||
@@ -95,12 +95,16 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
CargaEstadosCuenta(context, 119, -1, FechaEnvio, FechaActual)
|
||||
|
||||
Case "ScoreCard"
|
||||
CargaScoreCard(context, 140, FechaEnvio)
|
||||
CargaScoreCard(context, 140, FechaEnvio)
|
||||
Case "EjecutaReporteDiario"
|
||||
Dim tCveEmpresa As Integer = context.Request("CveEmpresa").ToString.ToEntero
|
||||
retorno = If(ReporteDiario(tCveEmpresa, context), "True", "false")
|
||||
context.Response.Write(retorno)
|
||||
End Select
|
||||
Catch ex As Exception
|
||||
ex.GuardaLog(ex.ToString())
|
||||
context.Response.Write(retorno)
|
||||
End Try
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
@@ -332,7 +336,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
If DtEmpresas IsNot Nothing Then
|
||||
For Each Row As DataRow In DtEmpresas.Rows
|
||||
Dim Usuario As Usuario = ValidaUsuarioSistema(Row("CveEmpresa").ToString().ToEntero())
|
||||
Dim Usuario As Usuario = ValidaUsuarioSistema(100, Row("CveEmpresa").ToString().ToEntero())
|
||||
Dim obj As JObject = EjecutarEnvioEstadoCuenta(Usuario, FechaEnvio, FechaActual, pCveCliente:=pCveCliente)
|
||||
|
||||
Retorno.Add(obj)
|
||||
@@ -347,11 +351,11 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function ValidaUsuarioSistema(CveEmpresa As Integer) As Usuario
|
||||
Private Function ValidaUsuarioSistema(CveUsuario As Integer, CveEmpresa As Integer) As Usuario
|
||||
Dim UsuarioActual As Usuario = Nothing
|
||||
Dim NombreCadena As String = ClsPaginas.GlobalNombreCadenaConexion(CveEmpresa)
|
||||
Dim ObjUsuarios As New ClsSisUsuarioAutenticacion(NombreCadena:=NombreCadena)
|
||||
UsuarioActual = ObjUsuarios.GetUsuarioDetalle(100)
|
||||
UsuarioActual = ObjUsuarios.GetUsuarioDetalle(CveUsuario, CveEmpresa)
|
||||
If UsuarioActual IsNot Nothing Then
|
||||
HttpContext.Current.Session("UsuarioSIG") = UsuarioActual
|
||||
'CreaObjetoEmpresa(UsuarioActual)
|
||||
@@ -874,7 +878,7 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
|
||||
#Region "S C O R E C A R D"
|
||||
Private Sub CargaScoreCard(ByVal context As HttpContext, pCveEmpresa As Integer, FechaEnvio As DateTime)
|
||||
Dim Usuario As Usuario = ValidaUsuarioSistema(pCveEmpresa)
|
||||
Dim Usuario As Usuario = ValidaUsuarioSistema(100, pCveEmpresa)
|
||||
Dim obj As Boolean = EjecutarEnvioScoreCard(Usuario, FechaEnvio)
|
||||
|
||||
End Sub
|
||||
@@ -1298,4 +1302,102 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
#Region "R E P O R T E D I A R I O "
|
||||
Private Function ReporteDiario(ByVal CveEmpresa As Integer, ByVal context As HttpContext) As Boolean
|
||||
Dim Usuario As Usuario = ValidaUsuarioSistema(100, CveEmpresa)
|
||||
Dim objGenerales As ClsGenerales = New ClsGenerales()
|
||||
Dim respuesta As Boolean = True
|
||||
Dim sbTablas As StringBuilder = New StringBuilder()
|
||||
sbTablas.Append($"<b><center>Reporte Diario {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}</center><b><br><br>")
|
||||
|
||||
If objGenerales.GetReporteDiario(CveEmpresa) Then
|
||||
Dim TablaActual As Integer = 1
|
||||
|
||||
For Each tabla As DataTable In objGenerales.DSResultados.Tables
|
||||
sbTablas.AppendLine(ConvertDataTableToHtml(tabla))
|
||||
TablaActual += 1
|
||||
sbTablas.Append("<br>")
|
||||
sbTablas.Append("<br>")
|
||||
Next
|
||||
Else
|
||||
respuesta = False
|
||||
End If
|
||||
|
||||
objGenerales.Dispose()
|
||||
'MandaCorreoDiario
|
||||
'Dim Correos As String = "hdiaz@grupodiaz.com.mx;libarra@grupodiaz.com.mx;jguerrero@grupodiaz.com.mx;contabilidad@grupodiaz.com.mx;cnazarit@yahoo.com;julian@adsistemas.mx;rene.molina@adssistemas.mx"
|
||||
Dim Correos As String = " rene.molina@adssistemas.mx"
|
||||
MandaCorreoDiario(sbTablas.ToString(), Correos, respuesta)
|
||||
Return respuesta
|
||||
End Function
|
||||
|
||||
Private Function ConvertDataTableToHtml(ByVal table As DataTable) As String
|
||||
Dim html As StringBuilder = New StringBuilder()
|
||||
Dim ColumnaTitulo As String = "Titulo"
|
||||
html.Append("<table border='1' style='border-collapse:collapse; width:100%;'>")
|
||||
If table.Columns(0).ColumnName = ColumnaTitulo AndAlso table.Rows.Count > 0 Then html.AppendFormat(" <caption style='background-color:#333333;'>{0}</caption>", table.Rows(0)(ColumnaTitulo))
|
||||
html.Append("<thead style='background-color:#DDD; padding: 0px;'><tr>")
|
||||
|
||||
For Each column As DataColumn In table.Columns
|
||||
If ColumnaTitulo <> column.ColumnName Then html.Append($"<th style='padding:5px; text-align:left;'>{column.ColumnName}</th>")
|
||||
Next
|
||||
|
||||
html.Append("</tr></thead>")
|
||||
html.Append("<tbody>")
|
||||
Dim numericValue As Decimal = Nothing
|
||||
|
||||
For Each row As DataRow In table.Rows
|
||||
html.Append("<tr>")
|
||||
|
||||
For Each column As DataColumn In table.Columns
|
||||
|
||||
If ColumnaTitulo <> column.ColumnName Then
|
||||
Dim value As Object = row(column)
|
||||
Dim cellValue As String
|
||||
|
||||
If column.DataType = GetType(Integer) OrElse column.DataType = GetType(Decimal) OrElse column.DataType = GetType(Double) OrElse column.DataType = GetType(Single) Then
|
||||
|
||||
If value IsNot DBNull.Value AndAlso Decimal.TryParse(value.ToString(), numericValue) Then
|
||||
|
||||
If numericValue <> 0 Then
|
||||
cellValue = numericValue.ToString("N2")
|
||||
Else
|
||||
cellValue = ""
|
||||
End If
|
||||
Else
|
||||
cellValue = ""
|
||||
End If
|
||||
|
||||
html.Append($"<td style='padding:5px; text-align:right;'>{cellValue}</td>")
|
||||
Else
|
||||
cellValue = If(value?.ToString(), String.Empty)
|
||||
html.Append($"<td style='padding:5px; text-align:left;'>{cellValue}</td>")
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
html.Append("</tr>")
|
||||
Next
|
||||
|
||||
html.Append("</tbody>")
|
||||
html.Append("</table>")
|
||||
Return html.ToString()
|
||||
End Function
|
||||
|
||||
Private Sub MandaCorreoDiario(ByVal Cuerpo As String, Correos As String, ByVal ProcesoOK As Boolean)
|
||||
Try
|
||||
Dim ListaArchivos As List(Of ClsSisMail.ArchivoMail) = New List(Of ClsSisMail.ArchivoMail)()
|
||||
Dim Correo As ClsSisMail = New ClsSisMail()
|
||||
Dim Para As String = Correos '"hdiaz@grupodiaz.com.mx;libarra@grupodiaz.com.mx;jguerrero@grupodiaz.com.mx;contabilidad@grupodiaz.com.mx;cnazarit@yahoo.com;julian@adsistemas.mx;rene.molina@adssistemas.mx"
|
||||
Dim Asunto As String = If(ProcesoOK, $"Reporte Diario", "Reporte Diario Error")
|
||||
Asunto = $"{Asunto} {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}"
|
||||
Correo.SendMail(ClsPaginas.EmpresaNotificaciones, Para, Asunto, Cuerpo, Archivos:=ListaArchivos)
|
||||
Me.GuardaLog($"EjecutaReporteDiario: MandaCorreo() correo enviado. ")
|
||||
Catch ex As Exception
|
||||
Extensiones.ModExtensiones.GuardaLog(Nothing, $"Error Tareas Programadas 119 error enviar mail --> {ex.Message} ")
|
||||
Me.GuardaLog($"EjecutaReporteDiario: MandaCorreo() Error {ex.StackTrace.ToString()}. ")
|
||||
End Try
|
||||
End Sub
|
||||
End Class
|
||||
#End Region
|
||||
|
||||
Reference in New Issue
Block a user