client/Reportes/FrmRepAnonimo.vb

201 lines
8.4 KiB
VB.net
Raw Permalink Normal View History

Imports System.Collections.Generic
Public Class FrmRepAnonimo
Dim FilaActual As Integer
Private Sub FrmRepAnonimo_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
''LLena Grid
LlenaGrid()
FilaActual = -1
''Llena combo
cmbEstatus.Items.Clear()
Dim MiDic As New Dictionary(Of Integer, String)()
MiDic.Add(0, "SELECCIONAR ESTATUS")
MiDic.Add(1, "NO REVISADO")
MiDic.Add(2, "REVISADO")
cmbEstatus.DataSource = New BindingSource(MiDic, Nothing)
cmbEstatus.DisplayMember = "Value"
cmbEstatus.ValueMember = "Key"
cmbEstatus.SelectedIndex = 0
Catch ex As Exception
MessageBox.Show("Hubo un problema en el acceso a la base de datos.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Public Sub LLenaGrid()
Dim SQLProm As String
Dim clCmj2 As New clsComplejo
Try
''LLena Grid
SQLProm = "SELECT IdReporte Id, Reporte, DatosPersona Datos, Fecha, ComentariosOC [Comentarios OC], IdEstatus Estatus, "
SQLProm = SQLProm & " (CASE WHEN IdEstatus = 1 THEN 'NO REVISADO' "
SQLProm = SQLProm & " WHEN IdEstatus = 2 THEN 'REVISADO' "
SQLProm = SQLProm & " END ) [Estatus Reporte], FechaUltMod [Fecha Ultima Modif.] "
SQLProm = SQLProm & " FROM ReporteAnonimo "
clCmj2.fdtDataSetTabla(SQLProm)
GRDMasterRep.SetDataBinding(clCmj2.ds, "Tabla")
Catch ex As Exception
MessageBox.Show("Hubo un problema en el acceso a la base de datos.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Private Sub GRDMasterRep_DoubleClick(sender As System.Object, e As System.EventArgs) Handles GRDMasterRep.DoubleClick
Dim Classcom As New SenteciasSQL.ClassSQL
Try
If GRDMasterRep.Row < 0 Then
Exit Sub
End If
FilaActual = GRDMasterRep.Row
txtIdReporte.Text = GRDMasterRep.DataSource.tables(0).Rows(FilaActual)(0)
txtReporte.Text = GRDMasterRep.DataSource.tables(0).Rows(FilaActual)(1) & ""
txtDatosPersona.Text = GRDMasterRep.DataSource.tables(0).Rows(FilaActual)(2) & ""
txtComentarios.Text = GRDMasterRep.DataSource.tables(0).Rows(FilaActual)(4) & ""
cmbEstatus.SelectedValue = GRDMasterRep.DataSource.tables(0).Rows(FilaActual)(5)
txtFechaUltMod.Text = GRDMasterRep.DataSource.tables(0).Rows(FilaActual)(3) & ""
''Guarda valores anteriores para auditoria.
txtComenAnterior.Text = txtComentarios.Text
txtEstatusAnterior.Text = cmbEstatus.SelectedItem.Value
Catch ex As Exception
MessageBox.Show("Error Busqueda; sbBuscas: " & ex.Message, "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End Try
End Sub
Private Sub btnSalir_Click(sender As System.Object, e As System.EventArgs) Handles btnSalir.Click
Me.Close()
End Sub
Private Sub btnGuardar_Click(sender As System.Object, e As System.EventArgs) Handles btnGuardar.Click
Dim SQLProm As String
Dim clCmj As New clsComplejo
Dim sComentario As String
Try
If FilaActual < 0 Then
MessageBox.Show("Seleccione un registro para actualizar el reporte.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If txtComentarios.Text.Trim() = "" Then
MessageBox.Show("Escriba un comentario para actualizar el reporte.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If cmbEstatus.SelectedValue <= 0 Then
MessageBox.Show("Seleccione un estatus para actualizar el reporte.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
If txtComentarios.Text = txtComenAnterior.Text And txtEstatusAnterior.Text = cmbEstatus.SelectedItem.Value Then
MessageBox.Show("No hay cambios en el comentario ni tampoco en el estatus. No hay nada que guardar.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Sub
End If
''LLama a la subrutina de Update que actualiza texto que contiene comilla sencilla.
Actualizacion(txtIdReporte.Text, txtComentarios.Text, cmbEstatus.SelectedValue)
Catch ex As Exception
MessageBox.Show("Hubo un problema en el acceso a la base de datos.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Public Sub Actualizacion(iIdReporte As Integer, sComentario As String, iEstatus As Integer)
''Utilizo esta subrutina especial, para guardar texto libre, incluyendo la comilla sencilla.
Dim clCmj As New clsComplejo
Dim commandText As String = "EXEC sp_U_ReporteAnomimo @IdReporte, @ComentariosOC, @IdEstatus "
Dim command As SqlClient.SqlCommand
''Abre conexion
clCmj.ConectaBD()
'Using connection As New SqlClient.SqlConnection(clCmj.cn.ConnectionString)
command = New SqlClient.SqlCommand(commandText, clCmj.cn)
command.Parameters.Add("@IdReporte", SqlDbType.Int)
command.Parameters("@IdReporte").Value = iIdReporte
command.Parameters.Add("@ComentariosOC", SqlDbType.VarChar)
command.Parameters("@ComentariosOC").Value = sComentario
command.Parameters.Add("@IdEstatus", SqlDbType.Int)
command.Parameters("@IdEstatus").Value = iEstatus
Try
'command.ExecuteReader()
Dim sResultado As String = command.ExecuteScalar().ToString()
If sResultado = "OK" Then
MessageBox.Show("El registro se guardó correctamente.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
LLenaGrid()
''Coloca el cursor en la posicion actual.
GRDMasterRep.Row = FilaActual
GuardaAuditoria()
LimpiaCampos()
Else
MessageBox.Show("Hubo un problema al guardar la información.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show("Hubo un problema en el acceso a la base de datos.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
''Cierra conexion
clCmj.sbCierraCn()
End Sub
Public Sub GuardaAuditoria()
Try
'Auditoria
Dim classcom As New clsComplejo
Dim ClassAud As New ClassMyUtils
Dim sAuditoria As String
sAuditoria = ""
sAuditoria = "Actualizacion de Reporte Anónimo."
''Datos anteriores
sAuditoria = sAuditoria & " Num. IdReporte : " & txtIdReporte.Text & ", "
sAuditoria = sAuditoria & " Comentario Anterior: " & txtComenAnterior.Text.Replace("'", "") & ", "
sAuditoria = sAuditoria & " Estatus anterior: " & txtEstatusAnterior.Text & ", "
''Datos modificados
sAuditoria = sAuditoria & " Comentario Nuevo: " & txtComentarios.Text.Replace("'", "") & ", "
sAuditoria = sAuditoria & " Estatus Nuevo: " & cmbEstatus.SelectedItem.Value
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 4, My.Computer.Name, "Minds Cliente", sAuditoria)
Catch ex As Exception
MessageBox.Show("Hubo un problema al generar el registro de auditoria.", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
End Sub
Public Sub LimpiaCampos()
txtReporte.Text = ""
txtDatosPersona.Text = ""
txtComentarios.Text = ""
cmbEstatus.SelectedValue = 0
txtFechaUltMod.Text = ""
FilaActual = -1
txtIdReporte.Text = ""
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim FrmEmail As frmEmailAnonimo = New frmEmailAnonimo
FrmEmail.ShowDialog()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnFTP.Click
Dim FrmEmail As FrmEmailFTP = New FrmEmailFTP
FrmEmail.ShowDialog()
End Sub
End Class