251 lines
14 KiB
VB.net
251 lines
14 KiB
VB.net
Imports Newtonsoft.Json
|
|
Imports System.Net
|
|
Imports System.Net.Http
|
|
Imports System.Net.Security
|
|
Imports System.Threading.Tasks
|
|
Imports WebIntranet.Clases
|
|
Imports WebIntranet.Models
|
|
|
|
Public Class listPicadas
|
|
Inherits System.Web.UI.Page
|
|
'Shared sessionUsuario As String
|
|
'Shared usuariosSeleccionados As List(Of String)
|
|
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
|
|
If Session("usuario") = "" Then
|
|
Response.Redirect("default.aspx")
|
|
End If
|
|
estIncPicBL.Visible = False
|
|
If Not IsPostBack Then
|
|
inpFechaInicio.Value = DateTime.Now.ToString("yyyy-MM") + "-01"
|
|
inpFechaFin.Value = DateTime.Now.ToString("yyyy-MM-dd")
|
|
End If
|
|
'sessionUsuario = Session("usuario")
|
|
'usuariosSeleccionados = Session("usuariosSeleccionados")
|
|
If Session("modo") = "PERSONAL" Then
|
|
intPicadaBL.Visible = False
|
|
VAAPBCBL.Visible = False
|
|
If Session("persona").Personas(0).Dni = "44286377S" Then
|
|
estIncPicBL.Visible = True
|
|
End If
|
|
'bolsaDeHorasBL.Visible = False
|
|
Else
|
|
VAAPBCBLpers.Visible = False
|
|
Li1.Visible = False
|
|
intPicadaPersBL.Visible = False
|
|
End If
|
|
MODO.Value = Session("modo")
|
|
End Sub
|
|
|
|
<System.Web.Services.WebMethod()>
|
|
Public Shared Async Function CargarListadodePicadasAsync(fechaInit As String, fechaEnd As String) As Task(Of String)
|
|
|
|
Try
|
|
ServicePointManager.ServerCertificateValidationCallback = New RemoteCertificateValidationCallback(Function() True)
|
|
Dim usuariosSeleccionados As List(Of String) = HttpContext.Current.Session("usuariosSeleccionados")
|
|
'// Aquí preparamos el objeto para la consulta.
|
|
Dim objetoConsulta As New Models.Consulta
|
|
objetoConsulta.fechaInicio = New Date(fechaInit)
|
|
objetoConsulta.fechaFin = New Date(fechaEnd)
|
|
'objetoConsulta.listaNif = DNI 'New List(Of String)
|
|
objetoConsulta.listaNif = usuariosSeleccionados 'New List(Of String)
|
|
|
|
'// Aquí convertimos el objeto en una cadena JSON.
|
|
Dim jsonConsulta As String = JsonConvert.SerializeObject(objetoConsulta)
|
|
Dim url As String = ConfigurationManager.AppSettings("RutaRes").ToString + "/api/ListPicaEntreFechas"
|
|
|
|
Dim clienteHTTP As New HttpClient
|
|
Dim contenidoConsultaHTTP As New StringContent(jsonConsulta, Encoding.UTF8, "application/json")
|
|
Debug.WriteLine("CargarListadodePicadasAsync:1===" + Now.ToLongTimeString)
|
|
Dim respuestaHTTP As HttpResponseMessage = Await clienteHTTP.PostAsync(url, contenidoConsultaHTTP).ConfigureAwait(False)
|
|
Debug.WriteLine("CargarListadodePicadasAsync:2===" + Now.ToLongTimeString)
|
|
Dim sRespuesta As String = Await respuestaHTTP.Content.ReadAsStringAsync().ConfigureAwait(False)
|
|
Debug.WriteLine("CargarListadodePicadasAsync:3===" + Now.ToLongTimeString)
|
|
'// danmun: Aquí SÍ hay que poner `.ConfigureAwait(False)` al final de las llamadas a métodos Async()
|
|
'// para que el control de ejecución vuelva a este hilo.
|
|
|
|
''// Deserializar a una clase.
|
|
Dim settings As New Newtonsoft.Json.JsonSerializerSettings()
|
|
settings.CheckAdditionalContent = True
|
|
Dim objetoDatos As ResultadoListPicaEntreFechas =
|
|
Newtonsoft.Json.JsonConvert.DeserializeObject(Of ResultadoListPicaEntreFechas)(sRespuesta, settings)
|
|
|
|
'Debug.WriteLine("Resultado: " & objetoDatos.resultado)
|
|
'Debug.WriteLine("Mensaje: " & objetoDatos.Mensaje)
|
|
'Debug.WriteLine("ListadoEF.FechaInicio: " & objetoDatos.ListadoEF.FechaInicio)
|
|
|
|
'Dim htmlImp = ""
|
|
'Dim html = ""
|
|
Dim listaDepartamento = objetoDatos.ListadoEF.ListaDepartamento
|
|
Dim totales As TotalPeriodo =
|
|
Newtonsoft.Json.JsonConvert.DeserializeObject(Of TotalPeriodo)(sRespuesta, settings)
|
|
|
|
|
|
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
|
|
|
|
Dim json As String = ""
|
|
Dim contadorDep = 0
|
|
For Each dep As Departamento In listaDepartamento
|
|
Dim contador = 0
|
|
For Each per As PersonaCH In dep.LisPersonas
|
|
'Dim sesUsu As String = HttpContext.Current.Session("usuario")
|
|
json += "{""ApellidosNombre"":""" + per.ApellidosNombre + """, ""NombreDepartamento"":""" + dep.NombreDepartamento + """,""turno"": ["
|
|
Dim x = 0
|
|
For Each turno As FechaTurno In per.LisFechasTurnos
|
|
If turno.LisPicadasAsistencias IsNot Nothing Then
|
|
|
|
If x > 0 Then
|
|
json += ","
|
|
End If
|
|
|
|
x += 1
|
|
json += "{""DesFechaTurno"": """ + turno.DesFechaTurno + """,""Picada"":["
|
|
Dim i = 0
|
|
|
|
For Each picada As PicadaAsistencia In turno.LisPicadasAsistencias
|
|
If i > 0 Then
|
|
json += ","
|
|
End If
|
|
i += 1
|
|
json += "{""Hora"":""" + picada.Hora + """, ""horaReal"":""" + picada.HoraReal + """, ""Incidencia"":""" + picada.Incidencia + """,""HorasATrabajar"":""" + picada.HorasATrabajar + """,""HorasTrabajadas"":""" + picada.HorasTrabajadas + """," +
|
|
"""HorasExtraACompensar"":""" + picada.HorasExtraACompensar + """,""HorasExtraAguardar"":""" + picada.HorasExtraAguardar + """, ""Saldo"":""" + picada.Saldo + """,""HorasRecuperables"":""" + picada.HorasRecuperables + """," +
|
|
"""HorasIncumplimiento"":""" + picada.HorasIncumplimiento + """,""HorasTrabajadasTarde"":""" + picada.HorasTrabajadasTarde + """}"
|
|
Next
|
|
json += "]}"
|
|
End If
|
|
Next
|
|
json += "],""totales"":[{""TotalHorasATrabajar"":""" + per.TotalesPeriodo.TotalHorasATrabajar + """,""TotalHorasTrabajadas"":""" + per.TotalesPeriodo.TotalHorasTrabajadas + """,""TotalHorasExtraACompensar"":""" + per.TotalesPeriodo.TotalHorasExtraACompensar + """," +
|
|
"""TotalHorasExtraAguardar"":""" + per.TotalesPeriodo.TotalHorasExtraAguardar + """,""TotalSaldo"":""" + per.TotalesPeriodo.TotalSaldo + """,""TotalHorasRecuperables"":""" + per.TotalesPeriodo.TotalHorasRecuperables + """,""TotalHorasIncumplimiento"":""" + per.TotalesPeriodo.TotalHorasIncumplimiento + """," +
|
|
"""TotalHorasTrabajadasTarde"":""" + per.TotalesPeriodo.TotalHorasTrabajadasTarde + """}]"
|
|
json += "}"
|
|
If contador < dep.LisPersonas.Count - 1 Then
|
|
contador += 1
|
|
json += ","
|
|
ElseIf contadorDep < listaDepartamento.Count - 1 Then
|
|
contadorDep += 1
|
|
json += ","
|
|
End If
|
|
|
|
Next
|
|
|
|
|
|
Next
|
|
If Not json = "" Then
|
|
json = "[" + json + "]"
|
|
End If
|
|
Return json
|
|
Catch ex As Exception
|
|
Return "error"
|
|
End Try
|
|
End Function
|
|
|
|
<System.Web.Services.WebMethod()>
|
|
Public Shared Function CargarListadodePicadas(fechaInit As String, fechaEnd As String) As String
|
|
'mensaje.InnerHtml = ""
|
|
Dim usuario As String = "tecnosis"
|
|
Dim contraseña As String = "patata2022"
|
|
Dim sessionUsuario As String = HttpContext.Current.Session("usuario")
|
|
'// A continuación, se realizará una petición al servicio REST
|
|
'// de la Oficina Antifraude para identificar al usuario "manuel".
|
|
|
|
Dim url1 As String = ConfigurationManager.AppSettings("RutaRes").ToString + "/api/ListPicaEntreFechas"
|
|
Dim clienteHTTP1 As New Net.WebClient()
|
|
Dim cadenaAutenticación As String =
|
|
System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(usuario & ":" & contraseña))
|
|
clienteHTTP1.Headers.Add("Authorization", "Basic " & cadenaAutenticación)
|
|
clienteHTTP1.Encoding = System.Text.Encoding.UTF8
|
|
Dim nif = sessionUsuario
|
|
Dim FechaInicio = fechaInit
|
|
Dim FechaFin = fechaEnd
|
|
Dim sRespuesta1 As String = clienteHTTP1.UploadString(url1, nif & "," & FechaInicio & "," & FechaFin)
|
|
'Me.TextBoxResultados.Text = sRespuesta1
|
|
|
|
|
|
'// Esta es una manera "genérica" de acceder a datos JSON mediante LINQ,
|
|
'// usando la biblioteca Newtonsoft.Json.
|
|
Dim datos As Newtonsoft.Json.Linq.JObject =
|
|
Newtonsoft.Json.JsonConvert.DeserializeObject(Of Newtonsoft.Json.Linq.JObject)(sRespuesta1)
|
|
Dim sbResultado As New Text.StringBuilder()
|
|
sbResultado.AppendFormat("Resultado: {0}{1}", datos.Item("Resultado").ToString, vbCrLf)
|
|
sbResultado.AppendFormat("Mensaje: {0}{1}", datos.Item("Mensaje"), vbCrLf)
|
|
sbResultado.AppendFormat("ListadoEF: {0}{1}", datos.Item("ListadoEF"), vbCrLf)
|
|
|
|
'// Deserializar a una clase.
|
|
Dim settings As New Newtonsoft.Json.JsonSerializerSettings()
|
|
settings.CheckAdditionalContent = True
|
|
Dim objetoDatos As Models.ResultadoListPicaEntreFechas =
|
|
Newtonsoft.Json.JsonConvert.DeserializeObject(Of Models.ResultadoListPicaEntreFechas)(sRespuesta1, settings)
|
|
|
|
Debug.WriteLine("Resultado: " & objetoDatos.resultado)
|
|
Debug.WriteLine("Mensaje: " & objetoDatos.Mensaje)
|
|
Debug.WriteLine("ListadoEF.FechaInicio: " & objetoDatos.ListadoEF.FechaInicio)
|
|
|
|
Dim htmlImp = ""
|
|
Dim html = ""
|
|
Dim listaDepartamento = objetoDatos.ListadoEF.ListaDepartamento
|
|
Dim totales As Models.TotalPeriodo =
|
|
Newtonsoft.Json.JsonConvert.DeserializeObject(Of Models.TotalPeriodo)(sRespuesta1, settings)
|
|
|
|
|
|
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
|
|
|
|
Dim json As String = ""
|
|
|
|
For Each dep As Models.Departamento In listaDepartamento
|
|
For Each per As Models.PersonaCH In dep.LisPersonas
|
|
json += "{""ApellidosNombre"":""" + per.ApellidosNombre + """, ""NombreDepartamento"":""" + dep.NombreDepartamento + """,""turno"": ["
|
|
Dim x = 0
|
|
For Each turno As Models.FechaTurno In per.LisFechasTurnos
|
|
|
|
If turno.LisPicadasAsistencias IsNot Nothing Then
|
|
If x > 0 Then
|
|
json += ","
|
|
End If
|
|
x += 1
|
|
json += "{""DesFechaTurno"": """ + turno.DesFechaTurno + """,""Picada"":["
|
|
Dim i = 0
|
|
For Each picada As Models.PicadaAsistencia In turno.LisPicadasAsistencias
|
|
|
|
If i > 0 Then
|
|
json += ","
|
|
End If
|
|
|
|
i += 1
|
|
|
|
json += "{""Hora"":""" + picada.Hora + """, ""horaReal"":""" + picada.HoraReal + """, ""Incidencia"":""" + picada.Incidencia + """,""HorasATrabajar"":""" + picada.HorasATrabajar + """,""HorasTrabajadas"":""" + picada.HorasTrabajadas + """," +
|
|
"""HorasExtraACompensar"":""" + picada.HorasExtraACompensar + """,""HorasExtraAguardar"":""" + picada.HorasExtraAguardar + """, ""Saldo"":""" + picada.Saldo + """,""HorasRecuperables"":""" + picada.HorasRecuperables + """," +
|
|
"""HorasIncumplimiento"":""" + picada.HorasIncumplimiento + """,""HorasTrabajadasTarde"":""" + picada.HorasTrabajadasTarde + """}"
|
|
Next
|
|
json += "]}"
|
|
End If
|
|
|
|
|
|
Next
|
|
json += "],""totales"":[{""TotalHorasATrabajar"":""" + per.TotalesPeriodo.TotalHorasATrabajar + """,""TotalHorasTrabajadas"":""" + per.TotalesPeriodo.TotalHorasTrabajadas + """,""TotalHorasExtraACompensar"":""" + per.TotalesPeriodo.TotalHorasExtraACompensar + """," +
|
|
"""TotalHorasExtraAguardar"":""" + per.TotalesPeriodo.TotalHorasExtraAguardar + """,""TotalSaldo"":""" + per.TotalesPeriodo.TotalSaldo + """,""TotalHorasRecuperables"":""" + per.TotalesPeriodo.TotalHorasRecuperables + """,""TotalHorasIncumplimiento"":""" + per.TotalesPeriodo.TotalHorasIncumplimiento + """," +
|
|
"""TotalHorasTrabajadasTarde"":""" + per.TotalesPeriodo.TotalHorasTrabajadasTarde + """}]"
|
|
Next
|
|
|
|
json += "}"
|
|
Next
|
|
|
|
If Not json = "" Then
|
|
json = "[" + json + "]"
|
|
End If
|
|
|
|
Return json
|
|
|
|
|
|
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------'
|
|
|
|
|
|
End Function
|
|
|
|
Public Function UnAccent(ByVal aString As String) As String
|
|
Dim toReplace() As Char = "àèìòùÀÈÌÒÙ äëïöüÄËÏÖÜ âêîôûÂÊÎÔÛ áéíóúÁÉÍÓÚðÐýÝ ãñõÃÑÕšŠžŽçÇåÅøØ".ToCharArray
|
|
Dim replaceChars() As Char = "aeiouAEIOU aeiouAEIOU aeiouAEIOU aeiouAEIOUdDyY anoANOsSzZcCaAoO".ToCharArray
|
|
For index As Integer = 0 To toReplace.GetUpperBound(0)
|
|
aString = aString.Replace(toReplace(index), replaceChars(index))
|
|
Next
|
|
Return aString
|
|
End Function
|
|
End Class |