client/Reportes/frmReporteJ14.vb
2020-03-10 11:10:16 -06:00

88 lines
3.6 KiB
VB.net

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
comboKey = DirectCast(cmbQuarter.SelectedItem, KeyValuePair(Of String, String)).Key
year = comboKey.Substring(0, 4)
quarter = comboKey.Substring(comboKey.Length - 1)
canExport = False
Try
SQL = "sp_Consulta_ReporteJ14 " + year + ", " + quarter
Dim dsGral As DataSet = Classcom.fdtDataSet(SQL)
If dsGral.Tables.Count = 0 Then
MessageBox.Show("No existen registros para el semestre seleccionado")
ElseIf dsGral.Tables(0).Rows.Count = 0 Then
MessageBox.Show("No existen registros para el semestre seleccionado")
Else
canExport = True
End If
btnExport.Enabled = canExport
btnExport.Visible = canExport
dgvResult.DataSource = dsGral.Tables(0)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
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"
Dim sr As StreamWriter
Dim strDelimiter As String = ";"
Dim intColumnCount As Integer = dgvResult.Columns.Count - 1
Dim strRowData As String = ""
Try
sr = File.CreateText(fileName)
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()
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)()
initialYear = 2020
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
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
End Class