API REST E119.ashx, metodo para obtener JAM_BASF_POG
This commit is contained in:
@@ -13,6 +13,7 @@ Public Class ClsInventarios
|
||||
Private SqlAdapter As SqlDataAdapter
|
||||
Private SqlTransacc As SqlTransaction
|
||||
Private Data As DataTable
|
||||
Private Dataset As DataSet
|
||||
|
||||
Private disposedValue As Boolean = False ' Para detectar llamadas redundantes
|
||||
'REGISTRAR CONEXIONES ABIERTAS
|
||||
@@ -140,6 +141,12 @@ Public Class ClsInventarios
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property DataSetResultados() As DataSet
|
||||
Get
|
||||
DataSetResultados = DataSet
|
||||
End Get
|
||||
End Property
|
||||
|
||||
#End Region
|
||||
|
||||
Sub New(Optional TransaccionCompartida As SqlTransaction = Nothing)
|
||||
@@ -5875,6 +5882,27 @@ Public Class ClsInventarios
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
#Region "JAM - POG"
|
||||
Public Function GetJAM_BASF_POG(Fecha As Date) As Boolean
|
||||
Dim Retorno As Boolean = False
|
||||
Dataset = New DataSet()
|
||||
DataAdapter("PA_JAM_BASF_POG")
|
||||
With SqlAdapter.SelectCommand.Parameters
|
||||
.Add("@Fecha", SqlDbType.Date).Value = Fecha
|
||||
End With
|
||||
|
||||
Try
|
||||
SqlAdapter.Fill(Dataset)
|
||||
Retorno = True
|
||||
Catch ex As Exception
|
||||
OnError("Ocurrió un error al obtener las existencias.", ex, SqlAdapter.SelectCommand.Parameters.ParametrosInfo)
|
||||
End Try
|
||||
|
||||
Return Retorno
|
||||
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
#Region " IDisposable Support "
|
||||
' IDisposable
|
||||
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
|
||||
@@ -5882,6 +5910,7 @@ Public Class ClsInventarios
|
||||
If disposing Then
|
||||
' TODO: Liberar otro estado (objetos administrados).
|
||||
If Not Data Is Nothing Then Data.Dispose() : Data = Nothing
|
||||
If Not Dataset Is Nothing Then Dataset.Dispose() : Dataset = Nothing
|
||||
If Not SqlAdapter Is Nothing Then SqlAdapter.Dispose() : SqlAdapter = Nothing
|
||||
If Not SqlTransacc Is Nothing Then SqlTransacc.Dispose() : SqlTransacc = Nothing
|
||||
If SqlConexion.State <> ConnectionState.Closed Then SqlConexion.Close()
|
||||
|
||||
303
Ashx/E119.ashx
Normal file
303
Ashx/E119.ashx
Normal file
@@ -0,0 +1,303 @@
|
||||
<%@ WebHandler Language="VB" Class="E119" %>
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Imports System.Data
|
||||
Imports System.IO
|
||||
Imports System.Net.Http
|
||||
Imports Newtonsoft.Json
|
||||
Imports Newtonsoft.Json.Linq
|
||||
Imports Extensiones
|
||||
|
||||
Public Class E119 : Implements IHttpHandler
|
||||
|
||||
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
||||
Get
|
||||
Return False
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Private ReadOnly Property CveEmpresa As Integer = 119
|
||||
|
||||
Public ReadOnly Property EsProduccion As Boolean
|
||||
Get
|
||||
If IsNothing(System.Configuration.ConfigurationManager.AppSettings("EsProduccion")) Then
|
||||
Return False
|
||||
Else
|
||||
Return (System.Configuration.ConfigurationManager.AppSettings("EsProduccion").ToString() = "1")
|
||||
End If
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property UsuarioWSE119 As String
|
||||
Get
|
||||
If IsNothing(System.Configuration.ConfigurationManager.AppSettings("UsuarioWSE119")) Then
|
||||
Return ""
|
||||
Else
|
||||
Return System.Configuration.ConfigurationManager.AppSettings("UsuarioWSE119").ToString()
|
||||
End If
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property PasswordWSE119 As String
|
||||
Get
|
||||
If IsNothing(System.Configuration.ConfigurationManager.AppSettings("PasswordWSE119")) Then
|
||||
Return ""
|
||||
Else
|
||||
Return System.Configuration.ConfigurationManager.AppSettings("PasswordWSE119").ToString()
|
||||
End If
|
||||
End Get
|
||||
End Property
|
||||
Public ReadOnly Property TokenAutorizacion As String
|
||||
Get
|
||||
Return "$2y$10$LGqtRWUloKQmAt.jcUldc.PmS5LJ6l.WU2w1G4PBOTLMVKZRNQFPS"
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property URLBase As String
|
||||
Get
|
||||
Return "https://services.fidelityapps.mx/"
|
||||
End Get
|
||||
End Property
|
||||
|
||||
|
||||
#Region "V A L I D A - D A T O S"
|
||||
Private Function ValidaUsuarioSistema(CveUsuario As Integer, CveEmpresa As Integer) As Usuario
|
||||
Dim UsuarioActual As Usuario = Nothing
|
||||
Dim ObjUsuarios As New ClsSisUsuarios
|
||||
If ObjUsuarios.GetUsuarios(CveUsuario) Then
|
||||
If ObjUsuarios.DtResultados.Rows.Count > 0 Then
|
||||
Dim Usuario = ObjUsuarios.DtResultados.Rows(0)("Usuario").ToString()
|
||||
Dim Contrasenia = ObjUsuarios.DtResultados.Rows(0)("Contraseña").ToString()
|
||||
UsuarioActual = ObjUsuarios.ValidaUsuario(Usuario, Contrasenia, IMEI, CveEmpresa)
|
||||
UsuarioActual.CveEmpresa = CveEmpresa
|
||||
CreaObjetoEmpresa(UsuarioActual)
|
||||
End If
|
||||
End If
|
||||
ObjUsuarios.Dispose()
|
||||
Return UsuarioActual
|
||||
End Function
|
||||
Private Sub CreaObjetoEmpresa(ByRef UsuarioActual As Usuario)
|
||||
Dim ObjEmpresa As New ClsSisEmpresas()
|
||||
If ObjEmpresa.GetEmpresas(UsuarioActual.CveEmpresa, "-1", "-1", "-1", "-1") Then
|
||||
If ObjEmpresa.GetEmpresasFuncionalidades(UsuarioActual.CveEmpresa) Then
|
||||
Dim dttmp As Data.DataTable = ObjEmpresa.DtResultados
|
||||
|
||||
Dim EmpresasFuncionalidades As New HybridDictionary
|
||||
For Each Row As Data.DataRow In dttmp.Rows
|
||||
EmpresasFuncionalidades.Add(Convert.ToInt32(Row("CveFuncionalidad")), Row("Valor").ToString)
|
||||
Next
|
||||
ObjEmpresa.Empresa.SetFuncionalidades(EmpresasFuncionalidades)
|
||||
End If
|
||||
|
||||
UsuarioActual.Empresa = ObjEmpresa.Empresa
|
||||
End If
|
||||
ObjEmpresa.Dispose()
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
||||
Dim retorno As String = ""
|
||||
Try
|
||||
Dim Metodo = If(context.Request("Metodo") = Nothing, "", context.Request("Metodo").ToString())
|
||||
'OBTENER EXISTENCIAS
|
||||
If Metodo = "ConsultaBASF_POG" Then
|
||||
context.Response.ContentType = "application/json"
|
||||
Dim Auth = ValidarSolicitud(context)
|
||||
|
||||
If Auth.IsSucces Then
|
||||
retorno = ConsultaDatos(context)
|
||||
Else
|
||||
context.Response.StatusCode = Auth.StatusCode
|
||||
retorno = JsonConvert.SerializeObject(Auth.ErrorMessage)
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
context.Response.Write(retorno)
|
||||
|
||||
Catch ex As Exception
|
||||
context.Response.ContentType = "text/html"
|
||||
retorno = ex.ToString()
|
||||
ex.GuardaLog(ex.ToString())
|
||||
|
||||
context.Response.Write(retorno)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Function ValidarSolicitud(ByVal context As HttpContext) As AuthMessage
|
||||
Dim unauthorized As Boolean = True
|
||||
Dim respuesta As New AuthMessage
|
||||
|
||||
Dim authHeader = context.Request.Headers("Authorization")
|
||||
If authHeader IsNot Nothing Then
|
||||
Dim basicAuth As String = authHeader.Replace("Basic ", "")
|
||||
|
||||
Dim usernamePasswordArray = Encoding.UTF8.GetString(Convert.FromBase64String(basicAuth)).Split(":"c)
|
||||
|
||||
Dim userName = usernamePasswordArray(0)
|
||||
Dim password = usernamePasswordArray(1)
|
||||
unauthorized = Not (userName = Me.UsuarioWSE119 AndAlso password = Me.PasswordWSE119)
|
||||
|
||||
Else
|
||||
respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña son requeridos"}
|
||||
respuesta.IsSucces = False
|
||||
respuesta.StatusCode = 200
|
||||
|
||||
Return respuesta
|
||||
End If
|
||||
|
||||
If unauthorized Then
|
||||
respuesta.ErrorMessage = New ResponseMsgError() With {.message = "el usuario y/o contraseña no son validos"}
|
||||
respuesta.IsSucces = False
|
||||
respuesta.StatusCode = 200
|
||||
|
||||
Return respuesta
|
||||
Else
|
||||
respuesta.ErrorMessage = Nothing
|
||||
respuesta.IsSucces = True
|
||||
respuesta.StatusCode = 200
|
||||
|
||||
Return respuesta
|
||||
End If
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
Private Function ConsultaDatos(ByVal context As HttpContext) As String
|
||||
Dim Respuesta As New ResponseMsg
|
||||
Dim RespuestaError As New ResponseMsgError
|
||||
Dim TieneError As Boolean = False
|
||||
|
||||
Dim strFecha = If(context.Request("Fecha") = Nothing, "", context.Request("Fecha").ToString())
|
||||
|
||||
If String.IsNullOrEmpty(strFecha) Then
|
||||
RespuestaError.message = "Debe especificar una fecha"
|
||||
context.Response.StatusCode = 200
|
||||
Return JsonConvert.SerializeObject(RespuestaError)
|
||||
End If
|
||||
|
||||
If Not IsDate(strFecha) Then
|
||||
RespuestaError.message = "La fecha no tiene el formato correcto"
|
||||
context.Response.StatusCode = 200
|
||||
Return JsonConvert.SerializeObject(RespuestaError)
|
||||
End If
|
||||
|
||||
Dim Fecha As DateTime = strFecha.ToDateTime()
|
||||
Dim Facturas As JArray = Nothing
|
||||
Dim Stock As JArray = Nothing
|
||||
|
||||
If Fecha > MinFecha Then
|
||||
Using ObjInventario As New ClsInventarios
|
||||
If ObjInventario.GetJAM_BASF_POG(Fecha) AndAlso ObjInventario.DataSetResultados IsNot Nothing Then
|
||||
Facturas = JArray.Parse(ObjInventario.DataSetResultados.Tables(0).DataTableToJSONIPP())
|
||||
Stock = JArray.Parse(ObjInventario.DataSetResultados.Tables(1).DataTableToJSONIPP())
|
||||
Else
|
||||
RespuestaError.message = "no se pudo obtener los datos"
|
||||
TieneError = True
|
||||
End If
|
||||
End Using
|
||||
Else
|
||||
RespuestaError.message = "la fecha no es leida correctamente"
|
||||
TieneError = True
|
||||
End If
|
||||
|
||||
If TieneError Then
|
||||
context.Response.StatusCode = 200
|
||||
Return JsonConvert.SerializeObject(RespuestaError)
|
||||
Else
|
||||
context.Response.StatusCode = 200
|
||||
Try
|
||||
Respuesta.data = New JObject(New JProperty("Facturas", Facturas), New JProperty("Stock", Stock))
|
||||
Respuesta.message = "Los datos se obtuvieron correctamente"
|
||||
Return JsonConvert.SerializeObject(Respuesta)
|
||||
Catch ex As Exception
|
||||
RespuestaError.message = "Ocurrió un error al generar la petición"
|
||||
Return JsonConvert.SerializeObject(RespuestaError)
|
||||
End Try
|
||||
|
||||
End If
|
||||
End Function
|
||||
|
||||
Private Class ResponseMsg
|
||||
Sub New()
|
||||
status = "success"
|
||||
End Sub
|
||||
Public Property status As String
|
||||
Public Property data As Object
|
||||
Public Property message As String
|
||||
End Class
|
||||
|
||||
Private Class ResponseMsgError
|
||||
Sub New()
|
||||
status = "error"
|
||||
End Sub
|
||||
Public Property status As String
|
||||
Public Property message As String
|
||||
End Class
|
||||
|
||||
Private Class AuthMessage
|
||||
Public Property IsSucces As Boolean
|
||||
Public Property ErrorMessage As ResponseMsgError
|
||||
Public Property StatusCode As Integer
|
||||
End Class
|
||||
|
||||
'Private Function ActualizarExistenciasJson(Todos As Boolean) As String
|
||||
' Dim payload = New JObject()
|
||||
|
||||
' Dim CountPeticiones As Integer = 0, CountPeticionesExitosas As Integer = 0
|
||||
|
||||
' Dim DtPS As DataTable = Nothing
|
||||
' Using ObjPS As New ClsProductosServicios
|
||||
' If ObjPS.GetExistenciasEmpresa("-1", CveEmpresa) Then
|
||||
' DtPS = ObjPS.DtResultados.Copy()
|
||||
' End If
|
||||
' End Using
|
||||
|
||||
' If DtPS IsNot Nothing Then
|
||||
' payload.Add(New JProperty("stock", GenerarPayloadExistencias(DtPS)))
|
||||
' End If
|
||||
|
||||
' Return payload.ToString()
|
||||
'End Function
|
||||
|
||||
|
||||
|
||||
Private Function Parametros(Cadena As String) As Hashtable
|
||||
Dim P1() As String = Cadena.Split("&"c)
|
||||
Dim Tmp As String
|
||||
Dim P2() As String
|
||||
|
||||
Dim URLParametros As New Hashtable
|
||||
|
||||
For Each Tmp In P1
|
||||
P2 = Tmp.Replace("%26%", "&").Split("="c)
|
||||
URLParametros.Add(P2(0).ToString.ToUpper, P2(1))
|
||||
Next
|
||||
Return URLParametros
|
||||
End Function
|
||||
|
||||
Private Shared Function IsValidJson(ByVal strInput As String) As Boolean
|
||||
If String.IsNullOrWhiteSpace(strInput) Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
strInput = strInput.Trim()
|
||||
|
||||
If (strInput.StartsWith("{") AndAlso strInput.EndsWith("}")) OrElse (strInput.StartsWith("[") AndAlso strInput.EndsWith("]")) Then
|
||||
|
||||
Try
|
||||
Dim obj = JToken.Parse(strInput)
|
||||
Return True
|
||||
Catch jex As JsonReaderException
|
||||
Console.WriteLine(jex.Message)
|
||||
Return False
|
||||
Catch ex As Exception
|
||||
Console.WriteLine(ex.ToString())
|
||||
Return False
|
||||
End Try
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
|
||||
End Class
|
||||
Reference in New Issue
Block a user