client/Catalogos/Mantenimiento/frmSectorEconomico.vb

182 lines
6.4 KiB
VB.net
Raw Normal View History

Public Class frmSectorEconomico
Private opcion As Boolean
Private idName As Integer
Private Sub frmSectorEconomico_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Iniciar()
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function Iniciar() As Boolean
Iniciar = False
Try
Limpiar()
llenarGrid()
DesHeader.Text = Me.Text
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Iniciar = True
End Function
Private Function Limpiar() As Boolean
Try
txtNombre.Enabled = False
txtNombre.Text = ""
txtId.Text = ""
txtId.Enabled = False
chkActivo.Enabled = False
chkActivo.Checked = False
BtnOk.Enabled = False
BtnEditar.Enabled = False
opcion = False
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
Private Function llenarGrid() As Boolean
llenarGrid = False
Try
Dim ClassCatalogos As New ClassCatalogos
GridMaster.AllowUpdate = False
ClassCatalogos.LlenaGrid("select * from CAT_SECTORECONOMICO", Me.GridMaster)
GridMaster.Splits(0).DisplayColumns(0).AutoSize()
GridMaster.Splits(0).DisplayColumns(1).AutoSize()
GridMaster.Splits(0).DisplayColumns(2).AutoSize()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
llenarGrid = True
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Me.Close()
End Sub
Private Sub BtnAgregar_Click(sender As System.Object, e As System.EventArgs) Handles BtnAgregar.Click
Limpiar()
habilitar()
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
opcion = True
End Sub
Private Function habilitar() As Boolean
habilitar = False
Try
txtNombre.Enabled = True
chkActivo.Enabled = True
BtnOk.Enabled = True
txtId.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
habilitar = True
End Function
Private Sub GridMaster_DoubleClick(sender As System.Object, e As System.EventArgs) Handles GridMaster.DoubleClick
llenarDatos()
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
End Sub
Private Function llenarDatos() As Boolean
llenarDatos = False
Try
idName = GridMaster.Columns(0).Value
txtId.Text = idName
txtNombre.Text = GridMaster.Columns(1).Value
chkActivo.Checked = GridMaster.Columns(2).Value
BtnEditar.Enabled = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
llenarDatos = True
End Function
Private Sub BtnEditar_Click(sender As System.Object, e As System.EventArgs) Handles BtnEditar.Click
opcion = False
habilitar()
txtId.Enabled = False
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
End Sub
Private Sub BtnOk_Click(sender As System.Object, e As System.EventArgs) Handles BtnOk.Click
Guardar()
End Sub
Private Function Guardar() As Boolean
Guardar = False
Dim cls As New clsComplejo
Dim ssql As String
Dim nombre As String
Dim chk As Integer
Dim classcom As New clsComplejo
Dim strSQLComodin As String
Try
If ValidarDatos() Then
nombre = txtNombre.Text.Trim()
chk = chkActivo.CheckState
If opcion Then
strSQLComodin = "SELECT * FROM CAT_SECTORECONOMICO where IDSECTORECONOMICO = " & txtId.Text
If classcom.BuscaDatos(strSQLComodin) Then
MessageBox.Show("Este id del sector económico ya existe en el catalogo ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
classcom.ds.Clear()
Exit Function
End If
strSQLComodin = "SELECT * FROM CAT_SECTORECONOMICO where SECTORECONOMICO = '" & txtNombre.Text & "'"
If classcom.BuscaDatos(strSQLComodin) Then
MessageBox.Show("Este nombre del sector económico ya existe en el catalogo ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
classcom.ds.Clear()
Exit Function
End If
idName = txtId.Text
ssql = "INSERT INTO CAT_SECTORECONOMICO(IDSECTORECONOMICO,SECTORECONOMICO,ACTIVO) "
ssql += " VALUES (" & idName & ",'" & nombre & "', " & chk & ")"
Else
ssql = "UPDATE CAT_SECTORECONOMICO SET SECTORECONOMICO ='" & nombre & "',"
ssql += "ACTIVO = " & chk & " WHERE IDSECTORECONOMICO =" & idName
End If
cls.sbGuardaModifica(ssql)
MessageBox.Show("Operacion Satisfactoria ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
Limpiar()
llenarGrid()
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Guardar = True
End Function
Private Function ValidarDatos() As Boolean
ValidarDatos = False
Try
If txtNombre.Text.Trim = "" Then
MessageBox.Show("Es Necesario Introducir el Nombre ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
ValidarDatos = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
Private Sub txtId_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtId.KeyPress
If Asc(e.KeyChar) <> 8 Then
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
End If
End If
End Sub
End Class