carga con excel

This commit is contained in:
2022-01-14 10:50:30 -07:00
parent 53b4d1e1ae
commit 61ae8bd6b9
2 changed files with 217 additions and 31 deletions

View File

@@ -5,13 +5,12 @@ Imports Microsoft.Reporting.WebForms
Imports System.Data
Imports Extensiones
Imports System.IO
Imports GemBox.Spreadsheet
Partial Class Inventarios_RecepcionAlmacen
Inherits ClsPaginas
#Region "PROPIEDADES"
Private Shared missing As Object = System.Reflection.Missing.Value
Private Property EstatusInicial As String
Get
EstatusInicial = ViewState("EstatusInicial").ToString
@@ -44,9 +43,6 @@ Partial Class Inventarios_RecepcionAlmacen
Else
Return CType(ViewState("DtInv"), DataTable)
End If
End Get
Set(value As DataTable)
ViewState("DtInv") = value
@@ -988,11 +984,15 @@ Partial Class Inventarios_RecepcionAlmacen
RecibidaCompleta = False
'' carga desde excel
' HplCargaExcel.Enabled = True
Dim CargaSoloUsados As Boolean = False
If ObjInventario.RecepcionAlmacenGet(pCveCompra, BuscaEntregaDirecta, -1, UsuarioActual.CveEmpresa, UsuarioActual.CveUsuario) AndAlso ObjInventario.DtResultados.Rows.Count > 0 Then
Dim DtRecepcion As DataTable = ObjInventario.DtResultados.Copy()
DtInv = DtRecepcion
Dim NumUsados = ObjInventario.DtResultados.COUNT("EsUsado", "EsUsado = True").ToEntero()
Dim NumProductos = ObjInventario.DtResultados.COUNT("EsUsado", "EsUsado = False").ToEntero()
Dim CveSubProyecto As Integer
@@ -4795,6 +4795,147 @@ Partial Class Inventarios_RecepcionAlmacen
#End Region
#Region "CargaExcel"
Private Sub BtnCargaExcel_Click(sender As Object, e As EventArgs) Handles BtnCargaExcel.Click
If TxtExcel.getfiles().Archivos.Count > 0 Then
Dim file As Archivo = TxtExcel.getfiles().Archivos(0)
Dim Directorio As String = AppDomain.CurrentDomain.BaseDirectory & file.path
Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb", "xls"), "EXCEL", "CSV")
CargarArchivoExcel(Directorio, file.filename)
Else
Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError)
End If
End Sub
Protected Sub CargarArchivoExcel(Ruta As String, FileName As String)
SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet)
Dim dt As DataTable = Nothing
Dim ErrorArchivo = False
Try
dt = ReadExcelFile(Ruta + FileName, True)
Catch ex As Exception
ErrorArchivo = True
OnError("Ocurrio un error al leer el archivo <br/>" & ex.Message, ex)
End Try
If Not ErrorArchivo AndAlso dt IsNot Nothing Then
If Not dt.Columns(0).ColumnName = "Cantidad" Then
Alert("El nombre de la primera columna debe ser 'Cantidad'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
If Not dt.Columns(1).ColumnName = "Código" Then
Alert("El nombre de la segunda columna debe ser 'Codigo'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
If Not dt.Columns(2).ColumnName = "Producto" Then
Alert("El nombre de la tercera columna debe ser 'Producto'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
If Not dt.Columns(3).ColumnName = "Serie" Then
Alert("El nombre de la cuarta columna debe ser 'Serie'. Favor de corregirlo", TipoMensaje.MsgError)
Exit Sub
End If
'If Not dt.Columns(4).ColumnName = "Lote" Then
' Alert("El nombre de la cuarta columna debe ser 'Lote'. Favor de corregirlo", TipoMensaje.MsgError)
' Exit Sub
'End If
'If Not dt.Columns(5).ColumnName = "FechaCaducidad" Then
' Alert("El nombre de la cuarta columna debe ser 'Fecha Caducidad'. Favor de corregirlo", TipoMensaje.MsgError)
' Exit Sub
'End If
dt.TableName = "Datos"
Dim ProductosNoCargados As New StringBuilder()
Dim RowsCargados As Integer = 0
Dim RowsNoCargados As Integer = 0
Dim NoPSConSerie As Integer = 0
If CveCompraSurtir > 0 Then
'DtRecepcion
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
If RowExcel("Código").ToString() <> "" Then
Dim RowPS = DtInv.FiltroPrimero(String.Format("Codigo='{0}'", RowExcel("Código").ToString()))
If RowPS IsNot Nothing AndAlso RowPS("CvePS").ToString().ToEntero() > 0 Then
Dim CveProducto As Integer = RowPS("CvePS").ToString().ToEntero()
Dim CveUnidadMedida As Integer = RowPS("CveUM").ToString().ToEntero()
Dim Cantidad As Double = RowExcel("Cantidad").ToString().ToDecimal()
Dim Serie As String = RowExcel("Serie").ToString()
Dim Lote As String '= RowExcel("Lote").ToString()
Dim FechaCaducidad As Date '= If(RowExcel("FechaCaducidad").ToString = "", MinFecha, RowExcel("FechaCaducidad").ToString.ToDate)
Dim Observaciones As String '= If(dt.Columns.Contains("Observaciones"), RowExcel("Observaciones").ToString, "").ToString
Dim Valido As Boolean = True
If RowPS("AplicaSerie").ToString() = "True" And (String.IsNullOrEmpty(Serie.Trim()) OrElse Serie = "-1") Then
Valido = False
Alert($"El producto '{RowPS("PS")}' requiere 'Serie'", TipoMensaje.MsgAdvertencia)
ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString())
End If
If RowPS("AplicaSerie").ToString() = "True" AndAlso Not String.IsNullOrEmpty(Serie.Trim()) Then
NoPSConSerie = NoPSConSerie + 1
End If
If Valido Then
CveConsecSerie = RowPS("Consec").ToString.ToEntero
AgregaSerie(RowExcel("Serie").ToString, 1)
'AgregarPS(Cantidad, CveProducto, CveUnidadMedida, Observaciones, CveSeccionAlmacen:=DdlSeccionAlmacen.SelectedValue.ToEntero, SeccionAlmacen:=DdlSeccionAlmacen.SelectedItem.Text, Serie:=If(Not String.IsNullOrEmpty(Serie), Serie, ""), Lote:=Lote, FechaCaducidad:=FechaCaducidad, Limpia:=False)
RowsCargados = RowsCargados + 1
Else
RowsNoCargados = RowsNoCargados + 1
ProductosNoCargados.AppendFormat("{0},", RowPS("PS").ToString())
End If
Else
RowsNoCargados = RowsNoCargados + 1
ProductosNoCargados.AppendFormat("{0},", RowExcel("Producto").ToString())
End If
End If
Next
Catch ex As Exception
OnError("Ocurrió un error al cargar los productos." & ProductosNoCargados.ToString(), ex)
Finally
Dim MensajeFinal As New StringBuilder()
If RowsNoCargados = 0 AndAlso RowsCargados > 0 Then
MensajeFinal.Append("Los productos se cargaron correctamente. <br/><br/>")
End If
If RowsCargados > 0 Then
MensajeFinal.Append("Se cargaron <b>" & RowsCargados & "</b> productos correctamente.")
End If
If RowsNoCargados > 0 Then
MensajeFinal.Append("No se pudieron cargar <b>" & RowsNoCargados & "</b> productos. <br/>Los siguientes productos no se pudieron cargar: " & ProductosNoCargados.ToString())
End If
Alert(MensajeFinal.ToString())
End Try
Else
Alert("No hay seleccionada compra", TipoMensaje.MsgError)
End If
End If
End Sub
#End Region
'Protected Sub BtnGuardarDocumento_Click(sender As Object, e As EventArgs)
' Dim Filesgral As List(Of Archivo) = TxtDocumento.getfiles().Archivos
@@ -4899,31 +5040,5 @@ Partial Class Inventarios_RecepcionAlmacen
End Class
'Private Function GuardaDocumentoBitacora(ObjEventoBitacora As ClsOIEventos, CveMovimiento As Integer) As Boolean
' Dim Retorno = True
' Dim Archivo As System.IO.FileInfo = Nothing
' For Each Dr As DataRow In DtDocumentos.Rows
' If ObjEventoBitacora.AddEventoBitacora("Documento Relacionado", Dr("FileExtension").ToString, UsuarioActual.CveUsuario, UsuarioActual.CveEmpresa, CveMovimientoAlmacen:=CveMovimiento) Then
' Try
' If Dr("Documento").ToString <> "" Then
' Archivo = New System.IO.FileInfo(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, Dr("Documento").ToString))
' If Archivo.Exists() Then
' File.Move(Archivo.ToString, String.Format("{0}OI\OI{1}{2}", UsuarioActual.Empresa.Ruta, ObjEventoBitacora.CveEvento.ToString, Archivo.Extension))
' Else
' Retorno = False
' End If
' End If
' Catch ex As Exception
' Retorno = False
' Exit For
' End Try
' Else
' Retorno = False
' Exit For
' End If
' Next
' Return Retorno
'End Function
End Class