-- cambio por rendimiento para el procesamento de ps adiconales
This commit is contained in:
@@ -290,40 +290,39 @@ Partial Class CatPS
|
|||||||
|
|
||||||
#Region "P R O D U C T O S A D I C I O N A L E S"
|
#Region "P R O D U C T O S A D I C I O N A L E S"
|
||||||
|
|
||||||
Private Function GuardarProductosEquivalenteEnFranquicia(ObjPS As ClsProductosServicios, CodigoPS As String, PSAdicional As String, Cantidad As Decimal, Opcion As Integer) As Boolean
|
Private Function GuardarProductosEquivalenteEnFranquicia(ObjPS As ClsProductosServicios, CodigoPS As String, PSAdicional As String, Cantidad As Decimal, Opcion As Integer) As String
|
||||||
|
Dim Retorno As String = ""
|
||||||
If UsuarioActual.Empresa.Funcionalidad(563) <> "" Then
|
If UsuarioActual.Empresa.Funcionalidad(563) <> "" Then
|
||||||
|
|
||||||
Dim StrEmpresas As String = UsuarioActual.Empresa.Funcionalidad(563) & "," & UsuarioActual.CveEmpresa ' agregamos la empresa actual
|
Dim StrEmpresas As String = UsuarioActual.Empresa.Funcionalidad(563) & "," & UsuarioActual.CveEmpresa ' agregamos la empresa actual
|
||||||
Dim EmpresasFranquicia As List(Of Integer) = StrEmpresas.Split(","c).ToList().ConvertAll(Function(x) Convert.ToInt32(x))
|
Dim EmpresasFranquicia As List(Of Integer) = StrEmpresas.Split(","c).ToList().ConvertAll(Function(x) Convert.ToInt32(x))
|
||||||
For Each Franquicia As Integer In EmpresasFranquicia
|
For Each Franquicia As Integer In EmpresasFranquicia
|
||||||
Dim CvePSPagina As Integer = GlobalDTPS(Franquicia).FiltroPrimeroValor("CvePS", String.Format("Codigo = '{0}'", CodigoPS)).ToEntero
|
Dim CvePSPagina As Integer = GlobalDTPS(Franquicia, Codigo:=CodigoPS).FiltroPrimeroValor("CvePS", "").ToEntero
|
||||||
Dim CvePSAdicional As Integer
|
Dim CvePSAdicional As Integer
|
||||||
|
|
||||||
If Opcion = 1 Then CvePSAdicional = GlobalDTPS(Franquicia).FiltroPrimeroValor("CvePS", String.Format("Codigo = '{0}'", PSAdicional)).ToEntero
|
If Opcion = 1 Then CvePSAdicional = GlobalDTPS(Franquicia,, Codigo:=PSAdicional).FiltroPrimeroValor("CvePS", "").ToEntero
|
||||||
|
|
||||||
If CvePSPagina <= 0 Then
|
If CvePSPagina <= 0 Then
|
||||||
Alert(String.Format("El producto de la página no existe en la franquicia: '{0}'", GlobalDTEmpresas(Franquicia).FiltroPrimeroValor("Empresa")), TipoMensaje.MsgAdvertencia)
|
Return String.Format("El producto:{0} no existe en la franquicia: '{1}'", CodigoPS, GlobalDTEmpresas(Franquicia).FiltroPrimeroValor("Empresa"))
|
||||||
Return False
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If CvePSAdicional <= 0 AndAlso Opcion = 1 Then
|
If CvePSAdicional <= 0 AndAlso Opcion = 1 Then
|
||||||
Alert(String.Format("El producto adicional no existe en la franquicia: '{0}'", GlobalDTEmpresas(Franquicia).FiltroPrimeroValor("Empresa")), TipoMensaje.MsgAdvertencia)
|
Return String.Format("El producto adicional:{0} no existe en la franquicia: '{1}'", CodigoPS, GlobalDTEmpresas(Franquicia).FiltroPrimeroValor("Empresa"))
|
||||||
Return False
|
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If Opcion = 1 Then
|
If Opcion = 1 Then
|
||||||
If Not ObjPS.AddPSAdicionales(CvePSPagina, CvePSAdicional, Cantidad) Then
|
If Not ObjPS.AddPSAdicionales(CvePSPagina, CvePSAdicional, Cantidad) Then
|
||||||
Return False
|
Return "no se pudo registrar"
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
If Opcion = 2 Then
|
If Opcion = 2 Then
|
||||||
If Not ObjPS.RemovePSAdicionales(CvePSPagina, -1) Then
|
If Not ObjPS.RemovePSAdicionales(CvePSPagina, -1) Then
|
||||||
Return False
|
Return "No se pudo eliminar"
|
||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
End If
|
End If
|
||||||
Return True
|
Return ""
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Sub LnkExcelPSAdicional_Click(sender As Object, e As EventArgs) Handles LnkExcelPSAdicional.Click
|
Private Sub LnkExcelPSAdicional_Click(sender As Object, e As EventArgs) Handles LnkExcelPSAdicional.Click
|
||||||
@@ -391,44 +390,49 @@ Partial Class CatPS
|
|||||||
|
|
||||||
Try
|
Try
|
||||||
Dim ContadorRegistros As Integer = 0
|
Dim ContadorRegistros As Integer = 0
|
||||||
Dim ObjPS As New ClsProductosServicios
|
Dim ObjPS As ClsProductosServicios
|
||||||
ObjPS.IniciaTransacSQL()
|
Dim dtPS As DataTable = dt.FiltraParametros("", DistinctColumns:={"CodigoProducto"})
|
||||||
|
Dim strNoCargados As New StringBuilder
|
||||||
|
|
||||||
'antes de iniciar la carga se limpiarán los asignados, se filtran por codigops
|
'antes de iniciar la carga se limpiarán los asignados, se filtran por codigops
|
||||||
For Each Row As DataRow In dt.FiltraParametros("", DistinctColumns:={"CodigoProducto"}).Rows
|
For Each Row As DataRow In dtPS.Rows
|
||||||
If Not GuardarProductosEquivalenteEnFranquicia(ObjPS, Row("CodigoProducto").ToString.Trim, "", 0, 2) Then
|
ObjPS = New ClsProductosServicios
|
||||||
|
ObjPS.IniciaTransacSQL()
|
||||||
|
ErrorExcel = False
|
||||||
|
Dim msgg As String = GuardarProductosEquivalenteEnFranquicia(ObjPS, Row("CodigoProducto").ToString.Trim, "", 0, 2)
|
||||||
|
If msgg = "" Then ''eliminar los ps
|
||||||
|
For Each dr As DataRow In dt.FiltraParametros($"CodigoProducto='{ Row("CodigoProducto").ToString.Trim}'").Rows
|
||||||
|
Dim CodigoPS As String = dr("CodigoProducto").ToString
|
||||||
|
Dim CodigoPSAdicional As String = dr("CodigoProductoAdicional").ToString
|
||||||
|
Dim Cantidad As Integer = dr("CantidadFija").ToString.ToEntero
|
||||||
|
If GuardarProductosEquivalenteEnFranquicia(ObjPS, CodigoPS, CodigoPSAdicional, Cantidad, 1) <> "" Then
|
||||||
|
ErrorExcel = True
|
||||||
|
strNoCargados.AppendFormat("código:{0} Adicional:{1}", dr("CodigoProducto").ToString, dr("CodigoProductoAdicional").ToString)
|
||||||
|
Exit For
|
||||||
|
End If
|
||||||
|
ContadorRegistros = ContadorRegistros + 1
|
||||||
|
Next
|
||||||
|
Else
|
||||||
ErrorExcel = True
|
ErrorExcel = True
|
||||||
Exit For
|
strNoCargados.AppendFormat(" {0} <br/> ", msgg)
|
||||||
End If
|
End If
|
||||||
|
If Not ErrorExcel Then
|
||||||
|
ObjPS.Commit()
|
||||||
|
Else
|
||||||
|
ObjPS.RollBack()
|
||||||
|
End If
|
||||||
|
ObjPS.Dispose()
|
||||||
Next
|
Next
|
||||||
If Not ErrorExcel Then
|
|
||||||
For Each Row As DataRow In dt.Rows
|
If ContadorRegistros > 1 Then
|
||||||
Dim CodigoPS As String = Row("CodigoProducto").ToString
|
|
||||||
Dim CodigoPSAdicional As String = Row("CodigoProductoAdicional").ToString
|
|
||||||
Dim Cantidad As Integer = Row("CantidadFija").ToString.ToEntero
|
|
||||||
If Not GuardarProductosEquivalenteEnFranquicia(ObjPS, CodigoPS, CodigoPSAdicional, Cantidad, 1) Then
|
|
||||||
ErrorExcel = True
|
|
||||||
Exit For
|
|
||||||
End If
|
|
||||||
ContadorRegistros = ContadorRegistros + 1
|
|
||||||
Next
|
|
||||||
End If
|
|
||||||
If Not ErrorExcel Then
|
|
||||||
ObjPS.Commit()
|
|
||||||
Dim StrEmpresas As String = UsuarioActual.Empresa.Funcionalidad(563) & "," & UsuarioActual.CveEmpresa ' agregamos la empresa actual
|
Dim StrEmpresas As String = UsuarioActual.Empresa.Funcionalidad(563) & "," & UsuarioActual.CveEmpresa ' agregamos la empresa actual
|
||||||
Dim EmpresasFranquicia As List(Of Integer) = StrEmpresas.Split(","c).ToList().ConvertAll(Function(x) Convert.ToInt32(x))
|
Dim EmpresasFranquicia As List(Of Integer) = StrEmpresas.Split(","c).ToList().ConvertAll(Function(x) Convert.ToInt32(x))
|
||||||
'regenerar el global de cada empresa
|
'regenerar el global de cada empresa
|
||||||
For Each Franquicia As Integer In EmpresasFranquicia
|
For Each Franquicia As Integer In EmpresasFranquicia
|
||||||
GlobalDTPSAdicionales(-1, Franquicia) = Nothing
|
GlobalDTPSAdicionales(-1, Franquicia) = Nothing
|
||||||
Next
|
Next
|
||||||
|
|
||||||
Alert($"{ContadorRegistros} Registros aplicados.")
|
|
||||||
Else
|
|
||||||
ObjPS.RollBack()
|
|
||||||
Alert($"Ocurrió un error al cargar los productos.", TipoMensaje.MsgAdvertencia)
|
|
||||||
End If
|
End If
|
||||||
|
Alert($"{ContadorRegistros} Registros aplicados.<br/>{If(strNoCargados.Length > 0, strNoCargados.ToString, "")}")
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Alert("No se pudo cargar el excel", TipoMensaje.MsgAdvertencia)
|
Alert("No se pudo cargar el excel", TipoMensaje.MsgAdvertencia)
|
||||||
GuardaLog(ex.Message)
|
GuardaLog(ex.Message)
|
||||||
|
|||||||
Reference in New Issue
Block a user