client/Catalogos/Mantenimiento/frmSucursal.vb

258 lines
9.4 KiB
VB.net

Public Class frmSucursal
Private opcion As Boolean
Private idName As Integer
Private Sub frmSucursal_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
Iniciar()
ClassCatalogos.CambiaColorbloque2(BtnAgregar, BtnEditar, BtnOk, Button1)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Function Iniciar() As Boolean
Iniciar = False
Try
Limpiar()
llenarComboEdo()
llenarGrid()
DesHeader.Text = Me.Text
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Iniciar = True
End Function
Private Function llenarComboEdo() As Boolean
llenarComboEdo = False
Dim Classcom As New clsComplejo
Try
Classcom.sbLlenaCombo("sp_ConsultarEstado ", Me.cboEstado)
cboEstado.SelectedIndex = -1
Catch ex As Exception
End Try
llenarComboEdo = True
End Function
Private Function llenarComboPlaza() As Boolean
llenarComboPlaza = False
Dim Classcom As New clsComplejo
Try
If cboEstado.SelectedIndex <> -1 Then
Classcom.sbLlenaCombo("SELECT ALIASID as Clave, PLAZA as Nombre from cat_plaza where idestado = " & cboEstado.SelectedValue, Me.cboPlaza)
cboPlaza.SelectedIndex = -1
End If
Catch ex As Exception
End Try
llenarComboPlaza = True
End Function
Private Function Limpiar() As Boolean
Try
txtNombre.Enabled = False
txtNombre.Text = ""
chkActivo.Enabled = False
chkActivo.Checked = False
txtAlias.Enabled = False
txtAlias.Text = ""
txtCP.Enabled = False
txtCP.Text = ""
cboEstado.SelectedIndex = -1
cboEstado.SelectedIndex = -1
cboEstado.Enabled = False
cboPlaza.SelectedIndex = -1
cboPlaza.SelectedIndex = -1
cboPlaza.Enabled = 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
Dim ssql As String
llenarGrid = False
Try
Dim ClassCatalogos As New ClassCatalogos
ssql = "select CS.IDSUCURSAL,CS.IDESTADO,CE.ESTADO,CS.IDCATALOGO,CS.IDPLAZA,CP.PLAZA,CS.NOMBRESUCURSAL,CS.ALIAS,CS.ACTIVO,CS.CODIGOPOSTAL "
ssql += "from CAT_SUCURSAL CS "
ssql += " INNER JOIN CAT_ESTADO CE ON CS.IDESTADO = CE.IDESTADO "
ssql += " INNER JOIN CAT_PLAZA CP ON CS.IDPLAZA = CP.ALIASID ORDER BY 1 ASC "
GridMaster.AllowUpdate = False
ClassCatalogos.LlenaGrid(ssql, Me.GridMaster)
GridMaster.Splits(0).DisplayColumns(0).AutoSize()
GridMaster.Splits(0).DisplayColumns(1).Visible = False
GridMaster.Splits(0).DisplayColumns(2).AutoSize()
GridMaster.Splits(0).DisplayColumns(3).Visible = False
GridMaster.Splits(0).DisplayColumns(4).AutoSize()
GridMaster.Splits(0).DisplayColumns(5).AutoSize()
GridMaster.Splits(0).DisplayColumns(6).AutoSize()
GridMaster.Splits(0).DisplayColumns(7).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(BtnAgregar, BtnEditar, BtnOk, Button1)
opcion = True
End Sub
Private Function habilitar() As Boolean
habilitar = False
Try
txtNombre.Enabled = True
chkActivo.Enabled = True
txtCP.Enabled = True
txtAlias.Enabled = True
cboEstado.Enabled = True
cboPlaza.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 GridMaster.DoubleClick
llenarDatos()
ClassCatalogos.CambiaColorbloque2(BtnAgregar, BtnEditar, BtnOk, Button1)
End Sub
Private Function llenarDatos() As Boolean
llenarDatos = False
Try
idName = GridMaster.Columns(0).Value
cboEstado.SelectedValue = GridMaster.Columns(1).Value
cboPlaza.SelectedValue = IIf(IsDBNull(GridMaster.Columns(4).Value), 0, GridMaster.Columns(4).Value)
txtNombre.Text = GridMaster.Columns(6).Value
txtAlias.Text = GridMaster.Columns(7).Value
chkActivo.Checked = IIf(IsDBNull(GridMaster.Columns(8).Value), 0, GridMaster.Columns(8).Value)
txtCP.Text = GridMaster.Columns(9).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()
ClassCatalogos.CambiaColorbloque2(BtnAgregar, 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 alis As String
Dim CP As Integer
Dim edo As Integer
Dim plaza As Integer
Try
If ValidarDatos() Then
nombre = txtNombre.Text.Trim()
chk = chkActivo.CheckState
alis = txtAlias.Text.Trim()
CP = txtCP.Text.Trim()
edo = cboEstado.SelectedValue
If cboPlaza.SelectedValue = 0 Then
plaza = 99999999
Else
plaza = cboPlaza.SelectedValue
End If
If opcion Then
ssql = "INSERT INTO CAT_SUCURSAL(IDESTADO,IDCATALOGO,IDPLAZA,NOMBRESUCURSAL,ALIAS,ACTIVO,CODIGOPOSTAL) "
ssql += " VALUES (" & edo & ",1," & plaza & ",'" & nombre & "','" & alis & "'," & chk & ",'" & CP & "')"
Else
ssql = "UPDATE CAT_SUCURSAL SET NOMBRESUCURSAL ='" & nombre & "',ALIAS ='" & alis & "',"
ssql += "CODIGOPOSTAL ='" & CP & "',ACTIVO = " & chk & ",IDESTADO =" & edo & ",IDPLAZA = " & plaza & ",IDCATALOGO=1 "
ssql += " WHERE IDSUCURSAL =" & idName
End If
cls.sbGuardaModifica(ssql)
MessageBox.Show("Operacion Satisfactoria ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Information)
Limpiar()
llenarGrid()
ClassCatalogos.CambiaColorbloque2(BtnAgregar, 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
If txtAlias.Text.Trim = "" Then
MessageBox.Show("Es necesario Introducir el alias ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
If txtCP.Text.Trim = "" Then
MessageBox.Show("Es necesario introducir el CP ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
If cboEstado.SelectedIndex = -1 Then
MessageBox.Show("Es necesario elegir estado ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
If cboEstado.SelectedValue = 99999999 Then
cboPlaza.SelectedValue = 99999999
Else
If cboPlaza.SelectedIndex = -1 Then
MessageBox.Show("Es necesario elegir plaza ", "MINDS", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Function
End If
End If
ValidarDatos = True
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Function
Private Sub txtCalif_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles txtCP.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
Private Sub cboEstado_SelectedValueChanged(sender As System.Object, e As System.EventArgs) Handles cboEstado.SelectedValueChanged
llenarComboPlaza()
End Sub
End Class