Complementos de pago bancos, descarga de excel

This commit is contained in:
rakcsle
2021-09-28 09:29:08 -07:00
parent 209c6c8440
commit ba4543e105
2 changed files with 162 additions and 17 deletions

View File

@@ -1,4 +1,4 @@
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="RepComplementoPago.aspx.vb" Inherits="Bancos_RepComplementoPago" %> <%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="true" EnableEventValidation = "false" CodeFile="RepComplementoPago.aspx.vb" Inherits="Bancos_RepComplementoPago" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server"> <asp:Content ID="Content1" ContentPlaceHolderID="CP" runat="Server">
</asp:Content> </asp:Content>
@@ -10,15 +10,19 @@
<asp:Content ID="Content4" ContentPlaceHolderID="HB" runat="Server"> <asp:Content ID="Content4" ContentPlaceHolderID="HB" runat="Server">
</asp:Content> </asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="H" runat="Server"> <asp:Content ID="Content5" ContentPlaceHolderID="H" runat="Server">
<asp:UpdatePanel runat="server"> <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="UpAcciones">
<ContentTemplate> <ContentTemplate>
<li> <li>
<a><i class="fa fa-file-pdf-o" style="font-weight: bold;"></i>PDF</a> <%--<a><i class="fa fa-file-pdf-o" style="font-weight: bold;"></i>PDF</a>--%>
<asp:LinkButton ID="LnkExcel" runat="server" OnClick="LnkExcel_Click" Text="<i class='fa fa-file-excel-o'></i> Excel" Visible="false" />
</li> </li>
<li> <li>
<asp:LinkButton ID="BtnEmitir" runat="server" Text="<i class='fa fa-print'></i> Emitir" Visible="false" /> <asp:LinkButton ID="BtnEmitir" runat="server" Text="<i class='fa fa-print'></i> Emitir" Visible="false" />
</li> </li>
</ContentTemplate> </ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="LnkExcel" />
</Triggers>
</asp:UpdatePanel> </asp:UpdatePanel>
</asp:Content> </asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="HA" runat="Server"> <asp:Content ID="Content6" ContentPlaceHolderID="HA" runat="Server">

View File

