Envio de ScoreCard E140
This commit is contained in:
@@ -8,9 +8,59 @@ Imports Newtonsoft.Json.Linq
|
|||||||
Imports Extensiones
|
Imports Extensiones
|
||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports CrystalDecisions.CrystalReports.Engine
|
Imports CrystalDecisions.CrystalReports.Engine
|
||||||
Imports CrystalDecisions.Shared
|
Imports CrystalDecisions.Shared
|
||||||
|
Imports Microsoft.Reporting.WebForms
|
||||||
|
|
||||||
Public Class TareasProgramadas : Implements IHttpHandler
|
Public Class TareasProgramadas : Implements IHttpHandler
|
||||||
|
|
||||||
|
|
||||||
|
Private ReadOnly Property GlobalDTUsuariosE140(Optional CveUsuario As Integer = -1, Optional CveCliente As Integer = -1, Optional CveProveedor As Integer = -1) As DataTable
|
||||||
|
Get
|
||||||
|
Dim CveEmpresa As Integer = 140
|
||||||
|
Dim Str As New StringBuilder
|
||||||
|
If CveUsuario <> -1 Then Str.AppendFormat("CveUsuario = {0}", CveUsuario)
|
||||||
|
If CveEmpresa <> -1 Then Str.AppendFormat(" {0} CveEmpresa = {1}", If(Str.Length > 0, "AND", ""), CveEmpresa)
|
||||||
|
If CveCliente <> -1 Then Str.AppendFormat(" {0} CveCliente = {1}", If(Str.Length > 0, "AND", ""), CveCliente)
|
||||||
|
If CveProveedor <> -1 Then Str.AppendFormat(" {0} CveProveedor = {1}", If(Str.Length > 0, "AND", ""), CveProveedor)
|
||||||
|
|
||||||
|
If CveUsuario <> -1 OrElse CveEmpresa <> -1 Then
|
||||||
|
Dim Dv As New DataView(DirectCast(HttpContext.Current.Application("GlobalDTUsuarios"), DataTable), Str.ToString, "", DataViewRowState.CurrentRows)
|
||||||
|
GlobalDTUsuariosE140 = Dv.ToTable
|
||||||
|
Dv.Dispose()
|
||||||
|
Else
|
||||||
|
GlobalDTUsuariosE140 = DirectCast(HttpContext.Current.Application("GlobalDTUsuarios"), DataTable)
|
||||||
|
End If
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
|
Public Shared ReadOnly Property GlobalDTSubProyectosE140(CveProyecto As Integer, Optional CveSubProyecto As Integer = -1, Optional Estatus As Integer = 1) As DataTable
|
||||||
|
Get
|
||||||
|
Dim CveEmpresa As Integer = 140
|
||||||
|
Dim AppNombre As String = String.Format("GlobalDTSubProyectos-{0}", CveEmpresa)
|
||||||
|
'sino existe, recarga los datos
|
||||||
|
If DirectCast(HttpContext.Current.Application(AppNombre), DataTable) Is Nothing Or (DirectCast(HttpContext.Current.Application(AppNombre), DataTable) IsNot Nothing AndAlso DirectCast(HttpContext.Current.Application(AppNombre), DataTable).Rows.Count = 0) Then
|
||||||
|
Dim P As New ClsSubProyectos
|
||||||
|
If P.GetSubProyectos(CveEmpresa:=CveEmpresa) Then HttpContext.Current.Application(AppNombre) = P.DtResultados
|
||||||
|
P.Dispose()
|
||||||
|
End If
|
||||||
|
|
||||||
|
If CveProyecto <> -1 OrElse CveSubProyecto <> -1 OrElse CveEmpresa <> -1 OrElse Estatus <> -1 Then
|
||||||
|
Dim StrSQL As New StringBuilder
|
||||||
|
If CveProyecto <> -1 Then StrSQL.AppendFormat(" AND CveProyecto = {0}", CveProyecto)
|
||||||
|
If CveSubProyecto <> -1 Then StrSQL.AppendFormat(" AND CveSubProyecto = {0}", CveSubProyecto)
|
||||||
|
If Estatus <> -1 Then StrSQL.AppendFormat(" AND CveEstatus = {0}", Estatus)
|
||||||
|
If CveEmpresa <> -1 Then StrSQL.AppendFormat(" AND CveEmpresa = {0}", CveEmpresa)
|
||||||
|
|
||||||
|
Dim Dv As New DataView(DirectCast(HttpContext.Current.Application(AppNombre), DataTable), StrSQL.ToString.Trim.TrimStart("A"c, "N"c, "D"c), "", DataViewRowState.CurrentRows)
|
||||||
|
GlobalDTSubProyectosE140 = Dv.ToTable
|
||||||
|
Dv.Dispose()
|
||||||
|
|
||||||
|
Else
|
||||||
|
GlobalDTSubProyectosE140 = DirectCast(HttpContext.Current.Application(AppNombre), DataTable)
|
||||||
|
End If
|
||||||
|
|
||||||
|
End Get
|
||||||
|
End Property
|
||||||
|
|
||||||
Private currentcontext As HttpContext
|
Private currentcontext As HttpContext
|
||||||
Private URLParametros As New Hashtable
|
Private URLParametros As New Hashtable
|
||||||
@@ -51,7 +101,10 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
|||||||
context.Response.Write(retorno)
|
context.Response.Write(retorno)
|
||||||
Case "EstadosCuenta"
|
Case "EstadosCuenta"
|
||||||
'CargaEstadosCuenta(context, 119, 227774)
|
'CargaEstadosCuenta(context, 119, 227774)
|
||||||
CargaEstadosCuenta(context, 119, -1, FechaEnvio, FechaActual)
|
CargaEstadosCuenta(context, 119, -1, FechaEnvio, FechaActual)
|
||||||
|
|
||||||
|
Case "ScoreCard"
|
||||||
|
CargaScoreCard(context, 140, FechaEnvio)
|
||||||
End Select
|
End Select
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
ex.GuardaLog(ex.ToString())
|
ex.GuardaLog(ex.ToString())
|
||||||
@@ -843,4 +896,430 @@ Public Class TareasProgramadas : Implements IHttpHandler
|
|||||||
End Sub
|
End Sub
|
||||||
#End Region
|
#End Region
|
||||||
|
|
||||||
|
#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 = ValidaUsuarioSistema(pCveEmpresa)
|
||||||
|
Dim obj = EjecutarEnvioScoreCard(Usuario, FechaEnvio)
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Function EjecutarEnvioScoreCard(UsuarioActual As Usuario, FechaEnvio As DateTime) As Boolean
|
||||||
|
Dim DtGrupoVendedores As DataTable = Nothing
|
||||||
|
Dim DtGrupoSucursales As DataTable = Nothing
|
||||||
|
Dim DtGrupoEmpresa As DataTable = Nothing
|
||||||
|
|
||||||
|
Using ObjVentas As New ClsVentas
|
||||||
|
'VENDEDORES
|
||||||
|
If ObjVentas.GetRepMetasVendedores(FechaEnvio, UsuarioActual.CveEmpresa, -1, -1,
|
||||||
|
-1, -1, -1,
|
||||||
|
-1, -1, GrupoSuperior:=0) Then
|
||||||
|
DtGrupoVendedores = ObjVentas.DtResultados.Copy
|
||||||
|
End If
|
||||||
|
'SUCURSAL
|
||||||
|
If ObjVentas.GetRepMetasVendedores(FechaEnvio, UsuarioActual.CveEmpresa, -1, -1,
|
||||||
|
-1, -1, -1,
|
||||||
|
-1, -1, GrupoSuperior:=1) Then
|
||||||
|
DtGrupoSucursales = ObjVentas.DtResultados.Copy
|
||||||
|
End If
|
||||||
|
'EMPRESA
|
||||||
|
If ObjVentas.GetRepMetasVendedores(FechaEnvio, UsuarioActual.CveEmpresa, -1, -1,
|
||||||
|
-1, -1, -1,
|
||||||
|
-1, -1, GrupoSuperior:=2) Then
|
||||||
|
DtGrupoEmpresa = ObjVentas.DtResultados.Copy
|
||||||
|
End If
|
||||||
|
End Using
|
||||||
|
|
||||||
|
Dim DtUsuarios As DataTable = GlobalDTUsuariosE140()
|
||||||
|
|
||||||
|
Dim ListaDirectivos As New List(Of MUsuarioEnviar)
|
||||||
|
'OSCAR FERNANDO LOPEZ CARRASCO
|
||||||
|
ListaDirectivos.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {2138}"), TipoUsuarioEnviar.Directivo) With
|
||||||
|
{
|
||||||
|
.SubProyecto = "Todos",
|
||||||
|
.ReporteEnviar = New MReporteEnviar() With
|
||||||
|
{
|
||||||
|
.Empresa = True, .Sucursal = True, .Vendedor = True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
'ANA IVETTE LOPEZ CARRASCO
|
||||||
|
ListaDirectivos.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {2292}"), TipoUsuarioEnviar.Directivo) With
|
||||||
|
{
|
||||||
|
.SubProyecto = "Todos",
|
||||||
|
.ReporteEnviar = New MReporteEnviar() With
|
||||||
|
{
|
||||||
|
.Empresa = True, .Sucursal = True, .Vendedor = True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
'FERNANDO MENDOZA LAMADRID
|
||||||
|
ListaDirectivos.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {2275}"), TipoUsuarioEnviar.Directivo) With
|
||||||
|
{
|
||||||
|
.SubProyecto = "Todos",
|
||||||
|
.ReporteEnviar = New MReporteEnviar() With
|
||||||
|
{
|
||||||
|
.Empresa = True, .Sucursal = True, .Vendedor = True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
'CARLOS ARMANDO MORENO GONZALEZ
|
||||||
|
ListaDirectivos.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {2763}"), TipoUsuarioEnviar.Directivo) With
|
||||||
|
{
|
||||||
|
.SubProyecto = "Todos",
|
||||||
|
.ReporteEnviar = New MReporteEnviar() With
|
||||||
|
{
|
||||||
|
.Empresa = True, .Sucursal = True, .Vendedor = True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
'EMMANUEL LOPEZ FIMBRES
|
||||||
|
ListaDirectivos.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3099}"), TipoUsuarioEnviar.Directivo) With
|
||||||
|
{
|
||||||
|
.SubProyecto = "Todos",
|
||||||
|
.ReporteEnviar = New MReporteEnviar() With
|
||||||
|
{
|
||||||
|
.Empresa = True, .Sucursal = True, .Vendedor = True
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
Dim PDFEmpresa As Byte() = GenerarScoredCardDirectivo(UsuarioActual, DtGrupoEmpresa)
|
||||||
|
Dim PDFSucursales As Byte() = GenerarScoredCardDirectivo(UsuarioActual, DtGrupoSucursales)
|
||||||
|
Dim PDFVendedores As Byte() = GenerarScoredCardDirectivo(UsuarioActual, DtGrupoVendedores)
|
||||||
|
|
||||||
|
For Each UsuarioEnviar In ListaDirectivos
|
||||||
|
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
|
||||||
|
|
||||||
|
If UsuarioEnviar.ReporteEnviar.Empresa Then
|
||||||
|
LSRutasMail.Add(New ClsSisMail.ArchivoMail With
|
||||||
|
{
|
||||||
|
.ArchivoBinario = PDFEmpresa,
|
||||||
|
.NombreArchivo = "ScoreCardEmpresa.pdf"
|
||||||
|
})
|
||||||
|
End If
|
||||||
|
|
||||||
|
If UsuarioEnviar.ReporteEnviar.Sucursal Then
|
||||||
|
LSRutasMail.Add(New ClsSisMail.ArchivoMail With
|
||||||
|
{
|
||||||
|
.ArchivoBinario = PDFSucursales,
|
||||||
|
.NombreArchivo = "ScoreCardSucursales.pdf"
|
||||||
|
})
|
||||||
|
End If
|
||||||
|
|
||||||
|
If UsuarioEnviar.ReporteEnviar.Vendedor Then
|
||||||
|
LSRutasMail.Add(New ClsSisMail.ArchivoMail With
|
||||||
|
{
|
||||||
|
.ArchivoBinario = PDFVendedores,
|
||||||
|
.NombreArchivo = "ScoreCardVendedores.pdf"
|
||||||
|
})
|
||||||
|
End If
|
||||||
|
|
||||||
|
If LSRutasMail.Count > 0 Then
|
||||||
|
EnviarCorreoFactura(UsuarioActual, UsuarioEnviar, LSRutasMail)
|
||||||
|
End If
|
||||||
|
|
||||||
|
Next
|
||||||
|
|
||||||
|
Dim ListaVendedores As New List(Of MUsuarioEnviar)
|
||||||
|
'LUIS FERNADO GRIJALVA COTA
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3236} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
'FERNANDO GRIJALVA
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3293} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
'ADRIAN MURRIETA
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3352} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
'BRAYAM URIEL CORRALES
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {2700} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
'DANIEL GASTELUM
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3360} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
'ALEJANDRA QUINTERO
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3336} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
'RICARDO FUENTES
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3363} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
'GERMAN LUNA
|
||||||
|
ListaVendedores.Add(New MUsuarioEnviar(DtUsuarios.FiltroPrimero($"CveUsuario = {3354} AND CveSubProyecto > 0"), TipoUsuarioEnviar.Vendedor))
|
||||||
|
|
||||||
|
For Each UsuarioEnviar In ListaVendedores
|
||||||
|
Dim LSRutasMail As New List(Of ClsSisMail.ArchivoMail)
|
||||||
|
Dim DtReporteVendedor As DataTable = Nothing
|
||||||
|
|
||||||
|
If UsuarioEnviar.CveSubProyecto > 0 AndAlso UsuarioEnviar.CveVendedor > 0 Then
|
||||||
|
|
||||||
|
Using ObjVentas As New ClsVentas
|
||||||
|
If ObjVentas.GetRepMetasVendedores(FechaEnvio, UsuarioActual.CveEmpresa, UsuarioEnviar.CveVendedor, -1,
|
||||||
|
-1, -1, -1, UsuarioEnviar.CveSubProyecto, -1, GrupoSuperior:=1) Then
|
||||||
|
DtReporteVendedor = ObjVentas.DtResultados.Copy
|
||||||
|
End If
|
||||||
|
End Using
|
||||||
|
|
||||||
|
LSRutasMail.Add(New ClsSisMail.ArchivoMail With
|
||||||
|
{
|
||||||
|
.ArchivoBinario = GenerarScoredCard(UsuarioActual, UsuarioEnviar, DtReporteVendedor),
|
||||||
|
.NombreArchivo = "ScoreCardSucursales.pdf"
|
||||||
|
})
|
||||||
|
|
||||||
|
If LSRutasMail.Count > 0 Then
|
||||||
|
EnviarCorreoFactura(UsuarioActual, UsuarioEnviar, LSRutasMail)
|
||||||
|
End If
|
||||||
|
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
|
||||||
|
Return False
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Sub EnviarCorreoFactura(UsuarioActual As Usuario, UsuarioEnviar As MUsuarioEnviar, LSRutasMail As List(Of ClsSisMail.ArchivoMail))
|
||||||
|
Dim ObjMail As New ClsSisMail()
|
||||||
|
Dim Mail As String = "jonathan.perez@adssistemas.mx"
|
||||||
|
Dim MailCC As String = "rene.molina@adssistemas.mx"
|
||||||
|
|
||||||
|
Dim ExistePDF As Boolean = False
|
||||||
|
|
||||||
|
If Not String.IsNullOrEmpty(Mail) Then
|
||||||
|
Try
|
||||||
|
Dim Asunto As String = $"ScoreCard: {Now.ToString("dd/MM/yyyy")}"
|
||||||
|
Dim Cuerpo As String = String.Empty
|
||||||
|
Dim ResultadoMail As Integer = 0
|
||||||
|
|
||||||
|
If ObjMail.SendMail(ClsPaginas.EmpresaNotificaciones, Mail, Asunto, Cuerpo, If(String.IsNullOrEmpty(MailCC), "", MailCC), LSRutasMail) Then
|
||||||
|
ResultadoMail = 1
|
||||||
|
End If
|
||||||
|
|
||||||
|
Catch ex As Exception
|
||||||
|
OnError("Ocurrió error al mandar el Mail", ex)
|
||||||
|
End Try
|
||||||
|
End If
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Protected Function GenerarScoredCard(UsuarioActual As Usuario, UsuarioEnviar As MUsuarioEnviar, DtDatos As DataTable) As Byte()
|
||||||
|
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta))
|
||||||
|
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port, UsuarioActual.CveEmpresa)
|
||||||
|
|
||||||
|
Dim params As New List(Of ReportParameter)
|
||||||
|
params.Add(New ReportParameter("pEmp", UsuarioActual.Empresa.Empresa))
|
||||||
|
If Imagen.Exists Then
|
||||||
|
params.Add(New ReportParameter("pImg", logouri))
|
||||||
|
Else
|
||||||
|
params.Add(New ReportParameter("pImg", ""))
|
||||||
|
End If
|
||||||
|
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario))
|
||||||
|
params.Add(New ReportParameter("FechaImpresion", Today))
|
||||||
|
params.Add(New ReportParameter("SubProyecto", UsuarioEnviar.SubProyecto))
|
||||||
|
params.Add(New ReportParameter("Agente", UsuarioEnviar.Agente))
|
||||||
|
|
||||||
|
|
||||||
|
Dim lrds As New List(Of ReportDataSource)
|
||||||
|
Dim rds As New ReportDataSource
|
||||||
|
rds.Name = "DataSet1"
|
||||||
|
rds.Value = DtDatos
|
||||||
|
lrds.Add(rds)
|
||||||
|
|
||||||
|
Return StreamPDF(UsuarioActual, "Empresas/Grales/Formatos/MetasVendedores.rdlc", lrds, params, "Rep. Metas por vendedores", "PDF")
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Protected Function GenerarScoredCardDirectivo(UsuarioActual As Usuario, DtDatos As DataTable) As Byte()
|
||||||
|
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", UsuarioActual.Empresa.Ruta))
|
||||||
|
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", HttpContext.Current.Request.Url.Scheme, HttpContext.Current.Request.Url.Host, HttpContext.Current.Request.Url.Port, UsuarioActual.CveEmpresa)
|
||||||
|
|
||||||
|
Dim params As New List(Of ReportParameter)
|
||||||
|
params.Add(New ReportParameter("pEmp", UsuarioActual.Empresa.Empresa))
|
||||||
|
If Imagen.Exists Then
|
||||||
|
params.Add(New ReportParameter("pImg", logouri))
|
||||||
|
Else
|
||||||
|
params.Add(New ReportParameter("pImg", ""))
|
||||||
|
End If
|
||||||
|
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Usuario))
|
||||||
|
params.Add(New ReportParameter("FechaImpresion", Today))
|
||||||
|
params.Add(New ReportParameter("SubProyecto", "Todos"))
|
||||||
|
params.Add(New ReportParameter("Agente", "Todos"))
|
||||||
|
|
||||||
|
|
||||||
|
Dim lrds As New List(Of ReportDataSource)
|
||||||
|
Dim rds As New ReportDataSource
|
||||||
|
rds.Name = "DataSet1"
|
||||||
|
rds.Value = DtDatos
|
||||||
|
lrds.Add(rds)
|
||||||
|
|
||||||
|
Return StreamPDF(UsuarioActual, "Empresas/Grales/Formatos/MetasVendedores.rdlc", lrds, params, "Rep. Metas por vendedores", "PDF")
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Enum TipoUsuarioEnviar
|
||||||
|
Directivo
|
||||||
|
Vendedor
|
||||||
|
End Enum
|
||||||
|
|
||||||
|
Public Class MUsuarioEnviar
|
||||||
|
|
||||||
|
Sub New(RowUsuario As DataRow, Tipo As TipoUsuarioEnviar)
|
||||||
|
If RowUsuario IsNot Nothing Then
|
||||||
|
Me.CveUsuario = RowUsuario("CveUsuario").ToString().ToEntero()
|
||||||
|
Me.Nombre = RowUsuario("Nombre").ToString()
|
||||||
|
Me.Correo = RowUsuario("Correo").ToString()
|
||||||
|
Me.CveSubProyecto = RowUsuario("CveSubProyecto").ToString().ToEntero()
|
||||||
|
Me.CveVendedor = RowUsuario("CveVendedor").ToString().ToEntero()
|
||||||
|
Me.Tipo = Tipo
|
||||||
|
|
||||||
|
If Me.Tipo = TipoUsuarioEnviar.Vendedor Then
|
||||||
|
Me.Agente = Me.Nombre
|
||||||
|
Else
|
||||||
|
Me.Agente = "Todos"
|
||||||
|
End If
|
||||||
|
|
||||||
|
If String.IsNullOrEmpty(SubProyecto) AndAlso CveSubProyecto > 0 Then
|
||||||
|
Me.SubProyecto = GlobalDTSubProyectosE140(-1, CveSubProyecto:=Me.CveSubProyecto).FiltroPrimeroValor("SubProyecto")
|
||||||
|
End If
|
||||||
|
End If
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Property CveUsuario As Integer
|
||||||
|
Public Property Nombre As String
|
||||||
|
Public Property Tipo As TipoUsuarioEnviar
|
||||||
|
Public Property ReporteEnviar As MReporteEnviar
|
||||||
|
Public Property CveSubProyecto As Integer
|
||||||
|
Public Property SubProyecto As String
|
||||||
|
Public Property Correo As String
|
||||||
|
Public Property CveVendedor As Integer
|
||||||
|
Public Property Agente As String
|
||||||
|
|
||||||
|
End Class
|
||||||
|
|
||||||
|
Public Class MReporteEnviar
|
||||||
|
Public Property Empresa As Boolean = False
|
||||||
|
Public Property Sucursal As Boolean = False
|
||||||
|
Public Property Vendedor As Boolean = False
|
||||||
|
End Class
|
||||||
|
|
||||||
|
Public Function StreamPDF(UsuarioActual As Usuario, RutaReporte As String, DataSource As List(Of ReportDataSource), Parametros As List(Of ReportParameter), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional MR As ReportViewer = Nothing) As Byte()
|
||||||
|
'limpio ReportViwer
|
||||||
|
Dim sw As New System.Diagnostics.Stopwatch()
|
||||||
|
sw.Start()
|
||||||
|
Dim Bytes As Byte() = Nothing
|
||||||
|
|
||||||
|
Dim CveUsuario As Integer = 0
|
||||||
|
Dim CveEmpresa As Integer = 0
|
||||||
|
Dim RutaEmpresa As String = ""
|
||||||
|
|
||||||
|
If UsuarioActual IsNot Nothing Then
|
||||||
|
CveUsuario = UsuarioActual.CveUsuario
|
||||||
|
CveEmpresa = UsuarioActual.CveEmpresa
|
||||||
|
RutaEmpresa = UsuarioActual.Empresa.RutaArchivos
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim bdir As String = If(RutaReporte.Contains("Empresas"), ModExtensiones.DirectorioBaseEmpresas, AppDomain.CurrentDomain.BaseDirectory)
|
||||||
|
|
||||||
|
'TOMAR LA RUTA BASE PARA EL DIRECTORIO DE LA EMPRESA
|
||||||
|
If Not String.IsNullOrEmpty(RutaEmpresa) AndAlso Not RutaReporte.Contains("Grales") Then
|
||||||
|
bdir = RutaEmpresa.Replace($"{CveEmpresa}/", "")
|
||||||
|
End If
|
||||||
|
|
||||||
|
RutaReporte.Replace("/", "\")
|
||||||
|
|
||||||
|
If Not RutaReporte.ToUpper().StartsWith(bdir.ToUpper()) Then
|
||||||
|
RutaReporte = String.Format("{0}{1}", bdir, RutaReporte)
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim EsProduccion As Boolean = UsuarioActual.Empresa.FacturaProduccion
|
||||||
|
|
||||||
|
If EsProduccion Then
|
||||||
|
|
||||||
|
Dim wsreport As New WSRDLC.WebServiceSoapClient
|
||||||
|
Dim params As New List(Of WSRDLC.ReportParameter)
|
||||||
|
Dim ds As New DataSet
|
||||||
|
For Each rpds As ReportDataSource In DataSource
|
||||||
|
Dim dt As DataTable = DirectCast(rpds.Value, Data.DataTable)
|
||||||
|
If dt Is Nothing Then
|
||||||
|
dt = New DataTable()
|
||||||
|
Else
|
||||||
|
dt = dt.Copy()
|
||||||
|
End If
|
||||||
|
dt.TableName = rpds.Name
|
||||||
|
ds.Tables.Add(dt)
|
||||||
|
Next
|
||||||
|
For Each rpds As ReportParameter In Parametros
|
||||||
|
Dim param As New WSRDLC.ReportParameter
|
||||||
|
param.Name = rpds.Name
|
||||||
|
param.Values = {rpds.Values(0)}
|
||||||
|
params.Add(param)
|
||||||
|
Next
|
||||||
|
Bytes = wsreport.StreamPDFBytes(RutaReporte, ds, params.ToArray(), NombreArchivo, Formato, CveEmpresa, CveUsuario)
|
||||||
|
wsreport = Nothing
|
||||||
|
params = Nothing
|
||||||
|
ds.Dispose() : ds = Nothing
|
||||||
|
Else
|
||||||
|
If IsNothing(MR) Then MR = New ReportViewer
|
||||||
|
Try
|
||||||
|
' MasterReporteador.LocalReport.DataSources.Clear()
|
||||||
|
For Each RDS As ReportDataSource In DataSource
|
||||||
|
MR.LocalReport.DataSources.Add(RDS)
|
||||||
|
Next
|
||||||
|
|
||||||
|
MR.LocalReport.ReportPath = RutaReporte
|
||||||
|
MR.ProcessingMode = ProcessingMode.Local
|
||||||
|
MR.LocalReport.EnableExternalImages = True
|
||||||
|
MR.LocalReport.SetParameters(Parametros)
|
||||||
|
MR.LocalReport.Refresh()
|
||||||
|
Dim Warnings As Warning() = Nothing
|
||||||
|
Dim StreamIds As String() = Nothing
|
||||||
|
Dim MimeType As String = Nothing
|
||||||
|
Dim Encoding As String = Nothing
|
||||||
|
Dim Extension As String = Nothing
|
||||||
|
Bytes = MR.LocalReport.Render(Formato, Nothing, MimeType, Encoding, Extension, StreamIds, Warnings)
|
||||||
|
Catch ex As Microsoft.Reporting.WebForms.ScriptManagerNotFoundException
|
||||||
|
GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}")
|
||||||
|
'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017
|
||||||
|
'GuardaLog($"Error: {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}")
|
||||||
|
Catch ex As Exception
|
||||||
|
GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}")
|
||||||
|
'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017
|
||||||
|
'GuardaLog($"Error {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}")
|
||||||
|
End Try
|
||||||
|
MR.Dispose()
|
||||||
|
MR = Nothing
|
||||||
|
'Dim ruta = wsreport.StreamPDF(RutaReporte, ds, params.ToArray(), NombreArchivo, Formato, CveEmpresa, CveUsuario)
|
||||||
|
'If File.Exists(ruta) Then
|
||||||
|
' Bytes = File.ReadAllBytes(ruta)
|
||||||
|
' File.Delete(ruta)
|
||||||
|
'End If
|
||||||
|
'Dim setup As AppDomainSetup = New AppDomainSetup
|
||||||
|
'With setup
|
||||||
|
' .ApplicationBase = Environment.CurrentDirectory
|
||||||
|
' .LoaderOptimization = LoaderOptimization.MultiDomainHost
|
||||||
|
'End With
|
||||||
|
'setup.SetCompatibilitySwitches({"NetFx40_LegacySecurityPolicy"})
|
||||||
|
'Dim _casPolicyEnabledDomain As AppDomain = AppDomain.CreateDomain("Full Trust", Nothing, setup)
|
||||||
|
'Dim fllreport As ADSReportLib.FullTrustReportviewer = Nothing
|
||||||
|
'Try
|
||||||
|
|
||||||
|
' fllreport = CType(_casPolicyEnabledDomain.CreateInstanceFromAndUnwrap(GetType(ADSReportLib.FullTrustReportviewer).Assembly.CodeBase, GetType(ADSReportLib.FullTrustReportviewer).FullName), ADSReportLib.FullTrustReportviewer)
|
||||||
|
|
||||||
|
' fllreport.Initialize("DisplayName", RutaReporte, Parametros.AsEnumerable(), New List(Of String()), True)
|
||||||
|
' For Each RDS As ReportDataSource In DataSource
|
||||||
|
' fllreport.AddDataSources(RDS.Name, DirectCast(RDS.Value, DataTable))
|
||||||
|
' Next
|
||||||
|
' Dim Warnings As Warning() = Nothing
|
||||||
|
' Dim StreamIds As String() = Nothing
|
||||||
|
' Dim MimeType As String = Nothing
|
||||||
|
' Dim Encoding As String = Nothing
|
||||||
|
' Dim Extension As String = Nothing
|
||||||
|
' Bytes = fllreport.Render(Formato, Nothing, MimeType, Encoding, Extension, StreamIds)
|
||||||
|
' fllreport = Nothing
|
||||||
|
'Catch ex As Microsoft.Reporting.WebForms.ScriptManagerNotFoundException
|
||||||
|
' GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}")
|
||||||
|
' 'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017
|
||||||
|
' 'GuardaLog($"Error: {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}")
|
||||||
|
'Catch ex As Exception
|
||||||
|
' GuardaLog($"Error: { If(ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, ex.Message) } | Descripcion: {If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException IsNot Nothing AndAlso ex.InnerException.InnerException.Message IsNot Nothing, ex.InnerException.InnerException.Message, If(ex.InnerException IsNot Nothing AndAlso ex.InnerException.Message IsNot Nothing, ex.InnerException.Message, "Sin descripcion"))} - Ruta {RutaReporte}")
|
||||||
|
' 'HAY QUE VALIDAR QUE LOS OBJETOS QUE SE USAN PARA GUARDAR LOG EXISTEN!!! IPP 14 AGOSTO 2017
|
||||||
|
' 'GuardaLog($"Error {ex.InnerException.Message} | Descripcion: {If(ex.InnerException.InnerException IsNot Nothing, ex.InnerException.InnerException.Message, "Sin descripcion")} - Ruta {RutaReporte}")
|
||||||
|
'Finally
|
||||||
|
' AppDomain.Unload(_casPolicyEnabledDomain)
|
||||||
|
'End Try
|
||||||
|
'If fllreport IsNot Nothing Then fllreport.liberarecursos()
|
||||||
|
|
||||||
|
End If
|
||||||
|
sw.Stop()
|
||||||
|
|
||||||
|
If sw.Elapsed.TotalSeconds > 5 Then
|
||||||
|
GuardaLog($"Reporte:{RutaReporte} | Tiempo Renderizado Milisegundos: {sw.ElapsedMilliseconds},Total Segundos: {sw.Elapsed.TotalSeconds} ")
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return Bytes
|
||||||
|
End Function
|
||||||
|
#End Region
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
Reference in New Issue
Block a user