diff --git a/Ashx/TareasProgramadas.ashx b/Ashx/TareasProgramadas.ashx
index 11eaff1b9..d93f99402 100644
--- a/Ashx/TareasProgramadas.ashx
+++ b/Ashx/TareasProgramadas.ashx
@@ -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
\ No newline at end of file
+#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($"
Reporte Diario {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}
")
+
+ 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("
")
+ sbTablas.Append("
")
+ 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("")
+ If table.Columns(0).ColumnName = ColumnaTitulo AndAlso table.Rows.Count > 0 Then html.AppendFormat(" {0}", table.Rows(0)(ColumnaTitulo))
+ html.Append("")
+
+ For Each column As DataColumn In table.Columns
+ If ColumnaTitulo <> column.ColumnName Then html.Append($"| {column.ColumnName} | ")
+ Next
+
+ html.Append("
")
+ html.Append("")
+ Dim numericValue As Decimal = Nothing
+
+ For Each row As DataRow In table.Rows
+ html.Append("")
+
+ 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($"| {cellValue} | ")
+ Else
+ cellValue = If(value?.ToString(), String.Empty)
+ html.Append($"{cellValue} | ")
+ End If
+ End If
+ Next
+
+ html.Append("
")
+ Next
+
+ html.Append("")
+ html.Append("
")
+ 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
+
\ No newline at end of file
diff --git a/TareasProgramadas/TareasReporteDiario.ashx b/TareasProgramadas/TareasReporteDiario.ashx
deleted file mode 100644
index 2e0b676eb..000000000
--- a/TareasProgramadas/TareasReporteDiario.ashx
+++ /dev/null
@@ -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($"Reporte Diario {DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss")}
");
-
- if (objGenerales.GetReporteDiario(CveEmpresa))
- {
- int TablaActual = 1;
- foreach (DataTable tabla in objGenerales.DSResultados.Tables)
- {
- sbTablas.AppendLine(ConvertDataTableToHtml(tabla));
- TablaActual++;
- sbTablas.Append("
");
- sbTablas.Append("
");
- }
- }
- 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("");
- if(table.Columns[0].ColumnName==ColumnaTitulo && table.Rows.Count > 0) html.AppendFormat(" {0}", table.Rows[0][ColumnaTitulo]);
-
- html.Append("");
- foreach (DataColumn column in table.Columns)
- {
- if (ColumnaTitulo != column.ColumnName) html.Append($"| {column.ColumnName} | ");
- }
- html.Append("
");
-
- html.Append("");
- foreach (DataRow row in table.Rows)
- {
- html.Append("");
- 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($"| {cellValue} | ");
- }
- else
- {
- cellValue = value?.ToString() ?? string.Empty;
- html.Append($"{cellValue} | ");
- }
- }
-
- }
- html.Append("
");
- }
- html.Append("");
-
- // Cerrar la tabla
- html.Append("
");
-
- return html.ToString();
- }
-
-
-
-
- //private string ConvertDataTableToHtml(DataTable table)
- //{
- // StringBuilder html = new StringBuilder();
-
- // html.Append("");
-
- // html.Append("");
- // foreach (DataColumn column in table.Columns)
- // {
- // html.Append($"| {column.ColumnName} | ");
- // }
- // html.Append("
");
-
-
- // html.Append("");
- // foreach (DataRow row in table.Rows)
- // {
- // html.Append("");
- // foreach (DataColumn column in table.Columns)
- // {
- // html.Append($"| {row[column]} | ");
- // }
- // html.Append("
");
- // }
- // html.Append("");
-
-
- // html.Append("
");
-
- // return html.ToString();
- //}
-
-
- private void MandaCorreo(string Cuerpo, bool PrceosoOK)
- {
- try
- {
- List ListaArchivos = new List();
- 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; }
- }
-
-}
\ No newline at end of file