Carga Presupuesto de archivo Excel en Contratos
This commit is contained in:
@@ -2462,11 +2462,12 @@ Namespace Extensiones
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
|
'Usa la librería ClosedXML
|
||||||
<Runtime.CompilerServices.Extension()>
|
<Runtime.CompilerServices.Extension()>
|
||||||
Public Sub ExportToExcelx(GridView As GridView, NombreArchivoXLSX As String)
|
Public Sub ExportToExcelX(GridView As GridView, NombreArchivoXLSX As String)
|
||||||
|
|
||||||
If GridView IsNot Nothing AndAlso GridView.Rows.Count > 0 Then
|
If GridView IsNot Nothing AndAlso GridView.Rows.Count > 0 Then
|
||||||
NombreArchivoXLSX = Regex.Replace(NombreArchivoXLSX.Replace("["c, "").Replace("]"c, ""), "[:\/?*]", String.Empty)
|
NombreArchivoXLSX = ValidFileName(NombreArchivoXLSX, 31)
|
||||||
Dim dt As New DataTable(NombreArchivoXLSX)
|
Dim dt As New DataTable(NombreArchivoXLSX)
|
||||||
Dim i As Integer = 0
|
Dim i As Integer = 0
|
||||||
Dim ArrColumnasVisibles As New List(Of Integer) 'solo recorro las columnas visibles
|
Dim ArrColumnasVisibles As New List(Of Integer) 'solo recorro las columnas visibles
|
||||||
@@ -2509,8 +2510,17 @@ Namespace Extensiones
|
|||||||
'Next
|
'Next
|
||||||
Next
|
Next
|
||||||
Using wb As New XLWorkbook()
|
Using wb As New XLWorkbook()
|
||||||
wb.Worksheets.Add(dt)
|
Dim WS As IXLWorksheet = wb.Worksheets.Add(NombreArchivoXLSX)
|
||||||
|
Dim RangoColTitulos As IXLCells = WS.FirstRow().CellsUsed()
|
||||||
|
|
||||||
|
WS.FirstCell().InsertTable(dt, False)
|
||||||
|
|
||||||
|
'Estilo
|
||||||
|
RangoColTitulos.Style.Fill.SetBackgroundColor(XLColor.FromArgb(75, 119, 190))
|
||||||
|
RangoColTitulos.Style.Font.SetBold(True)
|
||||||
|
RangoColTitulos.Style.Font.FontColor = XLColor.White
|
||||||
|
|
||||||
|
WS.Columns().AdjustToContents()
|
||||||
|
|
||||||
HttpContext.Current.Response.Clear()
|
HttpContext.Current.Response.Clear()
|
||||||
HttpContext.Current.Response.Buffer = True
|
HttpContext.Current.Response.Buffer = True
|
||||||
@@ -2527,7 +2537,7 @@ Namespace Extensiones
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
'usa la librería de gembox
|
'Usa la librería GemBox
|
||||||
<Runtime.CompilerServices.Extension()>
|
<Runtime.CompilerServices.Extension()>
|
||||||
Public Sub ExportToExcelG(Gv As GridView, NombreArchivoXLSx As String, Optional Titulo As String = "Reporte", Optional Usuario As Usuario = Nothing, Optional Filtros As String = "", Optional AlturaImagen As Double = 100, Optional AnchoImagen As Double = 100)
|
Public Sub ExportToExcelG(Gv As GridView, NombreArchivoXLSx As String, Optional Titulo As String = "Reporte", Optional Usuario As Usuario = Nothing, Optional Filtros As String = "", Optional AlturaImagen As Double = 100, Optional AnchoImagen As Double = 100)
|
||||||
Dim sw As New StringWriter()
|
Dim sw As New StringWriter()
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
<li>
|
<li>
|
||||||
<asp:LinkButton ID="LnkAutorizar" runat="server" data-toggle="confirmation" data-popout="true" data-original-title="¿Desea autorizar el presupuesto?" data-btn-ok-label="si"><i class="fa fa-check"></i> Autorizar</asp:LinkButton>
|
<asp:LinkButton ID="LnkAutorizar" runat="server" data-toggle="confirmation" data-popout="true" data-original-title="¿Desea autorizar el presupuesto?" data-btn-ok-label="si"><i class="fa fa-check"></i> Autorizar</asp:LinkButton>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<asp:LinkButton ID="LnkCargaPresupuesto" OnClick="LnkCargaPresupuesto_Click" runat="server"><i class="fa fa-upload"></i>Cargar Presupuesto</asp:LinkButton>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<asp:HyperLink ID="HlModificar" Target="_blank" Visible="false" runat="server"><i class="fa fa-edit"></i> Modificar Presupuesto</asp:HyperLink>
|
<asp:HyperLink ID="HlModificar" Target="_blank" Visible="false" runat="server"><i class="fa fa-edit"></i> Modificar Presupuesto</asp:HyperLink>
|
||||||
</li>
|
</li>
|
||||||
@@ -282,6 +285,61 @@
|
|||||||
</div>
|
</div>
|
||||||
</ContentTemplate>
|
</ContentTemplate>
|
||||||
</asp:UpdatePanel>
|
</asp:UpdatePanel>
|
||||||
|
<div id="ModalCargaPresupuesto" class="modal ADS fade" role="dialog">
|
||||||
|
<asp:UpdatePanel ID="UPCargaPresup" class="modal-dialog" tabindex="-1" runat="server" UpdateMode="Conditional">
|
||||||
|
<ContentTemplate>
|
||||||
|
<div class="modal-content rowpadding">
|
||||||
|
<div class="modal-header">
|
||||||
|
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||||
|
<span aria-hidden="true">×</span>
|
||||||
|
</button>
|
||||||
|
<h4 class="modal-title" runat="server" style="text-align: left">Cargar Presupuesto </h4>
|
||||||
|
</div>
|
||||||
|
<div class="modal-body">
|
||||||
|
|
||||||
|
<div class="portlet light smmallpadding bordered">
|
||||||
|
<div class="portlet-title">
|
||||||
|
<div class="caption font-green">
|
||||||
|
<i class="fa fa-upload font-green"></i>
|
||||||
|
<span class="caption-subject bold uppercase">Cargar archivo </span>
|
||||||
|
</div>
|
||||||
|
<div class="tools">
|
||||||
|
<a href="javascript:;" class="collapse" data-original-title="" title=""></a>
|
||||||
|
</div>
|
||||||
|
<div class="actions">
|
||||||
|
<div class="btn-group">
|
||||||
|
<asp:LinkButton ID="LnkFormatoPresup" OnClick="LnkFormatoPresup_Click" CssClass="btn yellow-gold" runat="server"><i class="fa fa-download"></i> Descargar Plantilla</asp:LinkButton>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="portlet-body rowpadding ">
|
||||||
|
<!--<div class=" row">
|
||||||
|
<div class="col-md-3">Concepto</div>
|
||||||
|
<div class="col-md-6">
|
||||||
|
<asp:DropDownList ID="ddlConceptocomisionNeto" runat="server" DataTextField="CodigoConcepto" DataValueField="CveConcepto" Class="form-control input-sm select2me" Width="100%" ValidationGroup="GrpGuardar"></asp:DropDownList>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
-->
|
||||||
|
<asp:TextBox ID="TxtCargarPresup" CssClass="ADSdropzone hidden" runat="server"></asp:TextBox>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="modal-footer">
|
||||||
|
<asp:UpdatePanel runat="server" UpdateMode="Conditional">
|
||||||
|
<ContentTemplate>
|
||||||
|
<asp:LinkButton ID="LnkCargarPresup" OnClick="LnkCargarPresup_Click" CssClass="btn btn-primary" runat="server">Procesar</asp:LinkButton>
|
||||||
|
</ContentTemplate>
|
||||||
|
</asp:UpdatePanel>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ContentTemplate>
|
||||||
|
<Triggers>
|
||||||
|
<asp:PostBackTrigger ControlID="LnkFormatoPresup" />
|
||||||
|
</Triggers>
|
||||||
|
</asp:UpdatePanel>
|
||||||
|
</div>
|
||||||
</asp:Content>
|
</asp:Content>
|
||||||
<asp:Content ID="Content8" ContentPlaceHolderID="JS" runat="Server">
|
<asp:Content ID="Content8" ContentPlaceHolderID="JS" runat="Server">
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|||||||
@@ -494,4 +494,76 @@ Partial Class Contratos_Presupuestos
|
|||||||
UpGvClasificaciones.Update()
|
UpGvClasificaciones.Update()
|
||||||
UpIndicadores.Update()
|
UpIndicadores.Update()
|
||||||
End Sub
|
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
|
End Class
|
||||||
|
|||||||
Reference in New Issue
Block a user