Files
SIG/RH/RepPersonalInconsistencias.aspx.vb
2023-10-09 11:55:07 -07:00

367 lines
13 KiB
VB.net

Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.SqlClient
Imports Extensiones
Imports Microsoft.Reporting.WebForms
Partial Class RH_RepPersonalInconsistencias
Inherits ClsPaginas
Private Property Gvi As Integer
Get
Return ViewState("Gvi").ToString.ToEntero
End Get
Set(value As Integer)
ViewState("Gvi") = value
End Set
End Property
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
ViewState("Gvi") = -1
ViewState("Orden0") = ""
ViewState("Orden1") = ""
ViewState("Orden2") = ""
DT1 = New DataTable
DT2 = New DataTable
DT3 = New DataTable
CargaDatos()
End If
End Sub
Private Property DT1 As DataTable
Get
Return DirectCast(ViewState("DT1"), DataTable)
End Get
Set(value As DataTable)
ViewState("DT1") = value
End Set
End Property
Private Property DT2 As DataTable
Get
Return DirectCast(ViewState("DT2"), DataTable)
End Get
Set(value As DataTable)
ViewState("DT2") = value
End Set
End Property
Private Property DT3 As DataTable
Get
Return DirectCast(ViewState("DT3"), DataTable)
End Get
Set(value As DataTable)
ViewState("DT3") = value
End Set
End Property
Protected Sub CargaGrid(Orden As String, gvi As Integer)
Dim DV As DataView = Nothing
If gvi = 0 Then
ViewState("Orden0") = Orden
DV = New DataView(CType(ViewState("DTContenido0"), DataTable), "", Orden, DataViewRowState.CurrentRows)
If Orden <> String.Empty Then
GV.DataSource = DV.ToTable()
GV.DataBind()
Else
GV.DataSource = CType(ViewState("DTContenido0"), DataTable)
End If
ElseIf gvi = 1 Then
ViewState("Orden1") = Orden
DV = New DataView(CType(ViewState("DTContenido1"), DataTable), "", Orden, DataViewRowState.CurrentRows)
If Orden <> String.Empty Then
GV1.DataSource = DV.ToTable()
GV1.DataBind()
Else
GV1.DataSource = CType(ViewState("DTContenido1"), DataTable)
End If
ElseIf gvi = 2 Then
ViewState("Orden2") = Orden
DV = New DataView(CType(ViewState("DTContenido2"), DataTable), "", Orden, DataViewRowState.CurrentRows)
If Orden <> String.Empty Then
GV2.DataSource = DV.ToTable()
GV2.DataBind()
Else
GV2.DataSource = CType(ViewState("DTContenido2"), DataTable)
End If
End If
DV.Dispose()
UpDatos.Update()
End Sub
Protected Sub CargaGrid(orden As String)
Dim DV As New DataView(CType(ViewState("DTContenido0"), DataTable), "", orden, DataViewRowState.CurrentRows)
If Orden <> String.Empty Then
GV.DataSource = DV.ToTable()
Else
GV.DataSource = CType(ViewState("DTContenido0"), DataTable)
End If
GV.DataBind()
DV = New DataView(CType(ViewState("DTContenido1"), DataTable), "", orden, DataViewRowState.CurrentRows)
If orden <> String.Empty Then
GV1.DataSource = DV.ToTable()
Else
GV1.DataSource = CType(ViewState("DTContenido1"), DataTable)
End If
GV1.DataBind()
DV = New DataView(CType(ViewState("DTContenido2"), DataTable), "", orden, DataViewRowState.CurrentRows)
If orden <> String.Empty Then
GV2.DataSource = DV.ToTable()
Else
GV2.DataSource = CType(ViewState("DTContenido2"), DataTable)
End If
GV2.DataBind()
UpDatos.Update()
DV.Dispose()
End Sub
Protected Sub GV_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GV.RowDataBound, GV1.RowDataBound, GV2.RowDataBound
If e.Row.RowIndex > 0 Then
e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
End If
End Sub
Protected Sub CargaDatos()
Using ObjAnomalias As New ClsRH
If ObjAnomalias.GetRepPersonalInconsistencias(UsuarioActual.CveEmpresa.ToEntero) Then
'DSContratosProximosAVencer = ObjAnomalias.DtResultados
'DSContratosProximosAVencer.Tables.Add(ObjAnomalias.DSResultados().Tables(0))
'DSContratosProximosAVencer.Tables.Add(ObjAnomalias.DSResultados().Tables(1))
'DSContratosProximosAVencer.Tables.Add(ObjAnomalias.DSResultados().Tables(2))
ViewState("DTContenido0") = ObjAnomalias.DSResultados().Tables(0)
ViewState("DTContenido1") = ObjAnomalias.DSResultados().Tables(1)
ViewState("DTContenido2") = ObjAnomalias.DSResultados().Tables(2)
DT1 = ObjAnomalias.DSResultados().Tables(0)
DT2 = ObjAnomalias.DSResultados().Tables(1)
DT3 = ObjAnomalias.DSResultados().Tables(2)
If DT1.Rows.Count > 0 Then
ImgExcel0.Visible = True
ImgImprimir0.Visible = True
Else
ImgExcel0.Visible = False
ImgImprimir0.Visible = False
End If
If DT2.Rows.Count > 0 Then
ImgExcel1.Visible = True
ImgImprimir1.Visible = True
Else
ImgExcel1.Visible = False
ImgImprimir1.Visible = False
End If
If DT3.Rows.Count > 0 Then
ImgExcel2.Visible = True
ImgImprimir2.Visible = True
Else
ImgExcel2.Visible = False
ImgImprimir2.Visible = False
End If
UpAcciones.Update()
LbTotalContratos.Text = "Total de Contratos: " + ObjAnomalias.DSResultados().Tables(0).Rows.Count.ToString
LbTotalAnomalias.Text = "Total de Anomalías: " + ObjAnomalias.DSResultados().Tables(1).Rows.Count.ToString
LbTotalCumpleañeros.Text = "Total de Cumpleañeros: " + ObjAnomalias.DSResultados().Tables(2).Rows.Count.ToString
CargaGrid("")
End If
End Using
Using ObjAF As New ClsAF()
If ObjAF.GetLicenciasVencidas(-1, -1, UsuarioActual.CveEmpresa, Estatus:=1) Then
GvLicencias.DataSource = ObjAF.DtResultados.FiltraParametros("CveEstatusPersonal = 1")
Else
GvLicencias.DataSource = Nothing
End If
End Using
UpLicenciasVencidas.Update()
GvLicencias.DataBind()
End Sub
Protected Sub ImgImprimir0_Click(sender As Object, e As EventArgs) Handles ImgImprimir0.Click
GenerarPDF(0)
End Sub
Protected Sub ImgImprimir1_Click(sender As Object, e As EventArgs) Handles ImgImprimir1.Click
GenerarPDF(1)
End Sub
Protected Sub ImgImprimir2_Click(sender As Object, e As EventArgs) Handles ImgImprimir2.Click
GenerarPDF(2)
End Sub
Protected Sub ImgExcel0_Click(sender As Object, e As EventArgs) Handles ImgExcel0.Click
'GvDatos.ExportToExcel("ReporteVentas" & NowADS().ToShortDateString)
GenerarPDF(0, "Excel")
End Sub
Protected Sub ImgExcel1_Click(sender As Object, e As EventArgs) Handles ImgExcel1.Click
'GvDatos.ExportToExcel("ReporteVentas" & NowADS().ToShortDateString)
GenerarPDF(1, "Excel")
End Sub
Protected Sub ImgExcel2_Click(sender As Object, e As EventArgs) Handles ImgExcel2.Click
'GvDatos.ExportToExcel("ReporteVentas" & NowADS().ToShortDateString)
GenerarPDF(2, "Excel")
End Sub
Private Sub GenerarPDF(OP As Integer, Optional Formato As String = "PDF")
Dim DT As New DataTable
Dim rdlc As String = ""
Dim NombreReporte As String = ""
Select Case OP
Case 0
DT = DT1
rdlc = "RepPersonalInconsistenciasCV.rdlc"
NombreReporte = "ContratosVencidosProximosVencer"
Exit Select
Case 1
DT = DT2
rdlc = "RepPersonalInconsistenciasAS.rdlc"
NombreReporte = "AnomaliasSeguroSocial"
Exit Select
Case 2
DT = DT3
rdlc = "RepPersonalInconsistenciasCU.rdlc"
NombreReporte = "CumpleañosVencidosActuales"
Exit Select
End Select
If DT IsNot Nothing Then
Dim StrFiltro As New StringBuilder
' StrFiltro.AppendFormat("<b>Agrupado por</b>: {0}", DdlGrupo.SelectedItem.Text)
Dim Imagen As New System.IO.FileInfo($"{UsuarioActual.Empresa.Ruta}/Logo.png")
Dim logouri = String.Format("{0}://{1}:{2}/Empresas/{3}/Logo.png", Request.Url.Scheme, Request.Url.Host, Request.Url.Port, UsuarioActual.CveEmpresa)
If txtFechaI.Text <> "" And rdlc = "RepPersonalInconsistenciasCU.rdlc" Then StrFiltro.AppendFormat("&emsp;<b>Fecha Inicio</b>: {0}", txtFechaI.Text)
If txtFechaF.Text <> "" And rdlc = "RepPersonalInconsistenciasCU.rdlc" Then StrFiltro.AppendFormat("&emsp;<b>Fecha Fin</b>: {0}", txtFechaF.Text)
Dim params As New List(Of ReportParameter)
params.Add(New ReportParameter("NombreEmpresa", UsuarioActual.Empresa.Empresa))
params.Add(New ReportParameter("UsuarioImprimio", UsuarioActual.Nombre))
params.Add(New ReportParameter("FechaImpresion", NowADS().ToDateTime.ToShortDateString))
params.Add(New ReportParameter("Filtros", StrFiltro.ToString))
params.Add(New ReportParameter("LogoPath", If(Imagen.Exists, $"file://{Imagen.FullName}", "")))
ImprimirPDF($"Empresas/Grales/Formatos/{rdlc}", DT, params, String.Format("{0}-{1}", NombreReporte, NowADS().ToDateTime.ToShortDateString), Formato:=Formato)
Else
Alert("No hay datos consultados", TipoMensaje.MsgAdvertencia)
End If
End Sub
#Region "ORDENAMIENTO"
Protected Sub LbOrden_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim Orden As String = ""
Dim Campo As String = ""
Dim gvi As Integer = 0
Dim Literal As Literal = Nothing
Const OrdenInicial As String = ""
Dim Arg(2) As String
Arg = CType(sender, LinkButton).CommandArgument().ToString.Split(";"c)
Campo = Arg(0)
gvi = Arg(1).ToEntero
Literal = CType(CType(sender, LinkButton).NamingContainer.FindControl("Img" & Campo.Replace(",", "_")), Literal)
Campo = Campo.Substring(0, Campo.Length - 1)
If ViewState(String.Format("O{0}", Campo, gvi)) IsNot Nothing AndAlso ViewState(String.Format("O{0}", Campo, gvi)).ToString = String.Format("{0} DESC", Campo) Then
ViewState(String.Format("O{0}", Campo)) = String.Format("{0} ASC", Campo)
Literal.Text = String.Format("<i class='fa fa-sort-asc' style='color:#999' ></i>")
Else
ViewState(String.Format("O{0}", Campo, gvi)) = String.Format("{0} DESC", Campo)
Literal.Text = String.Format("<i class='fa fa-sort-desc' style='color:#999' ></i>")
End If
Orden = OrdenInicial & ViewState(String.Format("O{0}", Campo, gvi)).ToString
ViewState("Orden") = Orden
CargaGrid(Orden, gvi)
End Sub
#End Region
Protected Sub BtnConsultarCumpleanios_Click(sender As Object, e As EventArgs)
Dim FechaInicio As Date = NowADS()
Dim FechaFin As Date = NowADS()
Dim MesajeError As String = ""
Try
If txtFechaI.Text.Length = 5 Then
FechaInicio = Date.Parse($"{txtFechaI.Text}/{NowADS().Year}")
Else
MesajeError = "Fecha inicio formato incorrecto. "
End If
Catch ex As Exception
MesajeError = "Fecha inicio formato incorrecto. "
End Try
Try
If txtFechaF.Text.Length = 5 Then
FechaFin = Date.Parse($"{txtFechaF.Text}/{NowADS().Year}")
Else
MesajeError = $"{MesajeError }Fecha fin formato incorrecto"
End If
Catch ex As Exception
MesajeError = $"{MesajeError }Fecha fin formato incorrecto"
End Try
If MesajeError.Length > 0 Then
Alert(MesajeError, TipoMensaje.MsgAdvertencia)
Exit Sub
End If
If FechaInicio > FechaFin Then
FechaFin = FechaFin.AddYears(1)
End If
Dim ObjAnomalias As New ClsRH
If ObjAnomalias.GetRepPersonalInconsistencias(UsuarioActual.CveEmpresa.ToEntero, txtFechaI.Text.ToDate, txtFechaF.Text.ToDate) Then
ViewState("DTContenido2") = ObjAnomalias.DSResultados().Tables(2)
DT3 = ObjAnomalias.DSResultados().Tables(2)
If DT3.Rows.Count > 0 Then
ImgExcel2.Visible = True
ImgImprimir2.Visible = True
Else
ImgExcel2.Visible = False
ImgImprimir2.Visible = False
End If
UpAcciones.Update()
LbTotalCumpleañeros.Text = "Total de Cumpleañeros: " + ObjAnomalias.DSResultados().Tables(2).Rows.Count.ToString
End If
CargaGrid("")
ObjAnomalias.Dispose()
End Sub
End Class