client/Catalogos/Mantenimiento/frmCatEBR.vb

464 lines
18 KiB
VB.net

Public Class frmCatEBR
Private opcion As Boolean
Private idName As Integer
Private tabla As String
Private update As String
Private Sub frmCatEBR_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Iniciar()
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
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 86, 1, "Entrando a los Catalogos de EBR")
TabControl1.TabPages.Remove(TabPage1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Iniciar = True
End Function
Private Function Limpiar() As Boolean
Try
BtnOk.Enabled = False
BtnEditar.Enabled = False
sizeColumns(Me, False)
opcion = False
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
Public Function sizeColumns(ByRef MainParent As Control, edit As Boolean) As Boolean
Dim classcom As New clsComplejo
If Not MainParent.HasChildren Then Exit Function
For Each x As Control In MainParent.Controls()
If x.HasChildren Then sizeColumns(x, edit)
Select Case True
Case TypeOf x Is C1.Win.C1TrueDBGrid.C1TrueDBGrid
classcom.ColsGridAutosize(x)
tabla = IIf(edit, x.Tag.ToString(), "")
Case TypeOf x Is TextBox
If edit Then
If x.Text = "" Then
MessageBox.Show("Ingresar un valor al campo.", "MINDS")
x.Focus()
Return False
Else
x.Text = x.Text
End If
Else
x.Text = ""
End If
x.Enabled = edit
update += IIf(edit, x.Tag & "='" & x.Text & "',", "")
End Select
Next
Return True
End Function
Private Function llenarGrid() As Boolean
llenarGrid = False
Try
Dim cls As New clsComplejo
Dim ds As New DataSet
ds = cls.fdtDataSet("SP_S_EBR_CATS")
'C1TrueDBGrid1.DataSource = ds.Tables(0)
'C1TrueDBGrid1.Splits(0).DisplayColumns(0).Visible = False
C1TrueDBGrid2.DataSource = ds.Tables(1)
C1TrueDBGrid2.Splits(0).DisplayColumns(0).Visible = False
C1TrueDBGrid2.Splits(0).DisplayColumns(1).Visible = False
C1TrueDBGrid3.DataSource = ds.Tables(2)
C1TrueDBGrid3.Splits(0).DisplayColumns(0).Visible = False
C1TrueDBGrid4.DataSource = ds.Tables(3)
C1TrueDBGrid4.Splits(0).DisplayColumns(0).Visible = False
C1TrueDBGrid4.Splits(0).DisplayColumns(1).Visible = False 'grado
C1TrueDBGrid5.DataSource = ds.Tables(4)
C1TrueDBGrid5.Splits(0).DisplayColumns(0).Visible = False 'tipo
C1TrueDBGrid5.Splits(0).DisplayColumns(1).Visible = False
C1TrueDBGrid6.DataSource = ds.Tables(5)
C1TrueDBGrid6.Splits(0).DisplayColumns(0).Visible = False 'PEP
C1TrueDBGrid6.Splits(0).DisplayColumns(1).Visible = False 'PEP
C1TrueDBGrid7.DataSource = ds.Tables(6)
C1TrueDBGrid7.Splits(0).DisplayColumns(0).Visible = False 'SERVICIOS
C1TrueDBGrid7.Splits(0).DisplayColumns(1).Visible = False 'SERVICIOS
C1TrueDBGrid8.DataSource = ds.Tables(7)
C1TrueDBGrid8.Splits(0).DisplayColumns(0).Visible = False 'DOMICILIO
C1TrueDBGrid8.Splits(0).DisplayColumns(1).Visible = False
C1TrueDBGrid9.DataSource = ds.Tables(8)
C1TrueDBGrid9.Splits(0).DisplayColumns(0).Visible = False
C1TrueDBGrid9.Splits(0).DisplayColumns(1).Visible = False 'OPERACIONES
C1TrueDBGrid10.DataSource = ds.Tables(9)
C1TrueDBGrid10.Splits(0).DisplayColumns(0).Visible = False
C1TrueDBGrid11.DataSource = ds.Tables(10)
C1TrueDBGrid11.Splits(0).DisplayColumns(0).Visible = False
update = ""
sizeColumns(Me, False)
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
BtnOk.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 C1TrueDBGrid1.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid1.Columns(0).Value
txtNombre.Text = C1TrueDBGrid1.Columns(1).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub BtnEditar_Click(sender As System.Object, e As System.EventArgs) Handles BtnEditar.Click
opcion = False
'habilitar()
BtnOk.Enabled = True
update = ""
sizeColumns(TabControl1.SelectedTab, True)
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 86, 1, "Edicion al Catalogo EBR: " & tabla & " Valores: " & update.Replace("'", ""))
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
End Sub
Private Sub BtnOk_Click(sender As System.Object, e As System.EventArgs) Handles BtnOk.Click
update = ""
If sizeColumns(TabControl1.SelectedTab, True) Then
Guardar()
End If
End Sub
Private Function Guardar() As Boolean
Guardar = False
Dim cls As New clsComplejo
Dim ssql As String
Dim suma As Single
Try
If tabla.ToUpper = "EBR_CAT_IRSUBF" Then
ssql = "Select SUM(WEIGHT) + " & IIf(TextBox1.Text = "", 0, TextBox1.Text) & " from EBR_CAT_IRSUBF WHERE ID <> " & idName
cls.fdtDataSetTabla(ssql)
If cls.ds.Tables(0).Rows.Count > 0 Then
suma = cls.ds.Tables(0).Rows(0).Item(0).ToString()
End If
If suma < 1 Then
If MsgBox("El valor capturado sumado con los otros valores, no llega al 100 %, ¿Desea continuar?", MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2 + MsgBoxStyle.Question) = vbNo Then
Exit Function
End If
End If
End If
ssql = "UPDATE " & tabla & " SET " & update.Substring(0, update.Length - 1) & " WHERE ID = " & idName
cls.sbGuardaModifica(ssql)
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 86, 1, "Modificación al Catalogo EBR: " & tabla & " Valores: " & update.Replace("'", ""))
MessageBox.Show("Operacion Satisfactoria ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
If suma > 1 Then
Validaciones()
End If
sizeColumns(Me, False)
llenarGrid()
BtnOk.Enabled = False
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Guardar = True
End Function
Private Function Validaciones() As Boolean
Dim cls As New clsComplejo
Dim ssql As String
Dim ds As DataSet
Try
ssql = "EBR_SUMACATS"
ds = cls.fdtDataSet(ssql)
If (ds.Tables(0).Rows(0)(0) > 1) Then
If TabControl1.SelectedTab Is TabPage2 Then
MessageBox.Show("La suma de los Factores Inherentes es mayor a 100", "MINDS")
Return True
End If
TabControl1.SelectedTab = TabPage2
Return False
ElseIf (ds.Tables(0).Rows(0)(0) < 1) Then
MessageBox.Show("La suma de los Factores Inherentes es menor a 100", "MINDS")
Return True
End If
If (ds.Tables(1).Rows(0)(0) > 100) Then
If TabControl1.SelectedTab Is TabPage10 Then
MessageBox.Show("La suma de la Efectividad de los controles es mayor a 100", "MINDS")
End If
TabControl1.SelectedTab = TabPage10
Return False
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Return 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 C1TrueDBGrid2_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid2.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid2.Columns(0).Value
TextBox2.Text = C1TrueDBGrid2.Columns(3).Value
TextBox1.Text = C1TrueDBGrid2.Columns(4).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid3_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid3.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid3.Columns(0).Value
TextBox4.Text = C1TrueDBGrid3.Columns(1).Value
TextBox3.Text = C1TrueDBGrid3.Columns(2).Value
TextBox21.Text = C1TrueDBGrid3.Columns(3).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid4_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid4.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid4.Columns(0).Value
TextBox6.Text = C1TrueDBGrid4.Columns(2).Value
TextBox5.Text = C1TrueDBGrid4.Columns(3).Value
TextBox22.Text = C1TrueDBGrid4.Columns(4).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid5_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid5.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid5.Columns(0).Value
TextBox8.Text = C1TrueDBGrid5.Columns(2).Value
TextBox7.Text = C1TrueDBGrid5.Columns(3).Value
TextBox23.Text = C1TrueDBGrid5.Columns(4).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid6_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid6.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid6.Columns(0).Value
TextBox10.Text = C1TrueDBGrid6.Columns(2).Value
TextBox24.Text = C1TrueDBGrid6.Columns(3).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid7_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid7.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid7.Columns(0).Value
TextBox12.Text = C1TrueDBGrid7.Columns(2).Value
TextBox11.Text = C1TrueDBGrid7.Columns(3).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid8_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid8.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid8.Columns(0).Value
TextBox14.Text = C1TrueDBGrid8.Columns(2).Value
TextBox9.Text = C1TrueDBGrid8.Columns(3).Value
TextBox13.Text = C1TrueDBGrid8.Columns(4).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid9_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid9.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid9.Columns(0).Value
TextBox16.Text = C1TrueDBGrid9.Columns(2).Value
TextBox15.Text = C1TrueDBGrid9.Columns(3).Value
TextBox25.Text = C1TrueDBGrid9.Columns(4).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid10_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid10.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid10.Columns(0).Value
TextBox18.Text = C1TrueDBGrid10.Columns(1).Value
TextBox17.Text = C1TrueDBGrid10.Columns(2).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub C1TrueDBGrid11_DoubleClick(sender As Object, e As EventArgs) Handles C1TrueDBGrid11.DoubleClick
Try
Limpiar()
idName = C1TrueDBGrid11.Columns(0).Value
TextBox20.Text = C1TrueDBGrid11.Columns(1).Value
TextBox19.Text = C1TrueDBGrid11.Columns(2).Value
BtnEditar.Enabled = True
ClassCatalogos.CambiaColorbloque2(BtnEditar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub TabControl1_Selected(sender As Object, e As TabControlEventArgs) Handles TabControl1.Selected
Limpiar()
Validaciones()
sizeColumns(Me, False)
End Sub
Private Sub frmCatEBR_Closed(sender As Object, e As EventArgs) Handles Me.Closed
Dim ClassAud As New ClassMyUtils
ClassAud.RT_Auditoria(clsVaribles.varUsuario, 86, 1, "Cerrando Catalogos de EBR")
End Sub
Private Sub TextBox2_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox2.KeyPress, TextBox4.KeyPress, TextBox8.KeyPress, TextBox6.KeyPress, TextBox20.KeyPress, TextBox18.KeyPress, TextBox16.KeyPress, TextBox14.KeyPress, TextBox12.KeyPress, TextBox10.KeyPress
If Not (Asc(e.KeyChar) = 8) Then
If Not ((Asc(e.KeyChar) >= 97 And Asc(e.KeyChar) <= 122) Or (Asc(e.KeyChar) >= 65 And Asc(e.KeyChar) <= 90) Or (Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57)) Then
e.KeyChar = ChrW(0)
e.Handled = True
End If
End If
End Sub
Private Sub frmCatEBR_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
If Not Validaciones() Then
e.Cancel = True
End If
End Sub
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress, TextBox9.KeyPress, TextBox7.KeyPress, TextBox5.KeyPress, TextBox3.KeyPress, TextBox25.KeyPress, TextBox24.KeyPress, TextBox23.KeyPress, TextBox22.KeyPress, TextBox21.KeyPress, TextBox19.KeyPress, TextBox17.KeyPress, TextBox15.KeyPress, TextBox13.KeyPress, TextBox11.KeyPress
If Not (Asc(e.KeyChar) = 8) Then
If Not ((Asc(e.KeyChar) >= 48 And Asc(e.KeyChar) <= 57) Or Asc(e.KeyChar) = 46) Then
e.KeyChar = ChrW(0)
e.Handled = True
End If
End If
End Sub
Private Sub TabControl1_Selecting(sender As Object, e As TabControlCancelEventArgs) Handles TabControl1.Selecting
'Validaciones()
'sizeColumns(Me, False)
End Sub
Private Sub TabControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles TabControl1.SelectedIndexChanged
'Validaciones()
'sizeColumns(Me, False)
End Sub
End Class