-- mejora en carga de excel formateado con códigos únicos E141

This commit is contained in:
2022-05-19 10:07:44 -07:00
parent afeaaa4641
commit 7ddb3ff16e

View File

@@ -4864,7 +4864,13 @@ Partial Class Inventarios_RecepcionAlmacen
Dim file As Archivo = TxtExcel.getfiles().Archivos(0) Dim file As Archivo = TxtExcel.getfiles().Archivos(0)
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.path Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.path
Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb", "xls"), "EXCEL", "CSV") Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb", "xls"), "EXCEL", "CSV")
If Tipo = "CSV" AndAlso UsuarioActual.Empresa.Funcionalidad(531) = "1" Then 'empresa de acumuladores
CargaArchivoCSV(Directorio, file.filename, HLFolio.Text)
Else
CargarArchivoExcel(Directorio, file.filename) CargarArchivoExcel(Directorio, file.filename)
End If
Else Else
Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError) Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError)
End If End If
@@ -4903,7 +4909,12 @@ Partial Class Inventarios_RecepcionAlmacen
Exit Sub Exit Sub
End If End If
ProcesaExcel(dt)
End If
End Sub
Private Function ProcesaExcel(dt As DataTable) As Boolean
dt.TableName = "Datos" dt.TableName = "Datos"
Dim ProductosNoCargados As New StringBuilder() Dim ProductosNoCargados As New StringBuilder()
Dim RowsCargados As Integer = 0 Dim RowsCargados As Integer = 0
@@ -4911,10 +4922,9 @@ Partial Class Inventarios_RecepcionAlmacen
Dim NoPSConSerie As Integer = 0 Dim NoPSConSerie As Integer = 0
If CveCompraSurtir > 0 Then If CveCompraSurtir > 0 Then
'DtRecepcion
Try Try
'Dim DtPS As DataTable = GlobalDTPS(UsuarioActual.CveEmpresa)
'If(dt.Columns.Contains("PorcentajeIVA"), Round(Row("PorcentajeIVA").ToString.ToDecimal, 4), 0)
For Each RowExcel As DataRow In dt.Rows For Each RowExcel As DataRow In dt.Rows
If RowExcel("Código").ToString() <> "" Then If RowExcel("Código").ToString() <> "" Then
@@ -4929,9 +4939,9 @@ Partial Class Inventarios_RecepcionAlmacen
Dim Cantidad As Double = RowExcel("Cantidad").ToString().ToDecimal() Dim Cantidad As Double = RowExcel("Cantidad").ToString().ToDecimal()
Dim Serie As String = RowExcel("Serie").ToString() Dim Serie As String = RowExcel("Serie").ToString()
Dim Lote As String = "" '= RowExcel("Lote").ToString() Dim Lote As String = ""
Dim FechaCaducidad As Date = MinFecha '= If(RowExcel("FechaCaducidad").ToString = "", MinFecha, RowExcel("FechaCaducidad").ToString.ToDate) Dim FechaCaducidad As Date = MinFecha
Dim Observaciones As String = "" '= If(dt.Columns.Contains("Observaciones"), RowExcel("Observaciones").ToString, "").ToString Dim Observaciones As String = ""
LbCantidad.Text = Cantidad.ToString LbCantidad.Text = Cantidad.ToString
Dim Valido As Boolean = True Dim Valido As Boolean = True
@@ -4986,9 +4996,9 @@ Partial Class Inventarios_RecepcionAlmacen
Alert("No hay seleccionada compra", TipoMensaje.MsgError) Alert("No hay seleccionada compra", TipoMensaje.MsgError)
End If End If
Return True
End If End Function
End Sub
Protected Sub LbDescargarExcelConceptos_Click(sender As Object, e As EventArgs) Protected Sub LbDescargarExcelConceptos_Click(sender As Object, e As EventArgs)
DescargarFormato() DescargarFormato()
@@ -5024,6 +5034,59 @@ Partial Class Inventarios_RecepcionAlmacen
End Sub End Sub
Private Sub CargaArchivoCSV(Ruta As String, FileName As String, Optional FolioFactura As String = "")
'Create a DataTable.
Dim dt As New DataTable()
dt.Columns.AddRange(New DataColumn(9) {New DataColumn("CodBarra", GetType(String)),
New DataColumn("OVenta", GetType(String)),
New DataColumn("Factura", GetType(String)),
New DataColumn("FechaFac", GetType(String)),
New DataColumn("Pallet", GetType(String)),
New DataColumn("CodigoJCI", GetType(String)),
New DataColumn("Producto", GetType(String)),
New DataColumn("Serie", GetType(String)),'CodigoUnico
New DataColumn("Cantidad", GetType(Integer)),
New DataColumn("Código", GetType(String))})
FolioFactura = FolioFactura.Replace("-", "")
'Read the contents of CSV file.
Dim csvData As String = File.ReadAllText(Ruta & FileName)
Dim CodigoUnico As String = "CU no escaneado" 'texto constante para determinar que no se leyó
Dim r As Integer = 1
'Execute a loop over the rows.
For Each row As String In csvData.Split(ControlChars.Lf)
If r > 2 Then ' si es la segundo renglon
If Not String.IsNullOrEmpty(row) Then
Dim i As Integer = 0
Dim rr As String() = row.Split(","c)
If CodigoUnico <> rr(7).Trim AndAlso (FolioFactura = "" OrElse FolioFactura = rr(2).Trim) Then
dt.Rows.Add()
dt.Rows(dt.Rows.Count - 1)("CodBarra") = rr(0).Trim
dt.Rows(dt.Rows.Count - 1)("OVenta") = rr(1).Trim
dt.Rows(dt.Rows.Count - 1)("Factura") = rr(2).Trim
dt.Rows(dt.Rows.Count - 1)("FechaFac") = rr(3).Trim
dt.Rows(dt.Rows.Count - 1)("Pallet") = rr(4).Trim
dt.Rows(dt.Rows.Count - 1)("CodigoJCI") = rr(5).Trim
dt.Rows(dt.Rows.Count - 1)("Producto") = rr(6).Trim
dt.Rows(dt.Rows.Count - 1)("Serie") = rr(7).Trim
dt.Rows(dt.Rows.Count - 1)("Cantidad") = 1
dt.Rows(dt.Rows.Count - 1)("Código") = GlobalDTPSSimplificado(UsuarioActual.CveEmpresa).FiltroPrimeroValor("Codigo", String.Format("Codigo2 = '{0}'", rr(5).Trim))
End If
End If
End If
r += 1
Next
ProcesaExcel(dt)
End Sub
#End Region #End Region
Private Function GuardaDocumentoBitacora(ObjEventoBitacora As ClsOIEventos, CveMovimiento As Integer) As Boolean Private Function GuardaDocumentoBitacora(ObjEventoBitacora As ClsOIEventos, CveMovimiento As Integer) As Boolean