--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
|
||||
|
||||
@@ -1,294 +0,0 @@
|
||||
<%@ WebHandler Language="C#" Class="TareasReporteDairio" %>
|
||||
|
||||
using System;
|
||||
using System.Web;
|
||||
using Extensiones;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using System.Web.Services;
|
||||
using System.Web.Services.Protocols;
|
||||
using GemBox.Spreadsheet;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using ClosedXML;
|
||||
|
||||
using System.Web.SessionState;
|
||||
using System.Web.Hosting;
|
||||
|
||||
public class TareasReporteDairio : IHttpHandler
|
||||
{
|
||||
|
||||
public void ProcessRequest(HttpContext context)
|
||||
{
|
||||
context.Response.ContentType = "text/plain";
|
||||
//context.Response.Write("Hello World");
|
||||
bool retorno = false;
|
||||
string Metodo = context.Request["Metodo"] ==null?"": context.Request["Metodo"];
|
||||
int CveEmpresa =context.Request["CveEmpresa"] ==null?0: context.Request["CveEmpresa"].ToEntero();
|
||||
switch (Metodo)
|
||||
{
|
||||
case "EjecutaReporteDiario":
|
||||
retorno = ReporteDiario(CveEmpresa, context);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (retorno)
|
||||
{
|
||||
context.Response.Write("True");
|
||||
|
||||
}else
|
||||
{
|
||||
context.Response.Write("False");
|
||||
|
||||
}
|
||||
|
||||
context.Response.End();
|
||||
|
||||
}
|
||||
private bool ReporteDiario(int CveEmpresa, HttpContext context)
|
||||
{
|
||||
Usuario Usuario = ValidaUsuarioSistema(100, CveEmpresa);
|
||||
|
||||
ClsGenerales objGenerales = new ClsGenerales();
|
||||
bool respuesta = true;
|
||||
StringBuilder sbTablas = 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))
|
||||
{
|
||||
int TablaActual = 1;
|
||||
foreach (DataTable tabla in objGenerales.DSResultados.Tables)
|
||||
{
|
||||
sbTablas.AppendLine(ConvertDataTableToHtml(tabla));
|
||||
TablaActual++;
|
||||
sbTablas.Append("<br>");
|
||||
sbTablas.Append("<br>");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
respuesta = false;
|
||||
}
|
||||
|
||||
objGenerales.Dispose();
|
||||
|
||||
MandaCorreo(sbTablas.ToString(), respuesta);
|
||||
|
||||
return respuesta;
|
||||
}
|
||||
|
||||
private string ConvertDataTableToHtml(DataTable table)
|
||||
{
|
||||
StringBuilder html = new StringBuilder();
|
||||
string ColumnaTitulo = "Titulo";
|
||||
html.Append("<table border='1' style='border-collapse:collapse; width:100%;'>");
|
||||
if(table.Columns[0].ColumnName==ColumnaTitulo && table.Rows.Count > 0) html.AppendFormat(" <caption style='background-color:#333333;'>{0}</caption>", table.Rows[0][ColumnaTitulo]);
|
||||
|
||||
html.Append("<thead style='background-color:#DDD; padding: 0px;'><tr>");
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
if (ColumnaTitulo != column.ColumnName) html.Append($"<th style='padding:5px; text-align:left;'>{column.ColumnName}</th>");
|
||||
}
|
||||
html.Append("</tr></thead>");
|
||||
|
||||
html.Append("<tbody>");
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
html.Append("<tr>");
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
if (ColumnaTitulo != column.ColumnName)
|
||||
{
|
||||
object value = row[column];
|
||||
string cellValue;
|
||||
if (column.DataType == typeof(int) || column.DataType == typeof(decimal) || column.DataType == typeof(double) || column.DataType == typeof(float))
|
||||
{
|
||||
if (value != DBNull.Value && decimal.TryParse(value.ToString(), out decimal numericValue))
|
||||
{
|
||||
if (numericValue != 0)
|
||||
{
|
||||
cellValue = numericValue.ToString("N2");
|
||||
}
|
||||
else
|
||||
{
|
||||
cellValue = "";//0.00
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cellValue = "";//0.00
|
||||
}
|
||||
html.Append($"<td style='padding:5px; text-align:right;'>{cellValue}</td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
cellValue = value?.ToString() ?? string.Empty;
|
||||
html.Append($"<td style='padding:5px; text-align:left;'>{cellValue}</td>");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
html.Append("</tr>");
|
||||
}
|
||||
html.Append("</tbody>");
|
||||
|
||||
// Cerrar la tabla
|
||||
html.Append("</table>");
|
||||
|
||||
return html.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//private string ConvertDataTableToHtml(DataTable table)
|
||||
//{
|
||||
// StringBuilder html = new StringBuilder();
|
||||
|
||||
// html.Append("<table border='1' style='border-collapse:collapse; width:100%;'>");
|
||||
|
||||
// html.Append("<thead><tr>");
|
||||
// foreach (DataColumn column in table.Columns)
|
||||
// {
|
||||
// html.Append($"<th style='padding:5px; text-align:left;'>{column.ColumnName}</th>");
|
||||
// }
|
||||
// html.Append("</tr></thead>");
|
||||
|
||||
|
||||
// html.Append("<tbody>");
|
||||
// foreach (DataRow row in table.Rows)
|
||||
// {
|
||||
// html.Append("<tr>");
|
||||
// foreach (DataColumn column in table.Columns)
|
||||
// {
|
||||
// html.Append($"<td style='padding:5px;'>{row[column]}</td>");
|
||||
// }
|
||||
// html.Append("</tr>");
|
||||
// }
|
||||
// html.Append("</tbody>");
|
||||
|
||||
|
||||
// html.Append("</table>");
|
||||
|
||||
// return html.ToString();
|
||||
//}
|
||||
|
||||
|
||||
private void MandaCorreo(string Cuerpo, bool PrceosoOK)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<ClsSisMail.ArchivoMail> ListaArchivos = new List<ClsSisMail.ArchivoMail>();
|
||||
ClsSisMail Correo = new ClsSisMail();
|
||||
//string Para = "julian@adssistemas.mx;rene.molina@adssistemas.mx;oscar.irigoyen@adssistemas.mx";
|
||||
|
||||
//string Para = "rene.molina@adssistemas.mx"; // oscar.irigoyen@adssistemas.mx;
|
||||
string Para = "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";
|
||||
|
||||
string Asunto = PrceosoOK ? $"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);
|
||||
this.GuardaLog($"EjecutaReporteDiario: MandaCorreo() correo enviado. ");
|
||||
|
||||
}catch(Exception ex)
|
||||
{
|
||||
Extensiones.ModExtensiones.GuardaLog(null,$"Error Tareas Programadas 119 error enviar mail --> {ex.Message} ");
|
||||
this.GuardaLog($"EjecutaReporteDiario: MandaCorreo() Error {ex.StackTrace.ToString()}. ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private Usuario ValidaUsuarioSistema(int CveUsuario, int CveEmpresa)
|
||||
{
|
||||
Usuario UsuarioActual = null/* TODO Change to default(_) if this is not a reference type */;
|
||||
|
||||
string NombreCadena = ClsPaginas.get_GlobalNombreCadenaConexion(CveEmpresa);
|
||||
ClsSisUsuarioAutenticacion ObjUsuarios = new ClsSisUsuarioAutenticacion(NombreCadena:NombreCadena);
|
||||
UsuarioActual = ObjUsuarios.GetUsuarioDetalle(CveUsuario);
|
||||
|
||||
if (UsuarioActual != null)
|
||||
{
|
||||
if( HttpContext.Current.Session == null)
|
||||
{
|
||||
// CrearHttpContextArtificial();
|
||||
CrearHttpContextConSession();
|
||||
}
|
||||
HttpContext.Current.Session["UsuarioSIG"] = UsuarioActual;
|
||||
}
|
||||
|
||||
ObjUsuarios.Dispose();
|
||||
return UsuarioActual;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void CrearHttpContextConSession()
|
||||
{
|
||||
//CrearHttpContextArtificial();
|
||||
|
||||
// Para agregar soporte de sesión, debemos inicializar el manejador de sesión
|
||||
var sessionContainer = new HttpSessionStateContainer("id",
|
||||
new SessionStateItemCollection(),
|
||||
new HttpStaticObjectsCollection(),
|
||||
10,
|
||||
true,
|
||||
HttpCookieMode.AutoDetect,
|
||||
SessionStateMode.InProc,
|
||||
false);
|
||||
|
||||
SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, sessionContainer);
|
||||
}
|
||||
|
||||
|
||||
private bool VerificarArchivo(FileInfo FInfo, long Tamanio, string FTPServer, string FTPUsr, string FTPPass)
|
||||
{
|
||||
bool Respuesta = false;
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
this.GuardaLog($"EjecutaThalamus: VerificarArchivo() conectando a FTP .");
|
||||
FtpWebRequest request = (FtpWebRequest)WebRequest.Create($"{FTPServer}/{FInfo.Name}");
|
||||
request.Credentials = new NetworkCredential(FTPUsr, FTPPass);
|
||||
request.Method = WebRequestMethods.Ftp.GetFileSize;
|
||||
request.UseBinary = true;
|
||||
FtpWebResponse loginresponse = (FtpWebResponse)request.GetResponse();
|
||||
FtpWebResponse respSize = (FtpWebResponse)request.GetResponse();
|
||||
respSize = (FtpWebResponse)request.GetResponse();
|
||||
long size = respSize.ContentLength;
|
||||
respSize.Close();
|
||||
|
||||
this.GuardaLog($"EjecutaThalamus: VerificarArchivo() tamaño local {Tamanio} ftp { size}. ");
|
||||
if (Tamanio == size)
|
||||
{
|
||||
Respuesta = true;
|
||||
this.GuardaLog($"EjecutaThalamus: VerificarArchivo() tamaño ok. ");
|
||||
}
|
||||
|
||||
}catch(Exception ex)
|
||||
{
|
||||
|
||||
Extensiones.ModExtensiones.GuardaLog(null,$"Error Tareas Programadas 119 verificando archivo { FInfo.Name } {ex.Message} ");
|
||||
this.GuardaLog($"EjecutaThalamus: VerificarArchivo() Error {ex.StackTrace.ToString()}. " );
|
||||
|
||||
Respuesta = false;
|
||||
}
|
||||
|
||||
return Respuesta;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public bool IsReusable
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user