client/Reportes/frmReporteJ14.vb

159 lines
6.7 KiB
VB.net
Raw Normal View History

2020-03-10 11:10:16 -06:00
Imports System.Collections.Generic
Imports System.IO
Public Class frmReporteJ14
Dim comboKey As String
Dim year As String
Dim quarter As String
Dim canExport As Boolean
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.Click
Dim Classcom As New clsComplejo
Dim SQL As String = String.Empty
Dim idInherent As Integer
Dim idConrolEffect As Integer
2020-05-06 18:18:29 -05:00
Dim incluyeInvalidos As Integer
2020-03-10 11:10:16 -06:00
comboKey = DirectCast(cmbQuarter.SelectedItem, KeyValuePair(Of String, String)).Key
year = comboKey.Substring(0, 4)
quarter = comboKey.Substring(comboKey.Length - 1)
canExport = False
2020-05-06 18:18:29 -05:00
btnExport.Enabled = canExport
btnExport.Visible = canExport
2020-05-28 01:03:24 -05:00
btnExportXLS.Enabled = canExport
btnExportXLS.Visible = canExport
2020-05-06 18:18:29 -05:00
dgvResult.DataSource = Nothing
incluyeInvalidos = 0
Dim result As DialogResult = MessageBox.Show("¿Incluir registros sin NIC válido?",
"Reporte J14",
MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
incluyeInvalidos = 1
End If
2020-03-10 11:10:16 -06:00
Try
2020-05-06 18:18:29 -05:00
SQL = "sp_Consulta_ReporteJ14 " + year + ", " + quarter + ", " + incluyeInvalidos.ToString
2020-03-10 11:10:16 -06:00
Dim dsGral As DataSet = Classcom.fdtDataSet(SQL)
If dsGral.Tables.Count = 0 Then
2020-05-06 18:18:29 -05:00
MessageBox.Show("No existen registros para el trimestre seleccionado")
Exit Sub
2020-03-10 11:10:16 -06:00
ElseIf dsGral.Tables(0).Rows.Count = 0 Then
2020-05-06 18:18:29 -05:00
MessageBox.Show("No existen registros para el trimestre seleccionado")
Exit Sub
2020-03-10 11:10:16 -06:00
Else
canExport = True
End If
btnExport.Enabled = canExport
btnExport.Visible = canExport
2020-05-28 01:03:24 -05:00
btnExportXLS.Enabled = canExport
btnExportXLS.Visible = canExport
2020-03-10 11:10:16 -06:00
dgvResult.DataSource = dsGral.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
2020-05-28 01:03:24 -05:00
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 121, 1, "Búsqueda Reporte J14")
2020-03-10 11:10:16 -06:00
End Sub
Private Sub btnExport_Click(sender As Object, e As EventArgs) Handles btnExport.Click
Dim fileName As String = year.ToString + "_" + quarter.ToString + "_ R03 J-0314.txt"
2020-05-06 18:18:29 -05:00
Dim repDirectory As String = ""
Dim fullPath As String = fileName
2020-03-10 11:10:16 -06:00
Dim sr As StreamWriter
Dim strDelimiter As String = ";"
Dim intColumnCount As Integer = dgvResult.Columns.Count - 1
Dim strRowData As String = ""
2020-05-06 18:18:29 -05:00
Dim Classcom As New clsComplejo
2020-03-10 11:10:16 -06:00
Try
2020-05-06 18:18:29 -05:00
Classcom.fdtDataSet("SELECT * FROM ParamRep")
If Classcom.ds.Tables(0).Rows.Count <> 0 Then
repDirectory = Classcom.ds.Tables(0).Rows(0).Item("rutacarteras").ToString()
If Directory.Exists(repDirectory) = False Then ' si no existe la carpeta se crea
Directory.CreateDirectory(repDirectory)
End If
fullPath = repDirectory & "\" & fileName
End If
sr = File.CreateText(fullPath)
2020-03-10 11:10:16 -06:00
For intX As Integer = 0 To dgvResult.Rows.Count - 1
strRowData = ""
For intRowData As Integer = 0 To intColumnCount
strRowData += Replace(dgvResult.Rows(intX).Cells(intRowData).Value, strDelimiter, "") & IIf(intRowData < intColumnCount, strDelimiter, "") '''''''''highlights this row
Next intRowData
sr.WriteLine(strRowData)
Next intX
MessageBox.Show("Reporte generado correctamente")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
sr.Close()
2020-05-28 01:03:24 -05:00
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 121, 1, "Generando Reporte J14")
2020-03-10 11:10:16 -06:00
End Sub
Private Sub frmReporteJ14_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim initialYear As Integer
Dim currentYear As Integer
Dim comboSource As New Dictionary(Of String, String)()
2020-05-28 01:03:24 -05:00
initialYear = 2019
2020-03-10 11:10:16 -06:00
currentYear = Now.Year
For year As Integer = initialYear To currentYear
comboSource.Add(year.ToString + "1", year.ToString + " - 1")
comboSource.Add(year.ToString + "2", year.ToString + " - 2")
comboSource.Add(year.ToString + "3", year.ToString + " - 3")
comboSource.Add(year.ToString + "4", year.ToString + " - 4")
Next
cmbQuarter.DataSource = New BindingSource(comboSource, Nothing)
cmbQuarter.DisplayMember = "Value"
cmbQuarter.ValueMember = "Key"
canExport = False
btnExport.Enabled = canExport
btnExport.Visible = canExport
2020-05-28 01:03:24 -05:00
btnExportXLS.Enabled = canExport
btnExportXLS.Visible = canExport
2020-03-10 11:10:16 -06:00
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 121, 1, "Entrando Reporte J14")
End Sub
Private Sub frmReporteJ14_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 121, 1, "Cerrando Reporte J14")
End Sub
2020-05-28 01:03:24 -05:00
Private Sub btnExportXLS_Click(sender As Object, e As EventArgs) Handles btnExportXLS.Click
Dim fileName As String = year.ToString + "_" + quarter.ToString + "_ R03 J-0314"
Dim fullPath As String = fileName
Dim clsExcel As aExcel
Dim ds As New DataSet
Try
clsExcel = New aExcel
clsExcel.Titulo = fileName
ds.Tables.Add("ReporteJ14")
' Add Columns
Dim col As DataColumn
For Each dgvCol As DataGridViewColumn In dgvResult.Columns
col = New DataColumn(dgvCol.Name)
ds.Tables("ReporteJ14").Columns.Add(col)
Next
'Add Rows from the datagridview
Dim row As DataRow
Dim colcount As Integer = dgvResult.Columns.Count - 1
For i As Integer = 0 To dgvResult.Rows.Count - 1
row = ds.Tables("ReporteJ14").Rows.Add
For Each column As DataGridViewColumn In dgvResult.Columns
row.Item(column.Index) = dgvResult.Rows.Item(i).Cells(column.Index).Value
Next
Next
clsExcel.ExportDataset(ds)
'MessageBox.Show("Reporte generado correctamente")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 121, 1, "Exportando Reporte J14")
End Sub
2020-03-10 11:10:16 -06:00
End Class