Carga Presupuesto de archivo Excel en Contratos
This commit is contained in:
@@ -494,4 +494,76 @@ Partial Class Contratos_Presupuestos
|
||||
UpGvClasificaciones.Update()
|
||||
UpIndicadores.Update()
|
||||
End Sub
|
||||
|
||||
Protected Sub LnkCargaPresupuesto_Click(sender As Object, e As EventArgs) Handles LnkCargaPresupuesto.Click
|
||||
RegistraScript("$('#ModalCargaPresupuesto').modal();")
|
||||
End Sub
|
||||
|
||||
Protected Sub LnkFormatoPresup_Click(sender As Object, e As EventArgs) Handles LnkFormatoPresup.Click
|
||||
GvPresupuestos.ExportToExcelX("Plantilla Presupuesto " + DateTime.Now.ToShortDateString)
|
||||
End Sub
|
||||
|
||||
Protected Sub LnkCargarPresup_Click(sender As Object, e As EventArgs) Handles LnkCargarPresup.Click
|
||||
If TxtCargarPresup.getfiles().Archivos.Count > 0 Then
|
||||
Dim file As Archivo = TxtCargarPresup.getfiles().Archivos(0)
|
||||
|
||||
Dim Directorio As String = Server.MapPath("~") & file.path
|
||||
|
||||
Dim Tipo As String = If(file.Extension.Contiene("xlsx", "xlsx", "xlsm", "xlsb"), "EXCEL", "CSV")
|
||||
CargarArchivo(Directorio, file.filename, Tipo)
|
||||
Else
|
||||
Alert("No existe el archivo. Favor de subir un archivo CSV o Excel a la plataforma.", TipoMensaje.MsgError)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub CargarArchivo(Ruta As String, FileName As String, Tipo As String)
|
||||
|
||||
Dim DTExcel As New DataTable
|
||||
Dim ErrorArchivo = False
|
||||
Dim ErrorExcel = False
|
||||
|
||||
DTExcel = ReadExcelFile(Ruta + FileName, True)
|
||||
|
||||
If Not ErrorArchivo Then
|
||||
If Not DTExcel.Columns(0).ColumnName = "Clasificación" Then
|
||||
Alert("El nombre de la primera columna debe ser 'Clasificación'. Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
If Not DTExcel.Columns(1).ColumnName = "Importe" Then
|
||||
Alert("El nombre de la segunda columna debe ser 'Importe'.Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
If Not DTExcel.Columns(2).ColumnName = "Observaciones" Then
|
||||
Alert("El nombre de la tercera columna debe ser 'Observaciones'.Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
If Not DTExcel.Columns(3).ColumnName = "Tipo Gasto" Then
|
||||
Alert("El nombre de la cuarta columna debe ser 'Tipo Gasto'. Favor de corregirlo", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End If
|
||||
End If
|
||||
|
||||
Try
|
||||
Dim txtImporte As TextBox = Nothing
|
||||
Dim txtObservacion As TextBox = Nothing
|
||||
Dim i As Integer = 0
|
||||
For Each row As GridViewRow In GvPresupuestos.Rows
|
||||
If (i < DTExcel.Rows.Count) Then
|
||||
txtImporte = row.FCTextBox("TxtImporteClasi")
|
||||
txtObservacion = row.FCTextBox("TxtObservacion")
|
||||
txtImporte.Text = DTExcel.Rows(i).Field(Of String)(1).ToString
|
||||
txtObservacion.Text = DTExcel.Rows(i).Field(Of String)(2).ToString
|
||||
i += 1
|
||||
End If
|
||||
Next
|
||||
Catch ex As Exception
|
||||
GuardaLog($"Ocurrio un error al cargar archivo Excel en Contratos/Presupuestos.aspx - {ex.ToString()}")
|
||||
Alert("Se produjo un error al ingresar los datos. Favor de contactar a soporte.", TipoMensaje.MsgError)
|
||||
Exit Sub
|
||||
End Try
|
||||
|
||||
RegistraScript("$('#ModalCargaPresupuesto').modal('hide');calculaTotal()")
|
||||
UpGvClasificaciones.Update()
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user