@@ -1,8 +1,10 @@
Option Explicit On Option Explicit On
Option Strict On Option Strict On
Imports System.Data Imports System.Data
Imports System.IO
Imports Extensiones Imports Extensiones
Imports GemBox.Spreadsheet
Partial Class Bancos_RepComplementoPago Partial Class Bancos_RepComplementoPago
Inherits ClsPaginas Inherits ClsPaginas
@@ -33,16 +35,26 @@ Partial Class Bancos_RepComplementoPago
Private Sub CargaDatos() Private Sub CargaDatos()
Dim CveCliente As Integer = If(DdlCliente.SelectedValue.ToEntero > 0, DdlCliente.SelectedValue.ToEntero, -1) Dim CveCliente As Integer = If(DdlCliente.SelectedValue.ToEntero > 0, DdlCliente.SelectedValue.ToEntero, -1)
Dim Banco As New ClsBancos Dim Banco As New ClsBancos
LnkExcel.Visible = False
If Banco.GetComplementoPagosRep(CveCliente, txtFechaI.Text.ToDateTime, txtFechaF.Text.ToDateTime, -1, -1, DdlOpcion.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, Estatus:=DdlEstatus.SelectedValue.ToEntero) Then If Banco.GetComplementoPagosRep(CveCliente, txtFechaI.Text.ToDateTime, txtFechaF.Text.ToDateTime, -1, -1, DdlOpcion.SelectedValue.ToEntero, UsuarioActual.CveEmpresa, Estatus:=DdlEstatus.SelectedValue.ToEntero) Then
GvD.DataSource = Banco.DtResultados '.FiltraParametros("CveComplementoPago is null") GvD.DataSource = Banco.DtResultados '.FiltraParametros("CveComplementoPago is null")
If Banco.DtResultados.Rows.Count > 0 Then
LnkExcel.Visible = True
End If
End If End If
Banco.Dispose() Banco.Dispose()
If DdlOpcion.SelectedValue = "2" Then GvD.Columns(8).Visible = True Else GvD.Columns(8).Visible = False If DdlOpcion.SelectedValue = "2" Then GvD.Columns(8).Visible = True Else GvD.Columns(8).Visible = False
GvD.DataBind() GvD.DataBind()
UpDatos.Update() UpDatos.Update()
UpAcciones.Update()
End Sub End Sub
Private Sub GeneraTimbre() Private Sub GeneraTimbre()
@@ -125,16 +137,16 @@ Partial Class Bancos_RepComplementoPago
If e.Row.DBCampo("BloqueadoUtilerias") = "1" Then If e.Row.DBCampo("BloqueadoUtilerias") = "1" Then
Mensaje = "Bloqueado Timbrando por aplicacion" Mensaje = "Bloqueado Timbrando por aplicacion"
End If End If
e.Row.FCLiteral("LtlMon").Text = e.Row.DBCampo("PagoAbreviaturaSAT") e.Row.FCLiteral("LtlMon").Text = e.Row.DBCampo("PagoAbreviaturaSAT")
If Not Mensaje.Length = 0 Then If Not Mensaje.Length = 0 Then
e.Row.ForeColor = Drawing.Color.Red e.Row.ForeColor = Drawing.Color.Red
e.Row.FCCheckBox("Chk").Enabled = False e.Row.FCCheckBox("Chk").Enabled = False
e.Row.FCCheckBox("Chk").ToolTip = Mensaje e.Row.FCCheckBox("Chk").ToolTip = Mensaje
End If End If
Else Else
e.Row.FCHyperLink("HplXML").Visible = True : e.Row.FCHyperLink("HplXML").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CompP&EXT=xml&CveComplementoPago={0}&SerieFolio={1}&CveIE={2}", e.Row.DBCampo("CveComplementoPago"), e.Row.DBCampo("SerieFolioPago").ToString.Replace("&", "%26%"), e.Row.DBCampo("CveIE").ToString))) e.Row.FCHyperLink("HplXML").Visible = True : e.Row.FCHyperLink("HplXML").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CompP&EXT=xml&CveComplementoPago={0}&SerieFolio={1}&CveIE={2}", e.Row.DBCampo("CveComplementoPago"), e.Row.DBCampo("SerieFolioPago").ToString.Replace("&", "%26%"), e.Row.DBCampo("CveIE").ToString)))
e.Row.FCHyperLink("HplPDF").Visible = True : e.Row.FCHyperLink("HplPDF").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CompP&EXT=pdf&CveComplementoPago={0}&SerieFolio={1}&CveIE={2}", e.Row.DBCampo("CveComplementoPago"), e.Row.DBCampo("SerieFolioPago").ToString.Replace("&", "%26%"), e.Row.DBCampo("CveIE").ToString))) e.Row.FCHyperLink("HplPDF").Visible = True : e.Row.FCHyperLink("HplPDF").NavigateUrl = String.Format("/Compras/PopUpVerFactura.aspx?P={0}", Encripta(String.Format("OP=CompP&EXT=pdf&CveComplementoPago={0}&SerieFolio={1}&CveIE={2}", e.Row.DBCampo("CveComplementoPago"), e.Row.DBCampo("SerieFolioPago").ToString.Replace("&", "%26%"), e.Row.DBCampo("CveIE").ToString)))
e.Row.FCLinkButton("LnkSendMail").Visible = True e.Row.FCLinkButton("LnkSendMail").Visible = True
@@ -378,8 +390,8 @@ Partial Class Bancos_RepComplementoPago
End If End If
Else Else
respuesta = False respuesta = False
End If End If
Return respuesta Return respuesta
End Function End Function
@@ -390,5 +402,134 @@ Partial Class Bancos_RepComplementoPago
TxtParaMail.Text = gvRow.DataKey("CobranzaCorreo").ToString TxtParaMail.Text = gvRow.DataKey("CobranzaCorreo").ToString
UpSendMail.Update() UpSendMail.Update()
RegistraScript("$('#ModalDivMail').modal('show');") RegistraScript("$('#ModalDivMail').modal('show');")
End Sub
Protected Sub LnkExcel_Click(sender As Object, e As EventArgs)
' GvD.ExportToExcelG("ReporteComplementos", "Reporte Complementos", UsuarioActual)
'GvD.ExportToExcelx("ReporteComplementos.xlsx")
' GvD.ExportToExcel("ReporteComplementos.xlsx")
Imprimir("Excel")
End Sub
Private Sub Imprimir(Optional reporte As String = "PDF")
If GvD.Rows.Count > 0 Then
Dim StrFiltro As New StringBuilder
'If DdlProveedor.SelectedValue.ToEntero > 0 Then StrFiltro.AppendFormat("Proveedor: {0},", DdlProveedor.SelectedText)
'If ddlProducto2.SelectedValue.ToEntero > 0 Then StrFiltro.AppendFormat(" Producto/Servicio: {0},", ddlProducto2.SelectedText)
If txtFechaI.Text <> "" Then StrFiltro.AppendFormat(" Fecha Inicio: {0} ", txtFechaI.Text)
If txtFechaF.Text <> "" Then StrFiltro.AppendFormat(" Fecha Fin: {0}", txtFechaF.Text)
ExportToExcelG(GvD, "ReporteComplementos.xlsx", "Reporte complementos de pago", UsuarioActual, StrFiltro.ToString, 100, 150)
Else
Alert("Debe consultar para generar un excel", TipoMensaje.MsgAdvertencia)
End If
End Sub
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 htw As New HtmlTextWriter(sw)
Gv.RenderControl(htw)
GemBox.Spreadsheet.SpreadsheetInfo.SetLicense("ESWN-4QFD-26JF-1SZ8")
Dim excel As GemBox.Spreadsheet.ExcelFile
Dim options = GemBox.Spreadsheet.LoadOptions.HtmlDefault
Using htmlStream = New MemoryStream(options.Encoding.GetBytes(sw.ToString()))
excel = GemBox.Spreadsheet.ExcelFile.Load(htmlStream, options)
If Usuario IsNot Nothing Then
Dim TotalRowHeader As Integer = 8
Dim TotalRowFooter As Integer = 2
Dim worksheet = excel.Worksheets(0)
worksheet.Rows.InsertEmpty(0, TotalRowHeader)
Dim celdasConTexto = worksheet.GetUsedCellRange(True)
celdasConTexto.Style.Font.Name = "Calibri Light"
Dim RangoNombreEmpresa = worksheet.Cells.GetSubrangeAbsolute(1, celdasConTexto.FirstColumnIndex, 1, celdasConTexto.LastColumnIndex)
RangoNombreEmpresa.Merged = True
RangoNombreEmpresa.Value = Usuario.Empresa.Empresa
RangoNombreEmpresa.Style.Font.Size = 18 * 20
RangoNombreEmpresa.Style.Font.Name = "Calibri Light"
RangoNombreEmpresa.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
RangoNombreEmpresa.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
Dim RangoFiltros = worksheet.Cells.GetSubrangeAbsolute(6, celdasConTexto.FirstColumnIndex, 6, celdasConTexto.LastColumnIndex)
RangoFiltros.Merged = True
RangoFiltros.Value = Filtros
RangoFiltros.Style.Font.Size = 15 * 20
RangoFiltros.Style.Font.Name = "Calibri Light"
RangoFiltros.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Left
RangoFiltros.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
Dim RangoTitulo = worksheet.Cells.GetSubrangeAbsolute(3, celdasConTexto.FirstColumnIndex, 3, celdasConTexto.LastColumnIndex)
RangoTitulo.Merged = True
RangoTitulo.Value = Titulo
RangoTitulo.Style.Font.Size = 20 * 20
RangoTitulo.Style.Font.Name = "Calibri Light"
RangoTitulo.Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
RangoTitulo.Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
worksheet.Columns("C").Width = 20000
worksheet.Columns("D").Width = 4000
worksheet.Columns("E").Width = 6000
worksheet.Columns("F").Width = 6000
worksheet.Columns("G").Width = 4000
worksheet.Columns("H").Width = 12000
For i = celdasConTexto.FirstColumnIndex To celdasConTexto.LastColumnIndex
worksheet.Rows(8).Cells(i).Style.Font.Size = 12 * 20
worksheet.Rows(8).Cells(i).Style.HorizontalAlignment = GemBox.Spreadsheet.HorizontalAlignmentStyle.Center
worksheet.Rows(8).Cells(i).Style.VerticalAlignment = GemBox.Spreadsheet.VerticalAlignmentStyle.Center
worksheet.Rows(8).Cells(i).Style.FillPattern.SetPattern(GemBox.Spreadsheet.FillPatternStyle.Solid, GemBox.Spreadsheet.SpreadsheetColor.FromArgb(75, 119, 190), GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255))
worksheet.Rows(8).Cells(i).Style.Font.Color = GemBox.Spreadsheet.SpreadsheetColor.FromArgb(255, 255, 255)
If i > 0 Then
Try
worksheet.Columns(i).AutoFit(1)
Catch ex As Exception
End Try
End If
Next
Dim IndexEndTable As Integer = Gv.Rows.Count + TotalRowHeader + TotalRowFooter
worksheet.Rows(IndexEndTable).Cells(2).Value = "Usuario Imprimió"
worksheet.Rows(IndexEndTable + 1).Cells(2).Value = Usuario.Nombre
worksheet.Rows(IndexEndTable).Cells(6).Value = "Fecha Impresión"
worksheet.Rows(IndexEndTable + 1).Cells(6).Value = DateTime.Now.ToString("dd/MM/yyyy")
Dim Imagen As New System.IO.FileInfo(String.Format("{0}/Logo.png", Usuario.Empresa.Ruta))
If Imagen.Exists Then
Dim Ruta As String = String.Format("{0}/Logo.png", Usuario.Empresa.Ruta)
Using sr As New StreamReader(Ruta)
Dim ms As New MemoryStream()
sr.BaseStream.CopyTo(ms)
worksheet.Pictures.Add(ms, ExcelPictureFormat.Png, "A1", AnchoImagen, AlturaImagen, LengthUnit.Pixel)
End Using
End If
End If
End Using
htw.Dispose()
excel.Save(HttpContext.Current.Response, $"{NombreArchivoXLSx}.xlsx")
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub End Sub
End Class End Class