1713 lines
76 KiB
Plaintext
1713 lines
76 KiB
Plaintext
<%@ WebHandler Language="VB" Class="SIGWeb" %>
|
|
|
|
Imports System
|
|
Imports System.Web
|
|
Imports System.Data
|
|
Imports Newtonsoft.Json
|
|
Imports Extensiones
|
|
Imports System.IO
|
|
Imports Microsoft.Reporting.WebForms
|
|
|
|
Public Class SIGWeb : Implements IHttpHandler, IRequiresSessionState
|
|
'TEMPORAL, DEBE SER REEMPLAZADO POR EL MODELO DE LA LIBRERIA
|
|
Public Class MResponseModel(Of T)
|
|
Public Property IsSuccess As Boolean
|
|
Public Property Message As String
|
|
Public Property Result As T
|
|
End Class
|
|
|
|
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
|
|
If context.Request("metodo") IsNot Nothing AndAlso context.Request("metodo").ToString() = "GetTokenAngular" Then
|
|
'context.Response.ContentType = "application/json; charset=utf-8"
|
|
|
|
context.Response.ContentType = "text/json"
|
|
If context.Request IsNot Nothing AndAlso context.Request.UrlReferrer IsNot Nothing Then
|
|
Dim origin As String = context.Request.UrlReferrer.ToString()
|
|
context.Response.AddHeader("Access-Control-Allow-Origin", origin.Substring(0, origin.Length - 1))
|
|
End If
|
|
'context.Response.AddHeader("Access-Control-Allow-Origin", "http://localhost:4200")
|
|
'context.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST")
|
|
context.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept")
|
|
context.Response.AddHeader("Access-Control-Allow-Credentials", "true")
|
|
context.Response.StatusCode = 200
|
|
Dim key As String = ""
|
|
Try
|
|
key = GetTokenAngular(context)
|
|
Catch ex As Exception
|
|
GuardaLog(ex.ToString())
|
|
End Try
|
|
Dim json As String = JsonConvert.SerializeObject(key)
|
|
context.Response.Write(json)
|
|
context.Response.Flush()
|
|
context.Response.Close()
|
|
context.Response.End()
|
|
Else
|
|
If context.Request("metodo").Contiene("Contabilizapoliza", "RevisaConexion") Then
|
|
context.Response.ContentType = "text/json"
|
|
Else
|
|
context.Response.ContentType = "text/plain"
|
|
|
|
End If
|
|
End If
|
|
|
|
Try
|
|
Select Case context.Request("metodo")
|
|
Case "Contabilizapoliza"
|
|
Dim CvePrePoliza As Integer = context.Request("CvePrePoliza").ToString().ToEntero()
|
|
Dim CveUsuario As Integer = context.Request("CveUsuario").ToString().ToEntero()
|
|
Dim CveEmpresa As Integer = context.Request("CveEmpresa").ToString().ToEntero()
|
|
GuardaLog(String.Format("?metodo=Contabilizapoliza&CvePrePoliza={0}&CveUsuario={1}&CveEmpresa ={2}", CvePrePoliza, CveUsuario, CveEmpresa))
|
|
ActualizaPrePoliza(context)
|
|
|
|
Dim obj As New MResponseModel(Of Object)()
|
|
obj.Result = DateTime.Now.ToString()
|
|
Dim retorno = JsonConvert.SerializeObject(obj).ToString()
|
|
context.Response.Write(retorno)
|
|
context.Response.StatusCode = 200
|
|
Case "RevisaConexion"
|
|
Dim obj As New MResponseModel(Of Object)()
|
|
obj.Result = DateTime.Now.ToString()
|
|
Dim retorno = JsonConvert.SerializeObject(obj).ToString()
|
|
context.Response.Write(retorno)
|
|
context.Response.StatusCode = 200
|
|
Case "getps"
|
|
GETPS(context)
|
|
Case "getps2"
|
|
GETPS(context, "PSCodigoClasificacion")
|
|
Case "getpsalmacen"
|
|
getpsalmacen(context)
|
|
Case "Uploadfile"
|
|
uploadfile(context)
|
|
Case "Downfile"
|
|
Downfile(context)
|
|
Case "GetImg"
|
|
GetImg(context)
|
|
Case "getpssat"
|
|
GETPSSAT(context)
|
|
Case "getpsusados"
|
|
GETPSUSADOS(context)
|
|
Case "getumsat"
|
|
GETUMSAT(context)
|
|
Case "getsatmatpeligroso"
|
|
GETSATMaterialPeligroso(context)
|
|
Case "getsatembalajes"
|
|
GETSATEmbalajes(context)
|
|
Case "getcliente"
|
|
GetClientes(context)
|
|
Case "getproveedores"
|
|
GetProveedores(context)
|
|
Case "getfraccionarancelaria"
|
|
GetFraccionArancelaria(context)
|
|
Case "GetUser"
|
|
GetUser(context)
|
|
Case "ActualizaPreP"
|
|
ActualizaPrePoliza(context)
|
|
Case "getpersonal"
|
|
getpersonal(context)
|
|
Case "getcontratos"
|
|
GetContratos(context)
|
|
Case "GettingCURP"
|
|
context.Response.Write(GettingCURP(context.Request("Curp").ToString(), context.Request("year").ToString().ToEntero()))
|
|
Case "ValidaCURP"
|
|
context.Response.Write(ValidaCURP(context.Request("Curp").ToString()))
|
|
Case "sendMail"
|
|
context.Response.Write(sendMail(context))
|
|
Case "sendMailEMD"
|
|
context.Response.Write(sendMailEMD(context))
|
|
Case "sendMailLPM"
|
|
context.Response.Write(sendMailLPM(context))
|
|
Case "getSATColomias"
|
|
getSatColonias(context)
|
|
Case "GetFilesDirectory"
|
|
GetFilesDirectory(context)
|
|
Case "Getetiquetas"
|
|
Getetiquetas(context)
|
|
Case "cancelarRemision"
|
|
cancelarRemision(context)
|
|
Case "RemoveMovimiento"
|
|
RemoveMovimiento(context)
|
|
End Select
|
|
Catch ex As Exception
|
|
ex.GuardaLog(ex.Message)
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
Public Sub ImprimirPDF(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, Optional Content_Disposition As String = "attachment")
|
|
'limpio ReportViwer
|
|
ImprimirbytesPDF(StreamPDF(RutaReporte, DataSource, Parametros, NombreArchivo, Formato, MR), NombreArchivo, Formato, Content_Disposition:=Content_Disposition)
|
|
End Sub
|
|
|
|
Public Function StreamPDF(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 = ""
|
|
|
|
|
|
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
|
|
|
|
If False 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
|
|
|
|
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
|
|
|
|
Public Sub ImprimirbytesPDF(bytes As Byte(), Optional NombreArchivo As String = "Reporte", Optional Formato As String = "PDF", Optional Descarga As Boolean = False, Optional Content_Disposition As String = "attachment")
|
|
'limpio ReportViwer
|
|
Dim mimeType As String = Nothing
|
|
Dim extension As String = Nothing
|
|
|
|
'If Descarga Then
|
|
' Try
|
|
' bytes = bytes
|
|
' File.WriteAllBytes(String.Format("{0}PDF/whatever.gif", UsuarioActual.Empresa.Ruta), img)
|
|
' Catch ex As Exception
|
|
' If UsuarioActual.CveRol = 1 Then
|
|
' Alert(ex.Message, TipoMensaje.MsgAdvertencia)
|
|
' Else
|
|
' Alert("Ocurrió un error al generar la descarga. Favor de contactar a soporte tecnico cod'IMPDFclspag'", TipoMensaje.MsgAdvertencia)
|
|
' End If
|
|
' End Try
|
|
'End If
|
|
|
|
Try
|
|
bytes = bytes
|
|
Response.Buffer = True
|
|
Response.Clear()
|
|
Response.ContentType = mimeType
|
|
Response.AddHeader("content-disposition", String.Format("{0}; filename={1}.{2}", Content_Disposition, NombreArchivo, If(Formato = "PDF", "pdf", "xls")))
|
|
Response.BinaryWrite(bytes) ' create the file
|
|
Response.Flush() ' send it to the client to download
|
|
HttpContext.Current.Response.SuppressContent = True
|
|
HttpContext.Current.ApplicationInstance.CompleteRequest()
|
|
HttpContext.Current.Response.End()
|
|
bytes = Nothing
|
|
Catch ex As Exception
|
|
|
|
Alert("Ocurrió un error al generar la descarga. Favor de contactar a soporte tecnico cod:'IMPDFclspag'", TipoMensaje.MsgAdvertencia)
|
|
|
|
End Try
|
|
End Sub
|
|
Dim Response As HttpResponse
|
|
Private Function Getetiquetas(context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim params As New List(Of ReportParameter)
|
|
params.Add(New ReportParameter("Envase", "1 1/9"))
|
|
params.Add(New ReportParameter("Tamano", "Small"))
|
|
params.Add(New ReportParameter("Cultivo", "Tomate"))
|
|
params.Add(New ReportParameter("noPallet", "000001"))
|
|
Response = context.Response
|
|
Dim tablaReporte As New DataTable
|
|
'"Empresas/Grales/Formatos/EquiposGPS.rdlc"
|
|
'"D:\\ADSistemas\\Proyectos\\SIG\\SIGIT\\GPS\\PalletEtiqueta.rdlc"
|
|
ImprimirPDF("GPS/PalletEtiqueta.rdlc", (New List(Of ReportDataSource)), params, "Equipo GPS")
|
|
Return retorno
|
|
End Function
|
|
Private Function GetTokenAngular(context As HttpContext) As String
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim tokenDescriptor = New Microsoft.IdentityModel.Tokens.SecurityTokenDescriptor With {
|
|
.Subject = New System.Security.Claims.ClaimsIdentity(New System.Security.Claims.Claim() {New System.Security.Claims.Claim("CvePlataforma", usuario.CvePlataforma.ToString()),
|
|
New System.Security.Claims.Claim("CveUsuario", usuario.CveUsuario.ToString()), New System.Security.Claims.Claim("CveEmpresa", usuario.CveEmpresa.ToString()),
|
|
New System.Security.Claims.Claim("CveRol", usuario.CveRol.ToString()), New System.Security.Claims.Claim("Fecha", Date.Now.ToLongDateString())}),
|
|
.Expires = Date.UtcNow.AddHours(3),
|
|
.SigningCredentials = New Microsoft.IdentityModel.Tokens.SigningCredentials(
|
|
New Microsoft.IdentityModel.Tokens.SymmetricSecurityKey(Encoding.ASCII.GetBytes("*_AsistenciaDesarrolloSistemas-SIGAPI_*17-06-2020")),
|
|
Microsoft.IdentityModel.Tokens.SecurityAlgorithms.HmacSha256Signature)}
|
|
Dim tokenHandler = New System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler()
|
|
Dim newtoken = tokenHandler.CreateToken(tokenDescriptor)
|
|
Dim stokenn As String = tokenHandler.WriteToken(newtoken)
|
|
Return stokenn
|
|
|
|
End Function
|
|
Private Function sendMailLPM(context As HttpContext) As String
|
|
Dim retorno As String = "true"
|
|
Dim nombre As String = ""
|
|
Dim correo As String = ""
|
|
Dim asunto As String = ""
|
|
Dim cuerpo As String = ""
|
|
Dim obj = context.Request("Nombre") 'Nombre=' + $('#Nombre').val() +'Correo=' + $('#Correo').val() +'Sitio=' + $('#Sitio').val() +'Cuerpo=' + $('#Cuerpo').val() +
|
|
If Not IsNothing(obj) Then
|
|
nombre = obj.ToString()
|
|
End If
|
|
obj = context.Request("Correo").Trim()
|
|
If Not IsNothing(obj) Then
|
|
correo = obj.ToString()
|
|
End If
|
|
obj = context.Request("Asunto").Trim()
|
|
If Not IsNothing(obj) Then
|
|
asunto = obj.ToString()
|
|
End If
|
|
obj = context.Request("Cuerpo").Trim()
|
|
If Not IsNothing(obj) Then
|
|
cuerpo = obj.ToString().Replace("< ", "<").Trim()
|
|
End If
|
|
Dim Body As String = String.Format("Prospecto : {0}<br/>Correo : {1}<br/>Asunto : {2}<br/><br/>{3}", nombre, correo, asunto, cuerpo)
|
|
Dim para As String = "contacto@localizacionprecisa.com;caudillo.90d@gmail.com;"
|
|
'para = ""
|
|
Dim Mail As New ClsSisMail()
|
|
If (nombre.Length > 0 Or correo.Length > 0) AndAlso Mail.SendMail(ClsPaginas.EmpresaNotificaciones, para, "Notificación prospecto", Body) Then
|
|
retorno = "true"
|
|
Else
|
|
retorno = "false"
|
|
End If
|
|
Return retorno
|
|
End Function
|
|
|
|
Private Function sendMailEMD(context As HttpContext) As String
|
|
Dim retorno As String = "true"
|
|
Dim nombre As String = ""
|
|
Dim correo As String = ""
|
|
Dim Phone As String = ""
|
|
Dim cuerpo As String = ""
|
|
Dim obj = context.Request("Nombre") 'Nombre=' + $('#Nombre').val() +'Correo=' + $('#Correo').val() +'Sitio=' + $('#Sitio').val() +'Cuerpo=' + $('#Cuerpo').val() +
|
|
If Not IsNothing(obj) Then
|
|
nombre = obj.ToString().Trim()
|
|
End If
|
|
obj = context.Request("Correo")
|
|
If Not IsNothing(obj) Then
|
|
correo = obj.ToString().Trim()
|
|
End If
|
|
obj = context.Request("Phone")
|
|
If Not IsNothing(obj) Then
|
|
Phone = obj.ToString().Trim()
|
|
End If
|
|
obj = context.Request("Cuerpo")
|
|
If Not IsNothing(obj) Then
|
|
cuerpo = obj.ToString().Replace("< ", "<").Trim()
|
|
End If
|
|
Dim Body As String = String.Format("Solicitó : {0}<br/>Correo : {1}<br/>Telefono : {2}<br/><br/>{3}", nombre, correo, Phone, cuerpo)
|
|
Dim para As String = "paola@adssistemas.mx;caudillo.90d@gmail.com;"
|
|
'para = ""
|
|
Dim Mail As New ClsSisMail()
|
|
If (nombre.Length > 0 Or correo.Length > 0) AndAlso Mail.SendMail(ClsPaginas.EmpresaNotificaciones, para, "Notificación contacto pagina", Body) Then
|
|
retorno = "true"
|
|
Else
|
|
retorno = "false"
|
|
End If
|
|
Return retorno
|
|
End Function
|
|
|
|
Private Function sendMail(context As HttpContext) As String
|
|
Dim retorno As String = "true"
|
|
Dim nombre As String = ""
|
|
Dim correo As String = ""
|
|
Dim sitio As String = ""
|
|
Dim cuerpo As String = ""
|
|
Dim obj = context.Request("Nombre") 'Nombre=' + $('#Nombre').val() +'Correo=' + $('#Correo').val() +'Sitio=' + $('#Sitio').val() +'Cuerpo=' + $('#Cuerpo').val() +
|
|
If Not IsNothing(obj) Then
|
|
nombre = obj.ToString().Trim()
|
|
End If
|
|
obj = context.Request("Correo").Trim()
|
|
If Not IsNothing(obj) Then
|
|
correo = obj.ToString()
|
|
End If
|
|
obj = context.Request("Sitio").Trim()
|
|
If Not IsNothing(obj) Then
|
|
sitio = obj.ToString()
|
|
End If
|
|
obj = context.Request("Cuerpo").Trim()
|
|
If Not IsNothing(obj) Then
|
|
cuerpo = obj.ToString().Replace("< ", "<").Trim()
|
|
End If
|
|
Dim Body As String = String.Format("Prospecto : {0}<br/>Correo : {1}<br/>Sitio : {2}<br/><br/>{3}", nombre, correo, sitio, cuerpo)
|
|
Dim para As String = "rene.molina@adssistemas.mx,sig.buzon@gmail.com,julian@adssistemas.mx;paola@adssistemas.mx;caudillo.90d@gmail.com;"
|
|
'para = ""
|
|
Dim Mail As New ClsSisMail()
|
|
If (nombre.Length > 0 Or correo.Length > 0) AndAlso Mail.SendMail(ClsPaginas.EmpresaNotificaciones, para, "NotificaciónProspecto", Body) Then
|
|
retorno = "true"
|
|
Else
|
|
retorno = "false"
|
|
End If
|
|
Return retorno
|
|
End Function
|
|
|
|
Private Sub GetUser(ByVal context As HttpContext)
|
|
Dim usuario As String = context.Request("usuario").ToString()
|
|
Dim CveUsuario As Integer = -1
|
|
Dim objs As New ClsSisUsuarios
|
|
objs.GetWSusuarios(usuario)
|
|
If objs.DtResultados.Rows.Count > 0 Then
|
|
CveUsuario = objs.DtResultados.Rows(0)("CveUsuario").ToString().ToEntero()
|
|
End If
|
|
objs.Dispose()
|
|
If CveUsuario > 0 Then
|
|
CveUsuario = 1
|
|
End If
|
|
|
|
context.Response.Write(CveUsuario.ToString())
|
|
context.Response.StatusCode = 200
|
|
End Sub
|
|
|
|
Private Sub ActualizaPrePoliza(ByVal context As HttpContext)
|
|
Dim CvePrePoliza As Integer = context.Request("CvePrePoliza").ToString.ToEntero
|
|
Dim CveEmpresa As Integer = context.Request("CveEmpresa").ToString.ToEntero
|
|
Dim CveUsuario As Integer = context.Request("CveUsuario").ToString.ToEntero
|
|
Dim Empresa As New Empresa
|
|
|
|
Dim Retorno As Integer = 0
|
|
|
|
Dim ObjEmpresa As New ClsSisEmpresas()
|
|
If ObjEmpresa.GetEmpresas(CveEmpresa, "-1", "-1", "-1", "-1") Then
|
|
Empresa = ObjEmpresa.Empresa
|
|
End If
|
|
ObjEmpresa.Dispose()
|
|
Dim IdPoliza As Integer = -1
|
|
|
|
Dim ObjConta As New ClsContabilidad
|
|
Try
|
|
ObjConta.GetPrePoliza(CvePrePoliza, CveEmpresa)
|
|
IdPoliza = ObjConta.DtResultados.FiltroPrimeroValor("IdPoliza", "").ToEntero
|
|
If IdPoliza > 0 Then
|
|
ObjConta.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False)
|
|
End If
|
|
|
|
If ObjConta.ContabilizarPrePoliza(CvePrePoliza, CveUsuario, Empresa, pIDPoliza:=If(IdPoliza > 0, IdPoliza, -1)) Then
|
|
Retorno = 200
|
|
End If
|
|
Catch ex As Exception
|
|
GuardaLogAD(ex.ToString())
|
|
End Try
|
|
ObjConta.Dispose()
|
|
|
|
Empresa = Nothing
|
|
'context.Response.Write(CveUsuario.ToString())
|
|
context.Response.StatusCode = Retorno
|
|
End Sub
|
|
|
|
Private Sub GetImg(ByVal context As HttpContext)
|
|
Dim Url As String = Decripta(context.Request("r").ToString)
|
|
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
If Not IsNothing(usuario) Then
|
|
Url = String.Format("{0}Empresas\{1}\{2}", ModExtensiones.DirectorioBaseEmpresas, usuario.CveEmpresa, Url)
|
|
Dim FileInfo As FileInfo = New FileInfo(Url)
|
|
If FileInfo.Exists Then
|
|
context.Response.ContentType = "image/png"
|
|
context.Response.Flush()
|
|
context.Response.WriteFile(FileInfo.FullName)
|
|
context.Response.End()
|
|
End If
|
|
FileInfo = Nothing
|
|
Url = ""
|
|
End If
|
|
End Sub
|
|
|
|
#Region "File"
|
|
|
|
Private Sub Downfile(ByVal context As HttpContext)
|
|
Dim savepath As String = ""
|
|
Dim tempPath As String = ""
|
|
tempPath = String.Format("{0}{1}", System.Configuration.ConfigurationManager.AppSettings("FolderPath"), "/Temp")
|
|
savepath = context.Server.MapPath(tempPath)
|
|
Dim nombre As String = String.Format("{0}\{1}", savepath, context.Request("nombre"))
|
|
File.Delete(nombre)
|
|
tempPath = ""
|
|
savepath = ""
|
|
context.Response.StatusCode = 200
|
|
End Sub
|
|
|
|
Private Sub uploadfile(ByVal context As HttpContext)
|
|
Dim postedFile As HttpPostedFile
|
|
Dim savepath As String = ""
|
|
Dim tempPath As String = ""
|
|
tempPath = String.Format("{0}{1}", System.Configuration.ConfigurationManager.AppSettings("FolderPath"), "/Temp")
|
|
savepath = context.Server.MapPath(tempPath)
|
|
Dim filename As String
|
|
Dim tick As String
|
|
tick = (DateTime.Now.Ticks + 1).ToString()
|
|
If Not Directory.Exists(savepath) Then
|
|
Directory.CreateDirectory(savepath)
|
|
End If
|
|
If context.Request.Files.Count = 0 Then
|
|
Dim copyFile As String = context.Request("File")
|
|
Dim Cve As String = context.Request("Cve")
|
|
|
|
If copyFile <> "" Then
|
|
Dim ext As Integer = copyFile.IndexOf(","c) + 1
|
|
|
|
Dim extension As String = copyFile.Substring(5, ext - 5)
|
|
If extension.Contains("image/") Then extension = extension.Replace("image/", "").Replace(";base64,", "")
|
|
'Dim extncion As String =
|
|
filename = String.Format("{0}-{1}.{2}", tick, Cve, extension)
|
|
|
|
Dim msf As New MemoryStream(Convert.FromBase64String(copyFile.Substring(ext)))
|
|
Dim stem As Stream = New FileStream(String.Format("{0}\{1}", savepath, filename), FileMode.Create)
|
|
msf.WriteTo(stem)
|
|
msf.Close()
|
|
stem.Close()
|
|
msf.Dispose()
|
|
stem.Dispose()
|
|
|
|
End If
|
|
Else
|
|
|
|
postedFile = context.Request.Files(0)
|
|
filename = String.Format("{0}-{1}", tick, postedFile.FileName)
|
|
|
|
postedFile.SaveAs(String.Format("{0}\{1}", savepath, filename))
|
|
End If
|
|
context.Response.Write(tick)
|
|
context.Response.StatusCode = 200
|
|
savepath = ""
|
|
tempPath = "" : filename = ""
|
|
postedFile = Nothing
|
|
End Sub
|
|
#End Region
|
|
|
|
|
|
Private Shared Function sendURL(ByVal URL As String, Optional Methodo As String = "POST", Optional Cookie As String = "", Optional maxTimeMilliseconds As Integer = 120000) As String
|
|
Dim resultado As String = ""
|
|
|
|
Try
|
|
Dim request As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create(URL), Net.HttpWebRequest)
|
|
request.Timeout = maxTimeMilliseconds
|
|
request.Method = Methodo
|
|
request.ContentType = "text/html; charset=utf-8" '"text/xml; charset=utf-8"
|
|
|
|
If Not String.IsNullOrEmpty(Cookie) Then
|
|
request.Headers.Add("Cookie", Cookie)
|
|
End If
|
|
|
|
'Using stream As IO.Stream = request.GetRequestStream()
|
|
|
|
' Using stmw As IO.StreamWriter = New IO.StreamWriter(stream)
|
|
' stmw.Write("")
|
|
' End Using
|
|
'End Using
|
|
|
|
Dim response As Net.WebResponse = CType(request.GetResponse(), Net.WebResponse)
|
|
Dim sr As IO.StreamReader = New IO.StreamReader(response.GetResponseStream())
|
|
resultado = sr.ReadToEnd()
|
|
sr.Close()
|
|
Catch ex As Exception
|
|
ex.ToString().GuardaLog()
|
|
'Extenciones.ApplicationParameter.GuardaLogEx(ex, $"SOAPAction : {SOAPAction} XML : {xml}")
|
|
End Try
|
|
|
|
Return resultado
|
|
End Function
|
|
|
|
Public Shared Function GettingCURP(ByVal Curp As String, year As Integer) As String
|
|
Dim abc As String() = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
|
|
Dim numeric01 As String() = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
|
|
Dim rule1 As String() = If(year < 2000, numeric01, abc)
|
|
Dim curpresult As String = ""
|
|
Dim i As Integer = 0
|
|
While curpresult.Length = 0 AndAlso i < rule1.Length
|
|
Dim z As Integer = 0
|
|
While curpresult.Length = 0 AndAlso z < numeric01.Length
|
|
curpresult = String.Format("{0}{1}{2}", Curp, rule1(i), numeric01(z))
|
|
Dim respuesta As String = sendURL(String.Format("http://www.renapo.sep.gob.mx/wsrenapo/MainControllerParam?curp={0}", curpresult), "GET")
|
|
|
|
Dim trlines As New List(Of String)
|
|
Dim keydict As New System.Collections.Concurrent.ConcurrentDictionary(Of String, String)
|
|
|
|
Dim indexttr As Integer = 0
|
|
Dim indexttrB As Integer = 0
|
|
Dim indexttd As Integer = 0
|
|
Dim indextdiv As Integer = 0
|
|
Dim indexinittext As Integer = 0
|
|
While Not IsNothing(respuesta) AndAlso respuesta.Length > 0
|
|
indexttr = respuesta.IndexOf("<tr")
|
|
If indexttr >= 0 Then
|
|
indexttrB = respuesta.Substring(indexttr + 3).IndexOf("<tr")
|
|
If indexttrB >= 0 Then
|
|
trlines.Add(respuesta.Substring(indexttr, indexttrB))
|
|
Else
|
|
trlines.Add(respuesta.Substring(indexttr))
|
|
|
|
End If
|
|
respuesta = respuesta.Substring(indexttr + 3)
|
|
Else
|
|
respuesta = ""
|
|
End If
|
|
|
|
End While
|
|
|
|
Dim key As String = ""
|
|
Dim keyvalue As String = ""
|
|
For Each item As String In trlines
|
|
key = ""
|
|
keyvalue = ""
|
|
indexttd = item.IndexOf("<td")
|
|
indextdiv = item.IndexOf("<div")
|
|
If indextdiv >= 0 Then
|
|
indexttr = indextdiv
|
|
indexttrB = item.IndexOf("</div")
|
|
Else
|
|
indexttr = indexttd
|
|
indexttrB = item.IndexOf("</td")
|
|
End If
|
|
If indexttr >= 0 Then
|
|
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
|
|
key = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
|
|
|
|
item = item.Substring(indexttrB + 3)
|
|
Else
|
|
item = ""
|
|
End If
|
|
|
|
If item.Length > 0 Then
|
|
|
|
indexttd = item.IndexOf("<td")
|
|
indextdiv = item.IndexOf("<div")
|
|
If indextdiv >= 0 Then
|
|
indexttr = indextdiv
|
|
indexttrB = item.IndexOf("</div")
|
|
Else
|
|
indexttr = indexttd
|
|
indexttrB = item.IndexOf("</td")
|
|
End If
|
|
If indexttr >= 0 Then
|
|
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
|
|
keyvalue = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
|
|
|
|
item = item.Substring(indexttr + 3)
|
|
Else
|
|
item = ""
|
|
End If
|
|
|
|
End If
|
|
If key.Length > 0 Then
|
|
keydict.TryAdd(key.Replace(":", "").Trim(), keyvalue.Trim().ToLower())
|
|
End If
|
|
Next
|
|
Dim Apellido1 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
|
|
Dim Apellido2 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
|
|
Dim Nombres As String = "" : keydict.TryGetValue("Nombres", Nombres)
|
|
If Nombres Is Nothing OrElse Nombres.Length = 0 Then
|
|
curpresult = ""
|
|
End If
|
|
System.Threading.Thread.Sleep(100)
|
|
z = z + 1
|
|
End While
|
|
i = i + 1
|
|
End While
|
|
Return curpresult
|
|
End Function
|
|
|
|
|
|
Public Shared Function ValidaCURP(ByVal Curp As String) As String
|
|
|
|
Dim respuesta As String = sendURL(String.Format("http://www.renapo.sep.gob.mx/wsrenapo/MainControllerParam?curp={0}", Curp), "GET")
|
|
|
|
Dim trlines As New List(Of String)
|
|
Dim keydict As New System.Collections.Concurrent.ConcurrentDictionary(Of String, String)
|
|
|
|
Dim indexttr As Integer = 0
|
|
Dim indexttrB As Integer = 0
|
|
Dim indexttd As Integer = 0
|
|
Dim indextdiv As Integer = 0
|
|
Dim indexinittext As Integer = 0
|
|
While Not IsNothing(respuesta) AndAlso respuesta.Length > 0
|
|
indexttr = respuesta.IndexOf("<tr")
|
|
If indexttr >= 0 Then
|
|
indexttrB = respuesta.Substring(indexttr + 3).IndexOf("<tr")
|
|
If indexttrB >= 0 Then
|
|
trlines.Add(respuesta.Substring(indexttr, indexttrB))
|
|
Else
|
|
trlines.Add(respuesta.Substring(indexttr))
|
|
|
|
End If
|
|
respuesta = respuesta.Substring(indexttr + 3)
|
|
Else
|
|
respuesta = ""
|
|
End If
|
|
|
|
End While
|
|
|
|
Dim key As String = ""
|
|
Dim keyvalue As String = ""
|
|
For Each item As String In trlines
|
|
key = ""
|
|
keyvalue = ""
|
|
indexttd = item.IndexOf("<td")
|
|
indextdiv = item.IndexOf("<div")
|
|
If indextdiv >= 0 Then
|
|
indexttr = indextdiv
|
|
indexttrB = item.IndexOf("</div")
|
|
Else
|
|
indexttr = indexttd
|
|
indexttrB = item.IndexOf("</td")
|
|
End If
|
|
If indexttr >= 0 Then
|
|
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
|
|
key = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
|
|
|
|
item = item.Substring(indexttrB + 3)
|
|
Else
|
|
item = ""
|
|
End If
|
|
|
|
If item.Length > 0 Then
|
|
|
|
indexttd = item.IndexOf("<td")
|
|
indextdiv = item.IndexOf("<div")
|
|
If indextdiv >= 0 Then
|
|
indexttr = indextdiv
|
|
indexttrB = item.IndexOf("</div")
|
|
Else
|
|
indexttr = indexttd
|
|
indexttrB = item.IndexOf("</td")
|
|
End If
|
|
If indexttr >= 0 Then
|
|
indexinittext = item.Substring(indexttr + 3).IndexOf(">")
|
|
keyvalue = item.Substring(indexinittext + indexttr + 4, (indexttrB - (indexinittext + indexttr + 4)))
|
|
|
|
item = item.Substring(indexttr + 3)
|
|
Else
|
|
item = ""
|
|
End If
|
|
|
|
End If
|
|
If key.Length > 0 Then
|
|
keydict.TryAdd(key.Replace(":", "").Trim(), keyvalue.Trim().ToLower())
|
|
End If
|
|
Next
|
|
Dim Apellido1 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
|
|
Dim Apellido2 As String = "" : keydict.TryGetValue("Apellido1", Apellido1)
|
|
Dim Nombres As String = "" : keydict.TryGetValue("Nombres", Nombres)
|
|
If Nombres Is Nothing OrElse Nombres.Length = 0 Then
|
|
Curp = ""
|
|
End If
|
|
|
|
Return Curp
|
|
End Function
|
|
#Region "Get Cliente"
|
|
Private Function GetClientes(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim DtRetorno As DataTable = Nothing
|
|
Dim ColumnaNombre As String = "NombreComercial"
|
|
'Abreviaturas. N. Nombre, NC. NombreComercial,...
|
|
If IfNull(context.Request("ColTexto"), "") = "N" Then
|
|
ColumnaNombre = "Nombre"
|
|
End If
|
|
|
|
Dim EsDistribuidor As Integer = IfNull(context.Request("esdistribuidor"), "-1").ToString.ToEntero
|
|
|
|
Dim cveclienteclasificacion = IfNull(context.Request("cveclienteclasificacion"), "-1").ToString.ToEntero
|
|
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim CveEmpresa As String
|
|
If IsNothing(usuario) Then
|
|
context.Response.Write("")
|
|
Else
|
|
CveEmpresa = usuario.CveEmpresa
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
Dim AppNombre As String = String.Format("GlobalDTCliente-{0}", CveEmpresa)
|
|
'sino existe, recarga los datos
|
|
If context.Application(AppNombre) Is Nothing Then
|
|
Dim ObjClientes As New ClsClientes
|
|
If ObjClientes.GetClientes(-1, "-1", "-1", "-1", "-1", "-1", "-1", -1, CveEmpresa, Estatus:=-1, CveClienteClasificacion:=cveclienteclasificacion) Then
|
|
context.Application(AppNombre) = ObjClientes.DtResultados
|
|
End If
|
|
ObjClientes.Dispose()
|
|
End If
|
|
|
|
'Dim ObjClientes As New ClsClientes
|
|
'If ObjClientes.GetClientes(-1, Name, "-1", "-1", "-1", "-1", "-1", -1, CveEmpresa, Estatus:=-1) Then
|
|
' DtRetorno = ObjClientes.DtResultados
|
|
'End If
|
|
'ObjClientes.Dispose()
|
|
|
|
Dim dt As DataTable = DirectCast(context.Application(AppNombre), DataTable) '.FiltraParametros(String.Format("CveEmpresa = {0}", CveEmpresa))
|
|
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
|
|
If EsDistribuidor <> -1 Then
|
|
dt = dt.FiltraParametros(String.Format("EsDistribuidor = {0} ", CBool(EsDistribuidor)))
|
|
End If
|
|
|
|
DtRetorno = dt.FiltraParametros(String.Format("NombreComercial like '%{0}%' OR Nombre like '%{0}%' ", Name))
|
|
dt.Dispose()
|
|
End If
|
|
|
|
End If
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
Dim i As Integer = 0 'limpieza de columnas
|
|
While i < DtRetorno.Columns.Count
|
|
If Not DtRetorno.Columns(i).ColumnName.Contiene("CveCliente", ColumnaNombre) Then
|
|
DtRetorno.Columns.RemoveAt(i)
|
|
Else
|
|
i = i + 1
|
|
End If
|
|
End While
|
|
|
|
DtRetorno.Columns("CveCliente").ColumnName = "id"
|
|
DtRetorno.Columns(ColumnaNombre).ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
DtRetorno.Dispose()
|
|
DtRetorno = Nothing
|
|
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
#Region "Get Proveedor"
|
|
Private Function GetProveedores(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim DtRetorno As DataTable = Nothing
|
|
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim CveEmpresa As String
|
|
If IsNothing(usuario) Then
|
|
context.Response.Write("")
|
|
Else
|
|
CveEmpresa = usuario.CveEmpresa
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
Dim AppNombre As String = String.Format("GlobalDTCompProveedores-{0}", CveEmpresa)
|
|
'sino existe, recarga los datos
|
|
If context.Application(AppNombre) Is Nothing Then
|
|
Dim ObjProveedores As New ClsCompProveedores
|
|
If ObjProveedores.GetProveedores(ClsCompProveedores.TipoConsulta.ParaGlobalDT, -1, "-1", "-1", "-1", "-1", "-1", "-1", "-1", -1, CveEmpresa) Then
|
|
context.Application(AppNombre) = ObjProveedores.DtResultados
|
|
End If
|
|
ObjProveedores.Dispose()
|
|
End If
|
|
|
|
'Dim ObjProveedores As New ClsCompProveedores
|
|
'If ObjProveedores.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, -1, "-1", Name, "-1", "-1", "-1", "-1", "-1", -1, CveEmpresa) Then
|
|
' DtRetorno = ObjProveedores.DtResultados
|
|
'End If
|
|
'ObjProveedores.Dispose()
|
|
Dim dt As DataTable = DirectCast(context.Application(AppNombre), DataTable) '.FiltraParametros(String.Format("CveEmpresa = {0}", CveEmpresa))
|
|
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
|
|
DtRetorno = dt.FiltraParametros(String.Format("NombreCortoProveedor like '%{0}%'", Name))
|
|
End If
|
|
dt.Dispose()
|
|
End If
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
Dim i As Integer = 0 'limpieza de columnas
|
|
While i < DtRetorno.Columns.Count
|
|
If Not DtRetorno.Columns(i).ColumnName.Contiene("CveProveedor", "NombreCortoProveedor") Then
|
|
DtRetorno.Columns.RemoveAt(i)
|
|
Else
|
|
i = i + 1
|
|
End If
|
|
End While
|
|
|
|
DtRetorno.Columns("CveProveedor").ColumnName = "id"
|
|
DtRetorno.Columns("NombreCortoProveedor").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
DtRetorno.Dispose()
|
|
DtRetorno = Nothing
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
|
|
#Region " GET PS "
|
|
Private Function getpsalmacen(ByVal context As HttpContext) As String
|
|
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim CveEmpresa As String
|
|
Dim retorno As String = ""
|
|
Dim DtPSRetorno As DataTable = Nothing
|
|
|
|
If IsNothing(usuario) Then
|
|
context.Response.Write("")
|
|
Else
|
|
CveEmpresa = usuario.CveEmpresa
|
|
|
|
DtPSRetorno = New DataTable
|
|
DtPSRetorno.Columns.Add(New DataColumn("id", System.Type.GetType("System.Int32")))
|
|
DtPSRetorno.Columns.Add(New DataColumn("existencia", System.Type.GetType("System.Int32")))
|
|
DtPSRetorno.Columns.Add(New DataColumn("almacen", System.Type.GetType("System.String")))
|
|
|
|
Dim CvePS = IfNull(context.Request("cveps"), "0").ToString.ToEntero
|
|
Dim objInv As New ClsInventarios
|
|
If objInv.GetExistenciasProducto(CvePS, -1, CveEmpresa, -1, FechaMovto:=DateTime.Today.AddDays(1).ToString("yyyy/MM/dd HH:mm")) Then
|
|
|
|
' limpio los almacenes donde no tiene ningun producto existencia
|
|
For i = objInv.DtResultados.Columns.Count - 1 To 1 Step -1
|
|
|
|
If Not objInv.DtResultados.Columns(i).ColumnName.Contiene("CveAlmacen", "Almacen", "Existencia") Then
|
|
objInv.DtResultados.Columns.RemoveAt(i)
|
|
End If
|
|
Next
|
|
|
|
DtPSRetorno = objInv.DtResultados.FiltraParametros("CveAlmacen > 0 and Existencia > 0")
|
|
End If
|
|
|
|
objInv.Dispose()
|
|
|
|
End If
|
|
|
|
If DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0 Then
|
|
DtPSRetorno.Columns("CveAlmacen").ColumnName = "id"
|
|
DtPSRetorno.Columns("Almacen").ColumnName = "almacen"
|
|
DtPSRetorno.Columns("Existencia").ColumnName = "existencia"
|
|
retorno = JsonConvert.SerializeObject(DtPSRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
DtPSRetorno.Dispose()
|
|
|
|
Return retorno
|
|
End Function
|
|
|
|
Private Function GETPS(ByVal context As HttpContext, Optional PSCodigoDescripcion As String = "PSCodigo") As String
|
|
Dim retorno As String = ""
|
|
Dim DtPSRetorno As DataTable = Nothing
|
|
|
|
'NOTA:
|
|
' EN EL WHERE DE LINQ NO SE DEBE USAS EL OPERADOR 'AND' SABE PORQUE FUNCIONA DIFERENTE SE DEBE USAR 'ANDALSO',
|
|
' EJEMPLO UNA CONDICION AND DE DOS CAMPOS ARROJA CERO RESULTADOS PERO SI SE PONE ESTAS DOS CONDICIONES POR SEPARADO ARROJA DATOS
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim CveEmpresa As String
|
|
If IsNothing(usuario) Then
|
|
context.Response.Write("")
|
|
Else
|
|
CveEmpresa = usuario.CveEmpresa
|
|
Dim FuePorXml = IfNull(context.Request("FuePorXml"), "-1").ToString.ToEntero
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
Dim CveClasificacion = IfNull(context.Request("CveClasificacion"), "-1").ToString.ToEntero
|
|
Dim CveSubFamilia = IfNull(context.Request("CveSubFamilia"), "-1").ToString.ToEntero
|
|
Dim CveClasificacionPresupuesto = IfNull(context.Request("CveClasificacionPresupuesto"), "-1").ToString.ToEntero
|
|
Dim Pagina = IfNull(context.Request("Pagina"), "-1").ToString
|
|
Dim Estatus = IfNull(context.Request("Estatus"), "1").ToString
|
|
Dim CveSucursal = IfNull(context.Request("cvesucursal"), "-1").ToString.ToEntero
|
|
Dim CveSubProyecto = IfNull(context.Request("cvesubproyecto"), "-1").ToString.ToEntero
|
|
Dim UsoClasificacion = IfNull(context.Request("usoclasificacion"), "-1").ToString.ToEntero
|
|
Dim AplicaParaVenta = IfNull(context.Request("aplicaparaventa"), "1").ToString.ToEntero
|
|
Dim CveMarca = IfNull(context.Request("cvemarca"), "-1").ToString.ToEntero
|
|
|
|
Dim UsaGlobal As Boolean = True
|
|
|
|
'verifica existencias
|
|
If Pagina.Contiene("ventas/ventas", "oc/oc", "inv/traspaso") AndAlso CveEmpresa.Contiene(72, 80, 119, 140, 141, 152, 153, 159, 160, 161, 162, 163, 166) Then
|
|
UsaGlobal = False
|
|
|
|
'If CveEmpresa.Contiene(140, 141) And Pagina.Contiene("ventas/ventas") Then
|
|
' AplicaParaVenta = 1
|
|
'End If
|
|
|
|
Dim objInv As New ClsInventarios
|
|
If objInv.GetExistenciasProductosLike(Name, CveClasificacion, CveSubProyecto, Estatus.ToEntero, AplicaParaVenta, CveEmpresa, CveMarca) Then
|
|
|
|
' limpio los almacenes donde no tiene ningun producto existencia
|
|
|
|
Dim i As Integer = 0
|
|
While i < objInv.DtResultados.Columns.Count
|
|
|
|
If Not objInv.DtResultados.Columns(i).ColumnName.Contiene("CvePS", "PSCodigo", "PSCodigoClasificacion", "CveClasificacion") AndAlso objInv.DtResultados.SUM(String.Format("[{0}]", objInv.DtResultados.Columns(i).ColumnName)) = 0 Then
|
|
objInv.DtResultados.Columns.RemoveAt(i)
|
|
Else
|
|
i = i + 1
|
|
End If
|
|
End While
|
|
|
|
DtPSRetorno = objInv.DtResultados
|
|
|
|
End If
|
|
|
|
objInv.Dispose()
|
|
|
|
End If
|
|
|
|
If usuario.Empresa.Funcionalidad(558) = "1" AndAlso DtPSRetorno IsNot Nothing Then
|
|
Try
|
|
Dim NombreFiltroColumna As String = DtPSRetorno.Columns(3).ColumnName
|
|
DtPSRetorno = DtPSRetorno.FiltraParametros("", String.Format("{0} DESC,PSCodigo", NombreFiltroColumna))
|
|
Catch ex As Exception
|
|
End Try
|
|
|
|
End If
|
|
|
|
If UsaGlobal Then
|
|
'se recarga el global, y el clspaginas, son los unicos 2 lugares
|
|
Dim AppNombre As String = String.Format("GlobalDTPSSimplificado-{0}", CveEmpresa)
|
|
If context.Application(String.Format("GlobalDTPSSimplificado-{0}", CveEmpresa)) Is Nothing Then
|
|
Dim ObjPS As New ClsProductosServicios
|
|
If ObjPS.GetPSSimplificado(CveEmpresa) Then context.Application(AppNombre) = ObjPS.DtResultados.AsEnumerable()
|
|
ObjPS.Dispose()
|
|
|
|
End If
|
|
|
|
|
|
Dim DTPS = DirectCast(context.Application(AppNombre), EnumerableRowCollection(Of DataRow))
|
|
'Dim DTPS = ClsPaginas.GlobalDTPSSimplificado(CveEmpresa).AsEnumerable
|
|
|
|
If DTPS IsNot Nothing Then
|
|
|
|
|
|
'APLICACION DE FILTROS
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveEmpresa) = CveEmpresa))
|
|
If Estatus = 1 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveEstado) = 1))
|
|
ElseIf Estatus = -1 Then
|
|
|
|
End If
|
|
|
|
'If FuePorXml >= 0 Then
|
|
' DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!FuePorXML) = FuePorXml))
|
|
'End If
|
|
|
|
If Name <> "-1" Then
|
|
If PSCodigoDescripcion = "PSCodigo" Then
|
|
DTPS = DTPS.Where((Function(a) a!PSCodigo.ToString.ToLower Like ("*" + Name.ToLower + "*")))
|
|
Else
|
|
DTPS = DTPS.Where((Function(a) a!PSCodigoClasificacion.ToString.ToLower Like ("*" + Name.ToLower + "*")))
|
|
End If
|
|
End If
|
|
|
|
If CveClasificacion > 0 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveClasificacion) = CveClasificacion))
|
|
ElseIf CveClasificacion = -1 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveClasificacion) >= 0))
|
|
End If
|
|
|
|
If AplicaParaVenta > 0 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!AplicaParaVenta) = 1))
|
|
End If
|
|
|
|
'If CveSubFamilia > 0 Then
|
|
' DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveSubFamilia) = CveSubFamilia))
|
|
' 'ElseIf CveSubFamilia = -1 Then
|
|
' 'DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveSubFamilia) > 0))
|
|
'End If
|
|
|
|
If CveClasificacionPresupuesto > 0 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveClasificacionPresupuesto) = CveClasificacionPresupuesto))
|
|
End If
|
|
|
|
If UsoClasificacion > 0 Then DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!UsoClasificacion) = UsoClasificacion))
|
|
|
|
If Pagina <> "-1" Then
|
|
If Pagina = "Compras" Then
|
|
DTPS = DTPS.Where((Function(a) a!CveTipoPS = 1 AndAlso a!CveEstado = 1))
|
|
ElseIf Pagina = "Compras2" Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveTipoPS) = 1 AndAlso (Convert.ToInt32(a!CveEstado) = 1 OrElse Convert.ToInt32(a!CveEstado) = 2)))
|
|
ElseIf Pagina = "Inventarios" Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveTipoPS) = 2))
|
|
End If
|
|
End If
|
|
|
|
'Try, generado para cuando el resultado no tiene valores(The source contains no DataRows.), no detenga la ejecucion, no se le puso un count previo, porque el costo se duplica, al preguntar y luego ordenar y convertir a datatable
|
|
Try
|
|
DtPSRetorno = New DataView(DTPS.OrderBy(Function(a) a!PSCodigo).CopyToDataTable).ToTable(True, {"CvePS", "PSCodigo", "PSCodigoClasificacion", "CveClasificacion"})
|
|
Catch ex As Exception
|
|
DtPSRetorno = Nothing
|
|
End Try
|
|
|
|
End If
|
|
DTPS = Nothing
|
|
End If
|
|
|
|
|
|
|
|
|
|
|
|
If (usuario.TienePermisoProceso(300) Or usuario.TienePermisoProceso(301)) And (DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0) Then
|
|
|
|
Dim ObjClasificaciones As New ClsClasificaciones()
|
|
Dim DTClasificacionesComprobaciones As DataTable
|
|
|
|
Dim DTTmp As DataTable = DtPSRetorno.Clone
|
|
|
|
|
|
If ObjClasificaciones.GetClasificacionesComprobaciones(usuario.CveEmpresa) Then
|
|
|
|
If usuario.TienePermisoProceso(300) And usuario.TienePermisoProceso(301) Then
|
|
DTClasificacionesComprobaciones = ObjClasificaciones.DtResultados
|
|
ElseIf usuario.TienePermisoProceso(300) Then 'TipoComprobacion 1 Viaticos
|
|
DTClasificacionesComprobaciones = ObjClasificaciones.DtResultados.FiltraParametros("TipoComprobacion = 1")
|
|
Else 'TipoComprobacion 2 caja chica
|
|
DTClasificacionesComprobaciones = ObjClasificaciones.DtResultados.FiltraParametros("TipoComprobacion = 2")
|
|
End If
|
|
|
|
For Each pRow As DataRow In DtPSRetorno.Rows
|
|
|
|
For Each drow As DataRow In DTClasificacionesComprobaciones.Rows
|
|
If pRow("CveClasificacion").ToString.ToEntero = drow("CveClasificacion").ToString.ToEntero Then
|
|
|
|
Dim nRow As DataRow = DTTmp.NewRow
|
|
nRow("CvePS") = pRow("CvePS")
|
|
nRow("PSCodigo") = pRow("PSCodigo")
|
|
nRow("PSCodigoClasificacion") = pRow("PSCodigoClasificacion")
|
|
nRow("CveClasificacion") = pRow("CveClasificacion")
|
|
DTTmp.Rows.Add(nRow)
|
|
|
|
|
|
End If
|
|
Next
|
|
|
|
Next
|
|
|
|
DtPSRetorno = DTTmp.Copy
|
|
|
|
Else
|
|
'no regresar datos error al consultar
|
|
DtPSRetorno.Clear()
|
|
End If
|
|
DTTmp.Dispose()
|
|
ObjClasificaciones.Dispose()
|
|
|
|
End If
|
|
|
|
|
|
|
|
If DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0 Then
|
|
|
|
|
|
DtPSRetorno.Columns("CvePS").ColumnName = "id"
|
|
DtPSRetorno.Columns(PSCodigoDescripcion).ColumnName = "text"
|
|
If PSCodigoDescripcion = "PSCodigo" Then
|
|
DtPSRetorno.Columns().Remove("PSCodigoClasificacion")
|
|
Else
|
|
DtPSRetorno.Columns().Remove("PSCodigo")
|
|
End If
|
|
|
|
retorno = JsonConvert.SerializeObject(DtPSRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
DtPSRetorno.Dispose()
|
|
DtPSRetorno = Nothing
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
|
|
|
|
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
|
|
Get
|
|
Return False
|
|
End Get
|
|
End Property
|
|
|
|
|
|
|
|
#Region "Funciones"
|
|
Public Function GetJson(ByVal dt As DataTable) As String
|
|
Dim Retorno As String = ""
|
|
Dim serializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()
|
|
Dim rows As New List(Of Dictionary(Of String, Object))
|
|
Dim row As Dictionary(Of String, Object)
|
|
|
|
For Each dr As DataRow In dt.Rows
|
|
row = New Dictionary(Of String, Object)
|
|
For Each col As DataColumn In dt.Columns
|
|
row.Add(col.ColumnName, dr(col))
|
|
Next
|
|
rows.Add(row)
|
|
Next
|
|
If dt IsNot Nothing Then dt.Dispose()
|
|
Retorno = serializer.Serialize(rows)
|
|
rows = Nothing
|
|
serializer = Nothing
|
|
Return Retorno
|
|
End Function
|
|
ReadOnly Property UsuarioActual(ByVal context As HttpContext) As Usuario
|
|
Get
|
|
UsuarioActual = DirectCast(context.Session("UsuarioSIG"), Usuario)
|
|
End Get
|
|
End Property
|
|
#End Region
|
|
|
|
|
|
#Region " GET PS SAT "
|
|
Private Function GETPSSAT(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
|
|
'Dim DTPS = DirectCast(context.Application("GlobalDTPSATPS"), EnumerableRowCollection(Of DataRow))
|
|
Dim DtPSRetorno As DataTable
|
|
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
|
|
'If Name <> "-1" Then
|
|
' DTPS = DTPS.Where((Function(a) a!SATClaveProductoServicio.ToString.ToLower Like ($"*{Name.ToLower}*")))
|
|
'End If
|
|
|
|
'DtPSRetorno = New DataView(DTPS.OrderBy(Function(a) a!SATClavePS).CopyToDataTable).ToTable(True, {"CveSATPS", "SATClaveProductoServicio"})
|
|
DtPSRetorno = ClsPaginas.GlobalDTPSATPS(Name.ToLower)
|
|
If DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0 Then
|
|
DtPSRetorno.Columns("CveSATPS").ColumnName = "id"
|
|
DtPSRetorno.Columns("SATClaveProductoServicio").ColumnName = "text"
|
|
'limpia las columnas
|
|
For Each dc As DataColumn In DtPSRetorno.Clone.Columns
|
|
If Not dc.ColumnName.Contiene("id", "text") Then DtPSRetorno.Columns.Remove(dc.ColumnName)
|
|
Next
|
|
|
|
retorno = JsonConvert.SerializeObject(DtPSRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
DtPSRetorno.Dispose()
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
|
|
#Region " GET UM SAT "
|
|
Private Function GETUMSAT(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
|
|
|
|
If context.Application("GlobalDTPSATUM") Is Nothing Then
|
|
Dim ObjGrales As New ClsGenerales
|
|
If ObjGrales.GetSATUnidadMedida Then context.Application("GlobalDTPSATUM") = ObjGrales.DtResultados.AsEnumerable() Else context.Application("GlobalDTPSATUM") = Nothing
|
|
ObjGrales.Dispose()
|
|
End If
|
|
|
|
Dim DTUM = DirectCast(context.Application("GlobalDTPSATUM"), EnumerableRowCollection(Of DataRow))
|
|
Dim DtPSRetorno As DataTable
|
|
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
|
|
If Name <> "-1" Then
|
|
DTUM = DTUM.Where((Function(a) a!ClaveNombre.ToString.ToLower Like ("*" + Name.ToLower + "*")))
|
|
End If
|
|
|
|
If DTUM.Count > 0 Then
|
|
DtPSRetorno = New DataView(DTUM.OrderBy(Function(a) a!Nombre).CopyToDataTable).ToTable(True, {"CveUnidadMedidaSAT", "ClaveNombre"})
|
|
Else
|
|
DtPSRetorno = Nothing
|
|
End If
|
|
|
|
If DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0 Then
|
|
DtPSRetorno.Columns("CveUnidadMedidaSAT").ColumnName = "id"
|
|
DtPSRetorno.Columns("ClaveNombre").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtPSRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
DtPSRetorno.Dispose()
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
#Region " GET SAT CARTA PORTE "
|
|
Private Function GETSATMaterialPeligroso(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
|
|
|
|
If context.Application("GlobalDTMaterialPeligroso") Is Nothing Then
|
|
Dim ObjGrales As New ClsGenerales
|
|
If ObjGrales.GetMaterialPeligroso Then context.Application("GlobalDTMaterialPeligroso") = ObjGrales.DtResultados Else context.Application("GlobalDTMaterialPeligroso") = Nothing
|
|
ObjGrales.Dispose()
|
|
End If
|
|
|
|
Dim DTUM = DirectCast(context.Application("GlobalDTMaterialPeligroso"), DataTable).AsEnumerable
|
|
Dim DtPSRetorno As DataTable
|
|
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
|
|
If Name <> "-1" Then
|
|
DTUM = DTUM.Where((Function(a) a!ClaveMaterialPeligrosoDescripcion.ToString.ToLower Like ("*" + Name.ToLower + "*")))
|
|
End If
|
|
|
|
If DTUM.Count > 0 Then
|
|
DtPSRetorno = New DataView(DTUM.OrderBy(Function(a) a!ClaveMaterialPeligrosoDescripcion).CopyToDataTable).ToTable(True, {"CveMaterialPeligroso", "ClaveMaterialPeligrosoDescripcion"})
|
|
Else
|
|
DtPSRetorno = Nothing
|
|
End If
|
|
|
|
If DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0 Then
|
|
DtPSRetorno.Columns("CveMaterialPeligroso").ColumnName = "id"
|
|
DtPSRetorno.Columns("ClaveMaterialPeligrosoDescripcion").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtPSRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
DtPSRetorno.Dispose()
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
Return retorno
|
|
End Function
|
|
|
|
Private Function GETSATEmbalajes(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
|
|
|
|
If context.Application("GlobalDTEmbalajes") Is Nothing Then
|
|
Dim ObjGrales As New ClsGenerales
|
|
If ObjGrales.GetEmbalajes Then context.Application("GlobalDTEmbalajes") = ObjGrales.DtResultados Else context.Application("GlobalDTEmbalajes") = Nothing
|
|
ObjGrales.Dispose()
|
|
End If
|
|
|
|
Dim DTUM = DirectCast(context.Application("GlobalDTEmbalajes"), DataTable).AsEnumerable
|
|
Dim DtPSRetorno As DataTable
|
|
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
|
|
If Name <> "-1" Then
|
|
DTUM = DTUM.Where((Function(a) a!ClaveEmbalajeDescripcion.ToString.ToLower Like ("*" + Name.ToLower + "*")))
|
|
End If
|
|
|
|
If DTUM.Count > 0 Then
|
|
DtPSRetorno = New DataView(DTUM.OrderBy(Function(a) a!ClaveEmbalajeDescripcion).CopyToDataTable).ToTable(True, {"CveEmbalaje", "ClaveEmbalajeDescripcion"})
|
|
Else
|
|
DtPSRetorno = Nothing
|
|
End If
|
|
|
|
If DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0 Then
|
|
DtPSRetorno.Columns("CveEmbalaje").ColumnName = "id"
|
|
DtPSRetorno.Columns("ClaveEmbalajeDescripcion").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtPSRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
DtPSRetorno.Dispose()
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
Return retorno
|
|
End Function
|
|
|
|
|
|
#End Region
|
|
|
|
#Region " GET FRACCION ARANCELARIA "
|
|
Private Function GetFraccionArancelaria(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
|
|
Dim DT = DirectCast(context.Application("GlobalDTFraccionArancelaria"), EnumerableRowCollection(Of DataRow))
|
|
Dim DtRetorno As DataTable
|
|
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
|
|
If Name <> "-1" Then
|
|
DT = DT.Where((Function(a) a!ClaveSATFraccionArancelariaDescripcion.ToString.ToLower Like ($"*{Name.ToLower}*")))
|
|
End If
|
|
|
|
DtRetorno = New DataView(DT.OrderBy(Function(a) a!ClaveSATFraccionArancelaria).CopyToDataTable).ToTable(True, {"CveFraccionArancelaria", "ClaveSATFraccionArancelariaDescripcion"})
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
DtRetorno.Columns("CveFraccionArancelaria").ColumnName = "id"
|
|
DtRetorno.Columns("ClaveSATFraccionArancelariaDescripcion").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
DtRetorno.Dispose()
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
|
|
#Region "USADOS"
|
|
|
|
Private Function GETPSUSADOS(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim DtPSRetorno As DataTable = Nothing
|
|
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim CveEmpresa As String
|
|
If IsNothing(usuario) Then
|
|
context.Response.Write("")
|
|
Else
|
|
CveEmpresa = usuario.CveEmpresa
|
|
Dim FuePorXml = IfNull(context.Request("FuePorXml"), "-1").ToString.ToEntero
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
Dim CveClasificacion = IfNull(context.Request("CveClasificacion"), "-1").ToString.ToEntero
|
|
Dim CveSubFamilia = IfNull(context.Request("CveSubFamilia"), "-1").ToString.ToEntero
|
|
Dim CveClasificacionPresupuesto = IfNull(context.Request("CveClasificacionPresupuesto"), "-1").ToString.ToEntero
|
|
Dim Pagina = IfNull(context.Request("Pagina"), "-1").ToString
|
|
Dim Estatus = IfNull(context.Request("Estatus"), "1").ToString
|
|
Dim CveSucursal = IfNull(context.Request("cvesucursal"), "-1").ToString.ToEntero
|
|
Dim CveSubProyecto = IfNull(context.Request("cvesubproyecto"), "-1").ToString.ToEntero
|
|
Dim UsoClasificacion = IfNull(context.Request("usoclasificacion"), "-1").ToString.ToEntero
|
|
Dim UsaGlobal As Boolean = True
|
|
|
|
|
|
If UsaGlobal Then
|
|
|
|
Dim DTPS = DirectCast(context.Application(String.Format("GlobalDTPSSimplificado-{0}", CveEmpresa)), EnumerableRowCollection(Of DataRow))
|
|
|
|
If DTPS IsNot Nothing Then
|
|
|
|
'APLICACION DE FILTROS
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveEmpresa) = CveEmpresa))
|
|
If Estatus = 1 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveEstado) = 1))
|
|
ElseIf Estatus = -1 Then
|
|
|
|
End If
|
|
|
|
If Name <> "-1" Then
|
|
DTPS = DTPS.Where((Function(a) a!PSCodigo.ToString.ToLower Like ("*" + Name.ToLower + "*")))
|
|
End If
|
|
|
|
If CveClasificacion > 0 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveClasificacion) = CveClasificacion))
|
|
ElseIf CveClasificacion = -1 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveClasificacion) >= 0))
|
|
End If
|
|
|
|
If CveClasificacionPresupuesto > 0 Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveClasificacionPresupuesto) = CveClasificacionPresupuesto))
|
|
End If
|
|
|
|
If UsoClasificacion > 0 Then DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!UsoClasificacion) = UsoClasificacion))
|
|
|
|
If Pagina <> "-1" Then
|
|
If Pagina = "Compras" Then
|
|
DTPS = DTPS.Where((Function(a) a!CveTipoPS = 1 AndAlso a!CveEstado = 1))
|
|
ElseIf Pagina = "Compras2" Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveTipoPS) = 1 AndAlso (Convert.ToInt32(a!CveEstado) = 1 OrElse Convert.ToInt32(a!CveEstado) = 2)))
|
|
ElseIf Pagina = "Inventarios" Then
|
|
DTPS = DTPS.Where((Function(a) Convert.ToInt32(a!CveTipoPS) = 2))
|
|
End If
|
|
End If
|
|
|
|
Try
|
|
DtPSRetorno = New DataView(DTPS.OrderBy(Function(a) a!PSCodigo).CopyToDataTable).ToTable(True, {"CvePS", "PSCodigo", "CveTamaño"})
|
|
DtPSRetorno = DtPSRetorno.FiltraParametros("CveTamaño > 0")
|
|
Catch ex As Exception
|
|
DtPSRetorno = Nothing
|
|
End Try
|
|
DTPS = Nothing
|
|
|
|
End If
|
|
|
|
End If
|
|
If DtPSRetorno IsNot Nothing AndAlso DtPSRetorno.Rows.Count > 0 Then
|
|
DtPSRetorno.Columns("CvePS").ColumnName = "id"
|
|
DtPSRetorno.Columns("PSCodigo").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtPSRetorno).ToString
|
|
DtPSRetorno.Dispose()
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
#Region "Get Personal"
|
|
Private Function getpersonal(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim DtRetorno As DataTable = Nothing
|
|
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim CveEmpresa As String
|
|
If IsNothing(usuario) Then
|
|
context.Response.Write("")
|
|
Else
|
|
CveEmpresa = usuario.CveEmpresa
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
Dim AppNombre As String = String.Format("GlobalDTRHPersonal-{0}", CveEmpresa)
|
|
'sino existe, recarga los datos
|
|
If context.Application(AppNombre) Is Nothing Then
|
|
Dim ObjPersonal As New ClsRH
|
|
If ObjPersonal.GetPersonal(-1, "-1", "-1", "-1", "-1", -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, CveEmpresa) Then
|
|
context.Application(AppNombre) = ObjPersonal.DtResultados
|
|
End If
|
|
ObjPersonal.Dispose()
|
|
End If
|
|
|
|
'Dim ObjProveedores As New ClsCompProveedores
|
|
'If ObjProveedores.GetProveedores(ClsCompProveedores.TipoConsulta.ParaUsoEnEmpresa, -1, "-1", Name, "-1", "-1", "-1", "-1", "-1", -1, CveEmpresa) Then
|
|
' DtRetorno = ObjProveedores.DtResultados
|
|
'End If
|
|
'ObjProveedores.Dispose()
|
|
Dim dt As DataTable = DirectCast(context.Application(AppNombre), DataTable).FiltraParametros($"CveEmpresa = {CveEmpresa}")
|
|
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
|
|
DtRetorno = dt.FiltraParametros($"NombreCompleto like '%{Name}%'")
|
|
End If
|
|
End If
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
DtRetorno.Columns("CvePersonal").ColumnName = "id"
|
|
DtRetorno.Columns("NombreCompleto").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtRetorno).ToString
|
|
DtRetorno.Dispose()
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
|
|
Private Function GetFilesDirectory(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim urlhost As String = context.Request.Url.Host.ToUpper()
|
|
If (urlhost = "LOCALHOST") Then
|
|
Dim directorio As String = IfNull(context.Request("directorio"), "").ToString()
|
|
|
|
Dim xmlarchivos As System.Xml.Linq.XDocument = New System.Xml.Linq.XDocument()
|
|
Dim xfolder As XElement = New XElement("folder")
|
|
For Each urfile In System.IO.Directory.GetFiles(directorio)
|
|
Dim xfile As New XElement("archivo", urfile)
|
|
xfile.SetAttributeValue("EXT", Path.GetExtension(urfile))
|
|
xfolder.Add(xfile)
|
|
|
|
Next
|
|
xmlarchivos.Add(xfolder)
|
|
retorno = xmlarchivos.ToString()
|
|
context.Response.ContentType = "application/xml"
|
|
context.Response.Write(retorno)
|
|
context.Response.StatusCode = 200
|
|
Else
|
|
context.Response.StatusCode = 500
|
|
End If
|
|
Return retorno
|
|
End Function
|
|
|
|
#Region "Get SAT Colonmias"
|
|
Private Function getSATColonias(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim DtRetorno As DataTable = Nothing
|
|
|
|
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
|
|
|
|
Dim dt As DataTable = DirectCast(context.Application("GlobalDTColonia"), DataTable)
|
|
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
|
|
DtRetorno = dt.FiltraParametros($"ClaveSATColoniaCP like '%{Name}%'")
|
|
End If
|
|
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
DtRetorno.Columns("CveColonia").ColumnName = "id"
|
|
DtRetorno.Columns("ClaveSATColoniaCP").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtRetorno).ToString
|
|
DtRetorno.Dispose()
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
#Region "Get Contratos"
|
|
Private Function GetContratos(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
Dim DtRetorno As DataTable = Nothing
|
|
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
Dim CveEmpresa As String
|
|
If IsNothing(usuario) Then
|
|
context.Response.Write("")
|
|
Else
|
|
CveEmpresa = usuario.CveEmpresa
|
|
Dim Name = IfNull(context.Request("Name"), "-1").ToString
|
|
|
|
Dim dt As DataTable = DirectCast(context.Application("GlobalDTContratos"), DataTable).FiltraParametros(String.Format("CveEmpresa = {0}", CveEmpresa))
|
|
If dt IsNot Nothing AndAlso dt.Rows.Count > 0 Then
|
|
DtRetorno = dt.FiltraParametros(String.Format("NumeroContrato like '%{0}%'", Name))
|
|
End If
|
|
dt.Dispose()
|
|
End If
|
|
|
|
If DtRetorno IsNot Nothing AndAlso DtRetorno.Rows.Count > 0 Then
|
|
DtRetorno.Columns("CveContrato").ColumnName = "id"
|
|
DtRetorno.Columns("NumeroContrato").ColumnName = "text"
|
|
retorno = JsonConvert.SerializeObject(DtRetorno).ToString
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
|
|
DtRetorno.Dispose()
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
|
|
#Region "C A N C E L A R - R E M I S I O N"
|
|
Private Function cancelarRemision(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
|
|
Dim CveVenta As Integer = IfNull(context.Request("CveVenta"), "-1").ToString().ToEntero()
|
|
|
|
If CveVenta > 0 Then
|
|
Dim usuario As Usuario = UsuarioActual(context)
|
|
If usuario IsNot Nothing AndAlso usuario.CveEmpresa > 0 Then
|
|
Dim CveAlmacenDevolucion As Integer = 0
|
|
|
|
Using ObjInv As New ClsInventarios
|
|
If ObjInv.GetInv_Mov(CveVenta, usuario.CveEmpresa) Then
|
|
If ObjInv.DtResultados.Rows.Count > 0 Then
|
|
CveAlmacenDevolucion = ObjInv.DtResultados.FiltroPrimeroValor("CveAlmacen", "CveConcepto IN (3,40)").ToEntero()
|
|
End If
|
|
End If
|
|
End Using
|
|
|
|
Dim ObjFacturaCancelacion As New Modelos.Factura(usuario, CveVenta, usuario.CveEmpresa, EsCancelacion:=True)
|
|
ObjFacturaCancelacion.CveAlmacenDevolucion = CveAlmacenDevolucion
|
|
|
|
If ObjFacturaCancelacion.TipoDocto = "Rem" Then
|
|
Dim respuesta = ObjFacturaCancelacion.CancelarFactura(True, New List(Of Integer))
|
|
If respuesta IsNot Nothing Then
|
|
retorno = JsonConvert.SerializeObject(respuesta)
|
|
End If
|
|
End If
|
|
|
|
End If
|
|
|
|
End If
|
|
|
|
If Not String.IsNullOrEmpty(retorno) Then
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
#End Region
|
|
Private Function RemoveMovimiento(ByVal context As HttpContext) As String
|
|
Dim retorno As String = ""
|
|
|
|
Dim Borrar As Boolean = False
|
|
Dim Inv As New ClsInventarios
|
|
Dim Conta As New ClsContabilidad(Inv.IniciaTransacSQL())
|
|
Dim ObjGral As New ClsGenerales(Inv.IniciaTransacSQL())
|
|
|
|
Dim CveMovimiento As Integer = IfNull(context.Request("CveMovimiento"), "-1").ToString().ToEntero()
|
|
Dim CveEmpresa As Integer = IfNull(context.Request("CveEmpresa"), "-1").ToString().ToEntero()
|
|
|
|
Dim TieneError = False
|
|
|
|
CveMovimiento.ToString.GuardaLog
|
|
|
|
'Dim ObjConta As ClsContPAQi = Nothing
|
|
'If UsuarioActual.Empresa.UsaContabilidad Or UsuarioActual.Empresa.UsaAC Then
|
|
' ObjConta = New ClsContPAQi(UsuarioActual.Empresa)
|
|
' ObjConta.IniciaTransacSQL()
|
|
'End If
|
|
|
|
'If Not ObjGral.AddHistorialBitacora(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, "", "", UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, 1, String.Format("{0}, Informacion = {1}", TxtDescripcion.Text, DescripcionDetalladaEliminar), "Inventarios", TxtFolio.Text + " / " + DdlConcepto.SelectedItem.Text) Then
|
|
' TieneError = True
|
|
'End If
|
|
|
|
If Not Inv.MovimientoRemove(CveMovimiento, CveEmpresa) Then
|
|
|
|
TieneError = True
|
|
End If
|
|
|
|
'If Not TieneError Then
|
|
' If Not Conta.UpdatePrePolizasDetalleBloquear(CvePrePoliza, False) Then
|
|
' TieneError = True
|
|
' End If
|
|
'End If
|
|
|
|
If Not TieneError Then
|
|
'If ObjConta IsNot Nothing Then ObjConta.Commit()
|
|
Inv.Commit()
|
|
|
|
|
|
Else
|
|
Inv.RollBack()
|
|
|
|
Alert("Ocurrió un error al eliminar el movimiento. Por favor vuelva a intentar.", TipoMensaje.MsgError)
|
|
End If
|
|
CveMovimiento = 0
|
|
|
|
Inv.Dispose()
|
|
ObjGral.Dispose()
|
|
Conta.Dispose()
|
|
If Not String.IsNullOrEmpty(retorno) Then
|
|
context.Response.Write(retorno)
|
|
Else
|
|
context.Response.Write("[]")
|
|
End If
|
|
|
|
Return retorno
|
|
End Function
|
|
|
|
|
|
|
|
End Class |