Rep personal DIM
This commit is contained in:
149
Nomina/RepPersonalDIM.aspx.vb
Normal file
149
Nomina/RepPersonalDIM.aspx.vb
Normal file
@@ -0,0 +1,149 @@
|
||||
Option Explicit On
|
||||
Option Strict On
|
||||
|
||||
Imports System.Data
|
||||
Imports System.Drawing
|
||||
Imports System.IO
|
||||
Imports Extensiones
|
||||
Imports GemBox.Spreadsheet
|
||||
Imports Microsoft.Reporting.WebForms
|
||||
|
||||
Partial Class Nomina_RepPersonalDIM
|
||||
Inherits ClsPaginas
|
||||
|
||||
Public Property Dt_Datos As DataTable
|
||||
Get
|
||||
If ViewState("Dt_Datos") Is Nothing Then
|
||||
ViewState("Dt_Datos") = New DataTable
|
||||
End If
|
||||
Return DirectCast(ViewState("Dt_Datos"), DataTable)
|
||||
End Get
|
||||
Set(value As DataTable)
|
||||
ViewState("Dt_Datos") = value
|
||||
End Set
|
||||
|
||||
End Property
|
||||
|
||||
Protected Sub Nomina_RepPersonalDIM(sender As Object, e As EventArgs) Handles Me.Load
|
||||
If Not Page.IsPostBack Then
|
||||
|
||||
CargaEjercicios()
|
||||
DdlEjercicio.SelectedValueExist(UsuarioActual.Empresa.EjercicioActual)
|
||||
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub CargaEjercicios()
|
||||
'Dim ClsConta As New ClsContPAQi(UsuarioActual.Empresa)
|
||||
Dim ClsConta As New ClsContabilidad
|
||||
If ClsConta.GetEjercicios(UsuarioActual.CveEmpresa) Then
|
||||
DdlEjercicio.DataSource = ClsConta.DtResultados
|
||||
Else
|
||||
DdlEjercicio.DataSource = Nothing
|
||||
End If
|
||||
ClsConta.Dispose()
|
||||
DdlEjercicio.DataBind()
|
||||
|
||||
DdlEjercicio.SelectedValueExist(UsuarioActual.Empresa.EjercicioActual.ToString)
|
||||
|
||||
If DdlEjercicio.Items.Count = 0 Then
|
||||
DdlEjercicio.Items.Add(New ListItem(Now.Year.ToString, Now.Year.ToString))
|
||||
End If
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Sub BtnConsultar_Click(sender As Object, e As EventArgs)
|
||||
CargaDatos()
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub CargaDatos()
|
||||
|
||||
Dt_Datos = New DataTable
|
||||
LnkDescargaArchivo.Visible = False
|
||||
LnkExportar.Visible = False
|
||||
|
||||
Dim ObjNom As New ClsNominas
|
||||
|
||||
|
||||
If ObjNom.GetRepPersonalDIM(Ejercicio:=DdlEjercicio.SelectedValue.ToEntero, CveEmpresa:=UsuarioActual.CveEmpresa) Then
|
||||
GvDatos.DataSource = ObjNom.DtResultados
|
||||
Dt_Datos = ObjNom.DtResultados
|
||||
|
||||
If Dt_Datos.Rows.Count > 0 Then
|
||||
LnkDescargaArchivo.Visible = True
|
||||
LnkExportar.Visible = True
|
||||
End If
|
||||
|
||||
|
||||
Else
|
||||
GvDatos.DataSource = Nothing
|
||||
End If
|
||||
|
||||
ObjNom.Dispose()
|
||||
|
||||
GvDatos.DataBind()
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
#Region "DESCARGA EXCEL"
|
||||
|
||||
Private Sub LnkExportar_Click(sender As Object, e As EventArgs) Handles LnkExportar.Click
|
||||
Imprimir("Excel")
|
||||
End Sub
|
||||
|
||||
Private Sub Imprimir(Optional reporte As String = "PDF")
|
||||
GvDatos.ExportToExcelGembox("RepPersonalDIM", UsuarioActual, "Reporte Personal ", "", DatosFiltros:=$"Ejercicio {DdlEjercicio.SelectedItem.Text}")
|
||||
|
||||
End Sub
|
||||
|
||||
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
|
||||
End Sub
|
||||
|
||||
Protected Sub LnkDescargaArchivo_Click(ByVal sender As Object, ByVal e As EventArgs) Handles LnkDescargaArchivo.Click
|
||||
Dim tabla As DataTable = Dt_Datos ' Reemplaza esto con tu método para obtener la tabla
|
||||
|
||||
Dim contenido As String = ConvertirTablaATexto(tabla)
|
||||
|
||||
' Guardar el archivo en el servidor
|
||||
Dim nombreArchivo As String = "tabla.txt"
|
||||
Dim rutaArchivo As String = Server.MapPath("~/Descargas/" & nombreArchivo)
|
||||
File.WriteAllText(rutaArchivo, contenido)
|
||||
|
||||
' Descargar el archivo
|
||||
Response.ContentType = "text/plain"
|
||||
Response.AppendHeader("Content-Disposition", "attachment; filename=" & nombreArchivo)
|
||||
Response.TransmitFile(rutaArchivo)
|
||||
Response.End()
|
||||
End Sub
|
||||
|
||||
Public Function ConvertirTablaATexto(ByVal tabla As DataTable) As String
|
||||
Dim sb As New StringBuilder()
|
||||
|
||||
For Each fila As DataRow In tabla.Rows
|
||||
For i As Integer = 0 To tabla.Columns.Count - 1
|
||||
sb.Append(fila(i).ToString())
|
||||
|
||||
If i < tabla.Columns.Count - 1 Then
|
||||
sb.Append("|") ' Agrega el separador de pipes
|
||||
End If
|
||||
Next
|
||||
|
||||
sb.AppendLine() ' Agrega un salto de línea al final de cada fila
|
||||
Next
|
||||
|
||||
Return sb.ToString()
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user