From baac40127c3a6fa15edc61ea0773f12aff4f6e0e Mon Sep 17 00:00:00 2001 From: JORGE LUIS CAUDILLO ESPARZA Date: Thu, 14 May 2020 12:35:34 -0700 Subject: [PATCH 1/2] excel gembox --- App_Code/modExtensiones.vb | 47 +++++++++++++++++++++++++ OC/OC.aspx.vb | 46 ------------------------ Ventas/Ventas.aspx.vb | 72 ++------------------------------------ 3 files changed, 50 insertions(+), 115 deletions(-) diff --git a/App_Code/modExtensiones.vb b/App_Code/modExtensiones.vb index 7f7473927..1b799cb7d 100644 --- a/App_Code/modExtensiones.vb +++ b/App_Code/modExtensiones.vb @@ -68,6 +68,53 @@ Namespace Extensiones #End Region + Public Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable + GemBox.Spreadsheet.SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) + Dim excelFile As GemBox.Spreadsheet.ExcelFile = GemBox.Spreadsheet.ExcelFile.Load(flatFilePath) + + Dim unnamed As Integer = 0 + Dim cols As Integer + Dim columns As String() + Dim curRow As Integer = 0 + Dim curCol As Integer = 0 + Dim dataTable As DataTable = New DataTable() + Dim worksheet As GemBox.Spreadsheet.ExcelWorksheet = excelFile.Worksheets(0) + + For cols = 0 To worksheet.Rows(0).AllocatedCells.Count - 1 + + If firstRowHasHeaders Then + + If worksheet.Rows(0).Cells(cols).Value IsNot Nothing Then + dataTable.Columns.Add(worksheet.Rows(0).Cells(cols).Value.ToString()) + Else + dataTable.Columns.Add("Unnamed Column " & (System.Threading.Interlocked.Increment(unnamed))) + End If + + curRow = 1 + Else + dataTable.Columns.Add("Column " & (cols + 1)) + End If + Next + + While curRow < worksheet.Rows.Count + columns = New String(cols - 1) {} + + For curCol = 0 To cols - 1 + + If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then + columns(curCol) = "" + Else + columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString() + End If + Next + + dataTable.Rows.Add(columns) + curRow += 1 + End While + + Return dataTable + End Function + Public Function CadenaConexion() As String Dim BaseDatos As String = "Ventas" 'If Not IsNothing(System.Web.HttpContext.Current) AndAlso Not IsNothing(System.Web.HttpContext.Current.Session) Then diff --git a/OC/OC.aspx.vb b/OC/OC.aspx.vb index 8d188b934..0bc60d29f 100644 --- a/OC/OC.aspx.vb +++ b/OC/OC.aspx.vb @@ -6110,52 +6110,6 @@ Partial Class OC End If End Sub - Private Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable - SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) - Dim excelFile As ExcelFile = ExcelFile.Load(flatFilePath) - - Dim unnamed As Integer = 0 - Dim cols As Integer - Dim columns As String() - Dim curRow As Integer = 0 - Dim curCol As Integer = 0 - Dim dataTable As DataTable = New DataTable() - Dim worksheet As ExcelWorksheet = excelFile.Worksheets(0) - - For cols = 0 To worksheet.Rows(0).AllocatedCells.Count - 1 - - If firstRowHasHeaders Then - - If worksheet.Rows(0).Cells(cols).Value IsNot Nothing Then - dataTable.Columns.Add(worksheet.Rows(0).Cells(cols).Value.ToString()) - Else - dataTable.Columns.Add("Unnamed Column " & (System.Threading.Interlocked.Increment(unnamed))) - End If - - curRow = 1 - Else - dataTable.Columns.Add("Column " & (cols + 1)) - End If - Next - - While curRow < worksheet.Rows.Count - columns = New String(cols - 1) {} - - For curCol = 0 To cols - 1 - - If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then - columns(curCol) = "" - Else - columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString() - End If - Next - - dataTable.Rows.Add(columns) - curRow += 1 - End While - - Return dataTable - End Function Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String) diff --git a/Ventas/Ventas.aspx.vb b/Ventas/Ventas.aspx.vb index 6f9caf1da..9e050a276 100644 --- a/Ventas/Ventas.aspx.vb +++ b/Ventas/Ventas.aspx.vb @@ -19451,31 +19451,11 @@ Partial Class Ventas Public Sub LbDescargarExcel_Click(sender As Object, e As EventArgs) Handles LbDescargarExcelVentas.Click DescargarFormato() End Sub - Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String) + Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String, FileUrl As String) Dim dt As New DataTable - 'Dim Conexion As Odbc.OdbcConnection = Nothing Dim ErrorArchivo = False Dim n As Integer = 0 - dt = ReadExcelFile(Ruta + FileName, True) - 'Try - ' Select Case Tipo - ' Case "EXCEL" - ' Conexion = New Odbc.OdbcConnection("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=" + Ruta + FileName + ";") - ' Conexion.Open() - ' Dim cmd = Conexion.CreateCommand() - ' cmd.CommandType = CommandType.Text - ' cmd.CommandText = "Select * FROM [Hoja1$] WHERE Cantidad >=1" - ' Dim DataAdapter = New Odbc.OdbcDataAdapter(cmd) - ' DataAdapter.Fill(dt) - ' Case Else - ' Alert("El archivo no tiene el formato correcto", TipoMensaje.MsgError) - ' Exit Sub - ' End Select - 'Catch ex As Exception - ' ErrorArchivo = True - ' OnError("Ocurrio un Error al leer el archivo
" & ex.Message, ex) - 'End Try - 'Conexion.Close() + dt = ReadExcelFile(FileUrl, True) If Not ErrorArchivo Then If Not dt.Columns(0).ColumnName = "Cantidad" Then Alert("El nombre de la primera columna debe ser 'Cantidad'.Favor de corregirlo", TipoMensaje.MsgError) @@ -19676,7 +19656,7 @@ Partial Class Ventas Dim file As Archivo = TxtExcel.getfiles().Archivos(0) Dim Directorio As String = ModExtensiones.DirectorioBaseEmpresas & file.patch Dim Tipo As String = If(file.Extencion.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV") - CargarArchivo(Directorio, file.filename, Tipo) + CargarArchivo(Directorio, file.filename, Tipo, file.FileUrl) Else Alert("No existe el archivo. Favor de subir un archivo excel a la plataforma.", TipoMensaje.MsgError) End If @@ -25447,52 +25427,6 @@ Partial Class Ventas CargaEventoBitacora() End Sub - Private Function ReadExcelFile(ByVal flatFilePath As String, ByVal firstRowHasHeaders As Boolean) As DataTable - GemBox.Spreadsheet.SpreadsheetInfo.SetLicense(ModExtensiones.SerialGemBoxSpreadsheet) - Dim excelFile As GemBox.Spreadsheet.ExcelFile = GemBox.Spreadsheet.ExcelFile.Load(flatFilePath) - - Dim unnamed As Integer = 0 - Dim cols As Integer - Dim columns As String() - Dim curRow As Integer = 0 - Dim curCol As Integer = 0 - Dim dataTable As DataTable = New DataTable() - Dim worksheet As GemBox.Spreadsheet.ExcelWorksheet = excelFile.Worksheets(0) - - For cols = 0 To worksheet.Rows(0).AllocatedCells.Count - 1 - - If firstRowHasHeaders Then - - If worksheet.Rows(0).Cells(cols).Value IsNot Nothing Then - dataTable.Columns.Add(worksheet.Rows(0).Cells(cols).Value.ToString()) - Else - dataTable.Columns.Add("Unnamed Column " & (System.Threading.Interlocked.Increment(unnamed))) - End If - - curRow = 1 - Else - dataTable.Columns.Add("Column " & (cols + 1)) - End If - Next - - While curRow < worksheet.Rows.Count - columns = New String(cols - 1) {} - - For curCol = 0 To cols - 1 - - If worksheet.Rows(curRow).Cells(curCol).Value Is Nothing Then - columns(curCol) = "" - Else - columns(curCol) = worksheet.Rows(curRow).Cells(curCol).Value.ToString() - End If - Next - - dataTable.Rows.Add(columns) - curRow += 1 - End While - - Return dataTable - End Function End Class \ No newline at end of file From 61c473e8858668e8a0849f477ba2aba62c0a80f1 Mon Sep 17 00:00:00 2001 From: Jonathan Alexis Perez Morales Date: Thu, 14 May 2020 12:59:22 -0700 Subject: [PATCH 2/2] Correccion de directorio --- AF/AF.aspx.vb | 2 +- Bancos/CreditosPagoMultiple.aspx.vb | 2 +- Compras/Proveedores.aspx.vb | 4 ++-- General/RepPaqueteriasGuias.aspx.cs | 2 +- Inventarios/RecepcionUsados.aspx.vb | 4 ++-- OI/SoporteADS.aspx.vb | 4 ++-- PortalProveedor/PortalProveedor.aspx.vb | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/AF/AF.aspx.vb b/AF/AF.aspx.vb index f705a3c26..f53722f3c 100644 --- a/AF/AF.aspx.vb +++ b/AF/AF.aspx.vb @@ -2407,7 +2407,7 @@ Partial Class AF_AF Dim filemove As String = "" For Each fileItem As Archivo In filesgral - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") filemove = fileItem.filename Next diff --git a/Bancos/CreditosPagoMultiple.aspx.vb b/Bancos/CreditosPagoMultiple.aspx.vb index 615b0c0b8..70a1873b4 100644 --- a/Bancos/CreditosPagoMultiple.aspx.vb +++ b/Bancos/CreditosPagoMultiple.aspx.vb @@ -216,7 +216,7 @@ Partial Class Bancos_CreditosPagoMultiple Dim filemove As String = "" Dim Comprobante As String = "" For Each fileItem As Archivo In filesgral - Comprobante = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + Comprobante = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") filemove = fileItem.filename Next diff --git a/Compras/Proveedores.aspx.vb b/Compras/Proveedores.aspx.vb index 0d11cf687..6e1e76ea6 100644 --- a/Compras/Proveedores.aspx.vb +++ b/Compras/Proveedores.aspx.vb @@ -2625,7 +2625,7 @@ Partial Class Compras_Proveedores Dim filemove As String = "" For Each fileItem As Archivo In filesgral - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") filemove = fileItem.filename Next @@ -2871,7 +2871,7 @@ Partial Class Compras_Proveedores Try - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") Dim tempArray() As String tempArray = fileItem.filename.ToString().Split("-".ToCharArray()) diff --git a/General/RepPaqueteriasGuias.aspx.cs b/General/RepPaqueteriasGuias.aspx.cs index de9a07d40..9fcbd9d2b 100644 --- a/General/RepPaqueteriasGuias.aspx.cs +++ b/General/RepPaqueteriasGuias.aspx.cs @@ -618,7 +618,7 @@ public partial class General_RepPaqueteriasGuias : ClsPaginas { try { - FileExtension = System.IO.Path.GetExtension(string.Format("{0}Temp\\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", ""); + FileExtension = System.IO.Path.GetExtension(string.Format("{0}Temp\\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", ""); string rutaDestino = UsuarioActual.Empresa.Ruta + "Documentos\\Guias\\" + CvePaqueteriaGuia + "." + FileExtension; if (!System.IO.Directory.Exists(UsuarioActual.Empresa.Ruta + "Documentos\\Guias\\")) { diff --git a/Inventarios/RecepcionUsados.aspx.vb b/Inventarios/RecepcionUsados.aspx.vb index 1145c7f0f..fc562aaa7 100644 --- a/Inventarios/RecepcionUsados.aspx.vb +++ b/Inventarios/RecepcionUsados.aspx.vb @@ -1540,7 +1540,7 @@ Partial Class Inventarios_RecepcionUsados Dim Filesgral As List(Of Archivo) = Anexo.getfiles().Archivos For Each fileItem As Archivo In Filesgral - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") Filename = fileItem.filename Next @@ -1624,7 +1624,7 @@ Partial Class Inventarios_RecepcionUsados Dim Filename As String = "" For Each fileItem As Archivo In Filesgral - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)) '.Replace(".", "") + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)) '.Replace(".", "") Filename = fileItem.filename Next diff --git a/OI/SoporteADS.aspx.vb b/OI/SoporteADS.aspx.vb index e91072dd1..13e589cda 100644 --- a/OI/SoporteADS.aspx.vb +++ b/OI/SoporteADS.aspx.vb @@ -2011,7 +2011,7 @@ Partial Class OI_SoporteADS For Each fileItem As Archivo In Filesgral - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") 'Filename = fileItem.filename Dim tempArray() As String tempArray = fileItem.filename.ToString().Split("-".ToCharArray()) @@ -2061,7 +2061,7 @@ Partial Class OI_SoporteADS For Each fileItem As Archivo In Filesgral - FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") 'Filename = fileItem.filename Dim tempArray() As String tempArray = fileItem.filename.ToString().Split("-".ToCharArray()) diff --git a/PortalProveedor/PortalProveedor.aspx.vb b/PortalProveedor/PortalProveedor.aspx.vb index 74ae350dd..fe6e0251c 100644 --- a/PortalProveedor/PortalProveedor.aspx.vb +++ b/PortalProveedor/PortalProveedor.aspx.vb @@ -1676,7 +1676,7 @@ Partial Class Portal_PortalProveedor ' Try - ' FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", ModExtensiones.DirectorioBaseEmpresas, fileItem.filename)).Replace(".", "") + ' FileExtension = IO.Path.GetExtension(String.Format("{0}Temp\{1}", AppDomain.CurrentDomain.BaseDirectory, fileItem.filename)).Replace(".", "") ' Dim tempArray() As String ' tempArray = fileItem.filename.ToString().Split("-".ToCharArray())